GitHub issue: Adding python.h library
State: closed

While compiling code using g++, one needs to specify the library as -lpython3.6m. When I was trying to build a submission package, I got errors of undefined reference to python header files, a solution to it is to add -lpython3.6m option. Where shall I make changes to solve this issue? I want to submit our code for FVT 1:1.

You will need link any external dependencies directly to your core submission library.  The only library that NIST will link against is your core submission library (i.e. libfrvt11_xxx_xxx.so).  Additionally, you will need to provide all Python dependencies in your submission package to us.

Could you please guide me to link the dependencies to my core submission library?

Looking for core implementation library in /home/akshirsagar/frvt-biocube/11/lib.[SUCCESS] Found core implementation library /home/akshirsagar/frvt-biocube/11/lib/libfrvt_11_biocube_001.so.
Attempting to compile and link /home/akshirsagar/frvt-biocube/11/lib/libfrvt_11_biocube_001.so against test harness.
Scanning dependencies of target validate11
[ 50%] Building CXX object src/testdriver/CMakeFiles/validate11.dir/home/akshirsagar/frvt-biocube/common/src/util/util.cpp.o
[100%] Building CXX object src/testdriver/CMakeFiles/validate11.dir/validate11.cpp.o
Linking CXX executable ../../../bin/validate11
../../../lib/libfrvt_11_biocube_001.so: undefined reference to `PyImport_Import'
../../../lib/libfrvt_11_biocube_001.so: undefined reference to `PyList_GetItem'
../../../lib/libfrvt_11_biocube_001.so: undefined reference to `PyUnicode_DecodeFSDefault'
../../../lib/libfrvt_11_biocube_001.so: undefined reference to `PySys_SetPath'
../../../lib/libfrvt_11_biocube_001.so: undefined reference to `PyFloat_FromDouble'
../../../lib/libfrvt_11_biocube_001.so: undefined reference to `Py_FinalizeEx'
../../../lib/libfrvt_11_biocube_001.so: undefined reference to `PyList_Size'
../../../lib/libfrvt_11_biocube_001.so: undefined reference to `PyObject_CallObject'
../../../lib/libfrvt_11_biocube_001.so: undefined reference to `Py_Initialize'
../../../lib/libfrvt_11_biocube_001.so: undefined reference to `PyFloat_AsDouble'
../../../lib/libfrvt_11_biocube_001.so: undefined reference to `Py_BuildValue'
../../../lib/libfrvt_11_biocube_001.so: undefined reference to `PyObject_GetAttrString'
../../../lib/libfrvt_11_biocube_001.so: undefined reference to `PyLong_FromLong'
../../../lib/libfrvt_11_biocube_001.so: undefined reference to `PyList_SetItem'
../../../lib/libfrvt_11_biocube_001.so: undefined reference to `PyList_New'
../../../lib/libfrvt_11_biocube_001.so: undefined reference to `PyCallable_Check'
collect2: error: ld returned 1 exit status
make[2]: *** [../bin/validate11] Error 1
make[1]: *** [src/testdriver/CMakeFiles/validate11.dir/all] Error 2
make: *** [all] Error 2
[ERROR] There were errors during compilation of your library with the validation test harness.  Please investigate and re-compile.


I am getting this error, I have tried find_package(Python3 COMPONENTS Interpreter Development) from 11/CmakeLists.txt but still I am getting this error. Where shall I link the Python library to my submission library?

You can't assume that python3 will be installed on our systems, because it is not.  You will need to place all of your python dependencies (e.g., libpython3.6m.so) into your ./lib folder and link against them when you build YOUR shared library.  You can use rpath=$ORIGIN, but you need to link your submission library against any 3rd party libraries that are required. For example, in your CMakeLists.txt:

set (CMAKE_SHARED_LINKER_FLAGS "-Wl,-rpath,$ORIGIN")
add_library (libfrvt_11_biocube_001 SHARED yourSourceCode.cpp)
target_link_libraries(libfrvt_11_biocube_001 libpython3.6m.so thirdpartylib1.so thirdpartylib2.so thirdpartylib3.so)