Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/128.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cmake/SWIG组合在虚拟环境中不能很好地发挥作用 我正在研究一个项目,它把Python 3和C++结合起来,所以我决定使用CGue+SWIG。我的问题是,在虚拟环境处于活动状态时键入“make”时,会丢失符号,因为找到的Python版本似乎不兼容: -- Found PythonInterp: /Users/aaragon/.virtualenvs/pydev/bin/python (found version "3.4.2") -- Found SWIG: /usr/local/bin/swig (found version "3.0.5") -- Found PythonLibs: /usr/lib/libpython3.4.dylib (found version "2.7.6")_Python_C++_Python 3.x_Cmake_Swig - Fatal编程技术网

Cmake/SWIG组合在虚拟环境中不能很好地发挥作用 我正在研究一个项目,它把Python 3和C++结合起来,所以我决定使用CGue+SWIG。我的问题是,在虚拟环境处于活动状态时键入“make”时,会丢失符号,因为找到的Python版本似乎不兼容: -- Found PythonInterp: /Users/aaragon/.virtualenvs/pydev/bin/python (found version "3.4.2") -- Found SWIG: /usr/local/bin/swig (found version "3.0.5") -- Found PythonLibs: /usr/lib/libpython3.4.dylib (found version "2.7.6")

Cmake/SWIG组合在虚拟环境中不能很好地发挥作用 我正在研究一个项目,它把Python 3和C++结合起来,所以我决定使用CGue+SWIG。我的问题是,在虚拟环境处于活动状态时键入“make”时,会丢失符号,因为找到的Python版本似乎不兼容: -- Found PythonInterp: /Users/aaragon/.virtualenvs/pydev/bin/python (found version "3.4.2") -- Found SWIG: /usr/local/bin/swig (found version "3.0.5") -- Found PythonLibs: /usr/lib/libpython3.4.dylib (found version "2.7.6"),python,c++,python-3.x,cmake,swig,Python,C++,Python 3.x,Cmake,Swig,因此,我得到以下错误: 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_New

因此,我得到以下错误:

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
  "_PyInt_FromSize_t", referenced from:
      SWIG_From_unsigned_SS_int(unsigned 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
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[3]: *** [_core.so] Error 1
make[2]: *** [CMakeFiles/_core.dir/all] Error 2
make[1]: *** [all] Error 2
make: *** [core] Error 2
当我置身于外部环境时,一切正常:

-- Found PythonInterp: /usr/bin/python (found version "2.7.6") 
-- Found SWIG: /usr/local/bin/swig (found version "3.0.5") 
-- Found PythonLibs: /usr/lib/libpython2.7.dylib (found version "2.7.6") 
除了我不想使用Python2.7.6,而是使用Python3。有没有办法修复此错误?这是我目前在CMakeLists.txt中使用的代码:

# 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)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/core/fem)

#set(CMAKE_SWIG_OUTDIR ${PROJECT_BINARY_DIR}/../lib/hybrida)


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

使用所需的Python版本创建您的虚拟环境:

virtualenv --python /path/to/python <venv_dir>

那不行。我使用惰性包装器创建了virtualenv,如下所示:$mkvirtualenv-python=/usr/local/bin/python3-pydev3,但仍然失败。