从SWIG的帮助文件开始,我想运行以下代码
# This is a CMake example for Python
FIND_PACKAGE(SWIG REQUIRED)
INCLUDE(${SWIG_USE_FILE})
FIND_PACKAGE(PythonLibs)
INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH})
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
SET(CMAKE_SWIG_FLAGS "")
SET_SOURCE_FILES_PROPERTIES(example.i PROPERTIES CPLUSPLUS ON)
SET_SOURCE_FILES_PROPERTIES(example.i PROPERTIES SWIG_FLAGS "-includeall")
SWIG_ADD_MODULE(example python example.i example.cxx) # I need to link to an external library
SWIG_LINK_LIBRARIES(example ${PYTHON_LIBRARIES})
这样可以正常工作,除了我的case.cxx需要链接到一个现有的库,我们称之为libmylibrary.a。我尝试将此添加到SWIG_LINK_LIBRARIES命令,但这没有做到这一点。有什么想法吗?
答案 0 :(得分:4)
事实证明你只需要修改上面的最后一行来阅读
SWIG_LINK_LIBRARIES(example mylibrary ${PYTHON_LIBRARIES})
其中mylibrary在libmylibrary.a文件中被理解。