如何在 Windows 10 上为我的库界面的 Cython 构建设置 BOOST_ALL_DYN_LINK

问题描述 投票:0回答:1

我的 C++ 库依赖于 boost_filesystem。我正在使用 Visual Studio 2022 在 Windows 10 上工作。我使用 Cython 为我的库构建了一个 python 界面。当我调用 Cython 时,它抱怨找不到“libboost_file_system-vc...”。问题是“lib”前缀指的是静态库,而我试图动态链接到“boost_file_system-vc...”。如果我创建“boost_file_system-vc...”的副本并添加“lib”前缀,我可以解决这个问题并获得一个工作界面”,但这显然是解决这个问题的错误方法。从我的情况来看到目前为止已经能够确定,要正确执行此操作,我需要设置编译器标志“/D BOOST_ALL_DYN_LINK=1”,但似乎我正在以错误的方式处理此问题,或者解决方案可能比我想象的更多我已经查看了相关帖子来寻求帮助,但到目前为止,我所看到的没有任何内容可以回答我的问题。

这是我的设置.py:

from setuptools import setup, Extension
from Cython.Build import cythonize
import os
from sys import platform

if platform == "win32":
    boostlib = 'boost_filesystem-vc143-mt-x64-1_78'
elif platform == "linux" or platform == "linux2":
    boostlib = 'boost_filesystem'

ext = [Extension(name = "*",
                 sources      = [os.path.join(os.path.dirname(__file__), "src", "*.pyx")],
                 extra_compile_args = [ '/D BOOST_ALL_DYN_LINK=1' ],
                 language     = "c++",
                 library_dirs = ['../../build/install/bin','../../build/install/lib','../../Dependencies/build/install/lib',],
                 libraries    = ['mylib',boostlib]
                )
]

setup( name = "hemi",
       ext_modules = cythonize(ext, language_level = "3"),
       include_dirs = ['../include',
                       ... # omitted lines
                       '../../Dependencies/build/install/include/boost-1_78',
                       '../../Dependencies/build/install/include'
                      ],
     )

我预计添加指定“extra_compile_args”的行会提示 Cython 查找名称不带“lib”前缀的库,即“boost_filesystem-vc ...”而不是“libboost_filesystem_vc ...”,但我仍然遇到相同的错误。我错了/错过了什么?谢谢!

windows boost cython dynamic-linking
1个回答
0
投票

定义

BOOST_ALL_DYN_LINK
是正确的想法,但显然我在错误的地方做的。我只是在我正在构建的库的顶级包含文件中添加了预处理器宏
#define BOOST_ALL_DYN_LINK
,而不是上面的 setup.py 中显示的行。

© www.soinside.com 2019 - 2024. All rights reserved.