c++ - 使用 Boost.Python 和静态库构建

标签 c++ python boost compilation compiler-errors

我想制作一个可以处理 python 插件的 C++ 应用程序,所以我进入了 boost.python。我正在创建一些使用 CMake 构建的测试程序。

在我的测试程序中,我有一个简单的“库”,它提出了一个插件接口(interface)(使用 boost.python 将其公开给 python)和一个插件加载器(尚未编码,内部没有任何内容)。

当我尝试直接构建可执行文件(没有任何库)时,出现链接错误(我公开的模块称为 pythonPlugin):

duplicate symbol _initpythonPlugin in:
    CMakeFiles/pythonPluginer.dir/main.cpp.o
    libcoreLib.a(PluginLoader.cpp.o)
duplicate symbol __Z24init_module_pythonPluginv in:
    CMakeFiles/pythonPluginer.dir/main.cpp.o
    libcoreLib.a(PluginLoader.cpp.o) 

当我构建一个中间静态库时,我得到了相同的结果。然而,当我把这个库变成一个共享库时,它工作得很好。这是一个子 CMakeList.txt :
file(GLOB sources core/*.h core/*.cpp )

add_library(coreLib SHARED ${sources})
target_link_libraries(coreLib 
                      ${PYTHON_LIBRARIES} 
                      ${Boost_LIBRARIES})

add_executable(pythonPluginer main.cpp)
target_link_libraries(pythonPluginer 
                      coreLib)

你对此有什么解释吗?是否可以在不使用共享库的情况下使用 boost/python 制作程序?

谢谢,
丹尼斯。

最佳答案

我会尝试从 file(GLOB...) 命令中删除 core/*.h
头文件不需要编译,这实际上可能会导致重复符号的问题。

关于c++ - 使用 Boost.Python 和静态库构建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16134764/

相关文章:

c++ - 查找导致 undefined reference 错误的源代码行

c++ - Qt4:使全屏窗口无法绕过(锁定屏幕)?

javascript - 如何在node.js中发送带有数据和不记名授权的POST请求?

python - 如何在 python 记录器中记录请求特定属性

c++ - 为团队的其他成员恢复对 Eclipse 项目库的更改

c++ - 尝试使用 boost::asio::signal_set 时无法编译

c++ boost filtering_streambuf 只读一些数据

c++ - 如何在 boost odeint bulirsch_stoer_dense_out 中插入解决方案

python - 通过在 python 中取平均值来生成 dict

C++ 模板 : A template to call variables by name