我想制作一个可以处理 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)
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)
最佳答案
我会尝试从 file(GLOB...) 命令中删除 core/*.h
头文件不需要编译,这实际上可能会导致重复符号的问题。
https://stackoverflow.com/questions/16134764/