简体   繁体   中英

FindSWIG.cmake unable to find correct header/library pair

I have the following code in the CMakeLists.txt file:

# find Python
find_package(PythonInterp)

# find SWIG
find_package(SWIG REQUIRED)
include(${SWIG_USE_FILE})

find_package(PythonLibs)
include_directories(${PYTHON_INCLUDE_PATH})

message(STATUS "PYTHON_INCLUDE_PATH: ${PYTHON_INCLUDE_PATH}")
message(STATUS "PYTHON_LIBRARIES:    ${PYTHON_LIBRARIES}")

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/core)        

SET_SOURCE_FILES_PROPERTIES(swig/core.i PROPERTIES CPLUSPLUS ON)
set_source_files_properties(swig/core.i SWIG_FLAGS "-includeall;-c++;-shadow")
swig_add_module(core python swig/core.i core/foo.cpp)
swig_link_libraries(core hybrida_core ${PYTHON_LIBRARIES})

When I see the output, this gives me:

-- Found PythonInterp: /Users/aaragon/.virtualenvs/pydev/bin/python (found version "3.4.1") 
-- PYTHON_EXECUTABLE: /Users/aaragon/.virtualenvs/pydev/bin/python
-- Python version: 3.4.1
-- Found SWIG: /usr/local/bin/swig (found version "3.0.3") 
-- Found PythonLibs: /usr/lib/libpython3.4.dylib (found version "2.7.6") 
-- PYTHON_INCLUDE_PATH: /System/Library/Frameworks/Python.framework/Headers
-- PYTHON_LIBRARIES:    /usr/lib/libpython3.4.dylib

So there's something wrong about the PythonLibs found as it says it found version 2.7.6. This results in tons of linking errors later:

Linking CXX shared module _core.so
Undefined symbols for architecture x86_64:
  "_PyClass_Type", referenced from:
      SwigPyClientData_New(_object*) in corePYTHON_wrap.cxx.o
  "_PyInstance_NewRaw", referenced from:
      SWIG_Python_NewShadowInstance(SwigPyClientData*, _object*) in corePYTHON_wrap.cxx.o
  "_PyInstance_Type", referenced from:
      SWIG_Python_GetSwigThis(_object*) in corePYTHON_wrap.cxx.o
  "_PyInt_AsLong", referenced from:
      SWIG_AsVal_long(_object*, long*) in corePYTHON_wrap.cxx.o
      SWIG_AsVal_unsigned_SS_long(_object*, unsigned long*) in corePYTHON_wrap.cxx.o
      SWIG_AsVal_double(_object*, double*) in corePYTHON_wrap.cxx.o
  "_PyInt_FromLong", referenced from:
      SWIG_From_int(int) in corePYTHON_wrap.cxx.o
  "_PyString_AsString", referenced from:
      SWIG_Python_str_AsChar(_object*) in corePYTHON_wrap.cxx.o
  "_PyString_AsStringAndSize", referenced from:
      SWIG_AsCharPtrAndSize(_object*, char**, unsigned long*, int*) in corePYTHON_wrap.cxx.o
  "_PyString_ConcatAndDel", referenced from:
      SwigPyObject_repr(SwigPyObject*) in corePYTHON_wrap.cxx.o
      swig_varlink_str(swig_varlinkobject*) in corePYTHON_wrap.cxx.o
  "_PyString_Format", referenced from:
      SwigPyObject_format(char const*, SwigPyObject*) in corePYTHON_wrap.cxx.o
  "_PyString_FromFormat", referenced from:
      SwigPyObject_repr(SwigPyObject*) in corePYTHON_wrap.cxx.o
      SwigPyPacked_repr(SwigPyPacked*) in corePYTHON_wrap.cxx.o
      SwigPyPacked_str(SwigPyPacked*) in corePYTHON_wrap.cxx.o
  "_PyString_FromString", referenced from:
      SWIG_Python_str_FromChar(char const*) in corePYTHON_wrap.cxx.o
      swig_varlink_repr(swig_varlinkobject*) in corePYTHON_wrap.cxx.o
      swig_varlink_str(swig_varlinkobject*) in corePYTHON_wrap.cxx.o
  "_PyString_FromStringAndSize", referenced from:
      SWIG_FromCharPtrAndSize(char const*, unsigned long) in corePYTHON_wrap.cxx.o
  "_Py_InitModule4_64", referenced from:
      _init_core in corePYTHON_wrap.cxx.o
      SWIG_Python_SetModule(swig_module_info*) in corePYTHON_wrap.cxx.o
  "__PyInstance_Lookup", referenced from:
      SWIG_Python_GetSwigThis(_object*) in corePYTHON_wrap.cxx.o
ld: symbol(s) not found for architecture x86_64

If I hard-code the following variable:

set (PYTHON_INCLUDE_DIR /Library/Frameworks/Python.framework/Versions/3.4/Headers)

Then I'm able to compile and link correctly. Is cmake unable to determine the right header files/library combination for Python?

显然,这是我在CMake 3.1.0中遇到的问题,但已在较新版本的CMake(3.1.1)中解决。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM