title: SWIG Linker: undefined symbol: _ZN2cv8fastFreeEPv (cv::fastFree(void*))
body: <p>I'm having some trouble getting my SWIG wrapper to work in python after I changed some code. I suspect it has to do with the linker.</p>
  
  <p>My question concerns <a href="https://github.com/jlowenz/pyviso2" rel="nofollow noreferrer">this github</a>:
  This file compiles as described in the readme, and can be imported without issues in python.</p>
  
  <p>I have made some changes to the code that require OpenCV. When building in C++, no errors occur and the code runs as expected, after the CMakeLists file was modified to also add some OpenCV libraries. </p>
  
  <p>After I made these modifications, I once again want to SWIG this to python, but I'm getting many linker errors. After googling I have already added the following arguments to the SWIG setup.py which you can find <a href="https://github.com/jlowenz/pyviso2/blob/master/src/setup.py" rel="nofollow noreferrer">here</a></p>
  
  <pre><code>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'])])
  </code></pre>
  
  <p>Which should add the correct include / library folders as well as the used libs (xfeatures, core, ..) in the correct order. An example of one of the files is : </p>
  
  <pre><code>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
  </code></pre>
  
  <p>The order was found by issuing the </p>
  
  <pre><code>pkg-config --cflags --libs opencv 
  </code></pre>
  
  <p>command, and taking the required libraries in the same order.</p>
  
  <p>In the end, the SWIG command yields no errors. When loading the supposedly generated viso2 module in python (after adding the location of the module to the sys.path), it yields error: </p>
  
  <pre><code>undefined symbol: _ZN2cv8fastFreeEPv
  </code></pre>
  
  <p>which can be c++filt to become cv::fastFree(void*) </p>
  
  <p>When running </p>
  
  <pre><code>ldd -r _viso2......linux.so 
  </code></pre>
  
  <p>Quite a big list of undefined symbols show up.</p>
  
  <pre><code>&lt;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 =&amp;gt; /home/floris/Software/Anaconda3/lib/libstdc++.so.6 (0x00007f4c7b3d0000)
      libm.so.6 =&amp;gt; /lib/x86_64-linux-gnu/libm.so.6 (0x00007f4c7b032000)
      libgcc_s.so.1 =&amp;gt; /home/floris/Software/Anaconda3/lib/libgcc_s.so.1 (0x00007f4c7ae20000)
      libpthread.so.0 =&amp;gt; /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f4c7ac01000)
      libc.so.6 =&amp;gt; /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)
  </code></pre>
  
  <p>The only functionality I added is the OpenCV functionality. </p>
  
  <p>Thanks for reading. If you have an idea let me know.</p>
  
  <p>Cheers! </p>