Using SWIG with a build system [closed]

江枫思渺然 提交于 2019-12-07 20:42:59

问题


Anyone have experience with using SWIG (the interface generator)?

I have a C project which I would like to expose to a bunch of other languages/frameworks, like Python, Java, .NET, Perl, PHP, Ruby.

I would like to integrate with my build system (which is CMake-based), but any method of accomplishing this will do.


回答1:


CMake comes with a module for building SWIG wrappers.

Your CMakeLists.txt should include something like this:

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 "")

SWIG_ADD_MODULE(example python example.i example.cxx)
SWIG_LINK_LIBRARIES(example ${PYTHON_LIBRARIES})

See http://www.itk.org/Wiki/CMake_FAQ#How_do_I_use_CMake_to_generate_SWIG_wrapper_libraries.3F for more details (the above example is taken from there...)



来源:https://stackoverflow.com/questions/1515374/using-swig-with-a-build-system

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!