SWIG链接器:未定义的符号:_ZN2cv8fastFreeEPv(cv :: fastFree(void *))
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SWIG链接器:未定义的符号:_ZN2cv8fastFreeEPv(cv :: fastFree(void *))相关的知识,希望对你有一定的参考价值。
在我更改了一些代码之后,我在使用python包装器在python中工作时遇到了一些麻烦。我怀疑它与链接器有关。
我的问题与this github有关:这个文件按照自述文件中的描述编译,可以在python中导入而没有问题。
我对需要OpenCV的代码进行了一些更改。在使用C ++构建时,在修改CMakeLists文件以添加一些OpenCV库之后,不会发生错误并且代码按预期运行。
在我做了这些修改后,我再一次想要将这个转换为python,但是我遇到了很多链接器错误。在谷歌搜索后,我已经将以下参数添加到SWIG setup.py中,您可以找到here
extra_compile_args=['-L/usr/local/lib -lopencv_xfeatures2d -lopencv_features2d
-lopencv_highgui -lopencv_core','-msse3'],
include_dirs=[numpy.get_include(),
'/usr/local/include/opencv',
'/usr/local/include'])])
哪个应该以正确的顺序添加正确的include / library文件夹以及使用的libs(xfeatures,core,..)。其中一个文件的示例是:
gcc -pthread -B /home/floris/Software/Anaconda3/compiler_compat -Wl,--sysroot=/ -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/home/floris/Software/Anaconda3/lib/python3.6/site-packages/numpy/core/include -I/usr/local/include/opencv -I/usr/local/include -I/home/floris/Software/Anaconda3/include/python3.6m -c filter.cpp -o build/temp.linux-x86_64-3.6/filter.o -L/usr/local/lib -lopencv_xfeatures2d -lopencv_features2d -lopencv_highgui -lopencv_core -msse3
订单是通过发出订单找到的
pkg-config --cflags --libs opencv
命令,并以相同的顺序获取所需的库。
最后,SWIG命令不会产生错误。在python中加载假定生成的viso2模块时(在将模块的位置添加到sys.path之后),它会产生错误:
undefined symbol: _ZN2cv8fastFreeEPv
这可以是c ++ filt成为cv :: fastFree(void *)
跑步时
ldd -r _viso2......linux.so
相当大的未定义符号列表显示出来。
<floris@OPTIMUSPRIME:/magatank/DataSets/LibViso2_python/pyviso2_gitclone/src$ ldd -r _viso2.cpython-36m-x86_64-linux-gnu.so
linux-vdso.so.1 (0x00007ffdfd7bc000)
libstdc++.so.6 => /home/floris/Software/Anaconda3/lib/libstdc++.so.6 (0x00007f4c7b3d0000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f4c7b032000)
libgcc_s.so.1 => /home/floris/Software/Anaconda3/lib/libgcc_s.so.1 (0x00007f4c7ae20000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f4c7ac01000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f4c7a810000)
/lib64/ld-linux-x86-64.so.2 (0x00007f4c7b9c1000)
undefined symbol: PyExc_ValueError (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyBool_Type (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyExc_IndexError (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyExc_SyntaxError (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyCapsule_Type (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PySlice_Type (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: _Py_NoneStruct (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyExc_AttributeError (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyExc_IOError (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyExc_MemoryError (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyType_Type (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyExc_OverflowError (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyExc_ZeroDivisionError (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyExc_NotImplementedError (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyExc_RuntimeError (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: _Py_NotImplementedStruct (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyExc_StopIteration (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyExc_TypeError (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyObject_GenericGetAttr (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyFloat_Type (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyExc_SystemError (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyExc_ImportError (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyTuple_SetItem (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyLong_AsLong (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: _ZN2cv8fastFreeEPv (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyObject_GetAttr (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyImport_AddModule (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyObject_Call (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyObject_Init (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyInstanceMethod_New (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyObject_Str (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyObject_GetAttrString (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyErr_Restore (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyType_IsSubtype (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyModule_GetDict (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyModule_AddObject (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: _ZN2cv7noArrayEv (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyTuple_New (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyObject_SetAttr (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyObject_IsInstance (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyEval_RestoreThread (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: _ZN2cv11xfeatures2d4SIFT6createEiiddd (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyDict_SetItemString (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyUnicode_FromFormat (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyLong_AsDouble (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyErr_SetObject (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: _PyObject_New (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyErr_Format (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyFloat_FromDouble (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyFloat_AsDouble (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyUnicode_DecodeUTF8 (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyImport_ImportModule (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyUnicode_FromString (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: _ZN2cv6String10deallocateEv (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PySequence_Check (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: _ZN2cv5errorEiRKNS_6StringEPKcS4_i (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyErr_Clear (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: _ZN2cv6String8allocateEm (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: Py_DecRef (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyCapsule_Import (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyLong_FromVoidPtr (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyErr_SetString (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyEval_InitThreads (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyCapsule_New (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyArg_ParseTuple (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: _ZN2cv3MatC1ERKS0_RKNS_5Rect_IiEE (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyGILState_Release (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyCapsule_GetPointer (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyObject_Free (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyType_Ready (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyObject_Size (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyEval_SaveThread (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PySequence_GetItem (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PySequence_Size (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyLong_FromLong (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyErr_WriteUnraisable (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyObject_IsTrue (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyModule_Create2 (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: _ZN2cv3Mat20updateContinuityFlagEv (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyErr_Occurred (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyErr_Fetch (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyObject_CallFunctionObjArgs (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PySlice_GetIndices (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyCallable_Check (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyLong_FromUnsignedLong (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyArg_UnpackTuple (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyGILState_Ensure (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyObject_Malloc (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyErr_Print (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyUnicode_Concat (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: _ZNK2cv3Mat6copyToERKNS_12_OutputArrayE (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: _ZN2cv3MatC1ERKS0_RKNS_5RangeES5_ (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: _ZN2cv3Mat10deallocateEv (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyUnicode_AsUTF8String (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyBytes_AsStringAndSize (./_viso2.cpython-36m-x86_64-linux-gnu.so)
undefined symbol: PyBool_FromLong (./_viso2.cpython-36m-x86_64-linux-gnu.so)
我添加的唯一功能是OpenCV功能。
谢谢阅读。如果您有任何想法,请告诉我。
干杯!
您必须使用参数libraries
和library_dirs
将库和库路径传递给构建过程,即:
ext = Extension(....
libraries=["opencv_xfeatures2d", "opencv_features2d",
"opencv_highgui", "opencv_core"],
library_dirs=['/usr/local/lib']
)
请注意,不需要-l
和-L
- 它们由distutils照顾。
为什么不将它们添加到额外的编译标志中呢?
建筑扩展包括以下步骤:
- 构建第一个cpp文件,创建一个对象文件。使用编译器标志。
- 构建更多的cpp文件(如果有的话)。使用编译器标志。
- 将所有目标文件链接在一起,需要库。使用链接器标志。
如您所见,最后一步需要库,但不提供它们,因为它们是编译器标志的一部分。另一方面,库是在编译期间提供的,但在此阶段不需要。
以上是关于SWIG链接器:未定义的符号:_ZN2cv8fastFreeEPv(cv :: fastFree(void *))的主要内容,如果未能解决你的问题,请参考以下文章
gcc链接错误:未定义对符号'_ZN2cv5flann12SearchParamsC1Eifb'的引用,[重复]
ImportError:使用 SWIG 时 _...so 文件中的未定义符号
Apple Mach-O 链接器错误 - 架构 x86_64 的未定义符号:“_UISceneWillEnterForegroundNotification”和“___isPlatformVersio