<div dir="ltr">Hello, <br>I'm running cmake on a system where I have module-loaded software such that `LD_LIBRARY_PATH` gets populated by the module (actually I'm using Lmod) function.<br><br>In my project, I have a dependency on VTK, and VTK could be compiled with Python wrapping. <div><br></div><div>This is what I have in my main CMakeFiles.txt</div><div><br></div><div><div>project(HG)</div><div>set(HG_VERSION MAJOR 0)</div><div>set(HG_VERSION MINOR 1)</div><div><br></div><div># We use VTK extensively</div><div>find_package(VTK REQUIRED)</div><div>include(${VTK_USE_FILE})</div><div><br></div><div><br></div><div>add_subdirectory(src)</div><div><div><br></div><div># :: Tests :: </div><div>set(BUILD_TESTS FALSE CACHE BOOL "Set this to TRUE if you want to build and \</div><div>    run the tests ")</div><div><br></div><div>if(BUILD_TESTS)</div><div>    # We use catch2 for tests</div><div>    find_package(Catch2 QUIET</div><div>        HINTS</div><div>        "${CMAKE_BINARY_DIR}/third_party"</div><div>        )</div><div><br></div><div>    if(NOT Catch2_FOUND)</div><div>        message(WARNING "Catch2 was not found in the system. \</div><div>        It will be downloaded from its git repository and installed")</div><div><br></div><div>        # Bootstrap Catch2</div><div>        include(DownloadCatch2)</div><div><br></div><div>        # Try again</div><div>        find_package(Catch2 REQUIRED)</div><div>    endif(NOT Catch2_FOUND)</div><div><br></div><div>    enable_testing()</div><div>    add_subdirectory(tests)</div><div>    </div><div>endif(BUILD_TESTS)</div></div><div><br>In the `tests` directory I have:</div><div><br></div><div><div>set(TEST_TARGET "test_${PROJECT_NAME}")</div><div><br></div><div># find_package(PythonInterp REQUIRED)</div><div># find_package(PythonLibs REQUIRED)</div><div># message(FATAL_ERROR ${PYTHON_LIBRARIES})</div><div><br></div><div># Generate test executable</div><div>add_executable(${TEST_TARGET}</div><div>    test_hg.cxx</div><div>    test_polydata_wrapper.cxx)</div><div>target_link_libraries(${TEST_TARGET} ${PROJECT_NAME} Catch2::Catch2 ${VTK_LIBRARIES})</div></div><div><br></div><div>Now, when I compile the project, when linking the tests target:</div><div>cmake -DBUILD_TESTS:BOOL=ON ..<br><br></div><div><div>[100%] Linking CXX executable test_HG</div><div>PATH_TO_VTK_LIB_DIR/vtkWrappingPython27Core-7.1.so.1: error: undefined reference to '_PyUnicodeUCS2_AsDefaultEncodedString'</div><div>PATH_TO_VTK_LIB_DIR/vtkWrappingPython27Core-7.1.so.1: error: undefined reference to 'PyUnicodeUCS2_AsUTF8String'</div><div>PATH_TO_VTK_LIB_DIR/vtkWrappingPython27Core-7.1.so.1: error: undefined reference to 'PyUnicodeUCS2_DecodeUTF8'</div><div>PATH_TO_VTK_LIB_DIR/vtkWrappingPython27Core-7.1.so.1: error: undefined reference to 'PyUnicodeUCS2_GetSize'</div><div>collect2: error: ld returned 1 exit status</div><div>make[2]: *** [tests/test_HG] Error 1</div><div>make[1]: *** [tests/CMakeFiles/test_HG.dir/all] Error 2</div><div>make: *** [all] Error 2</div></div><div><br></div><div>That is because the linker is linking against the system Python library instead of the one in the LD_LIBRARY_PATH.</div><div><br></div><div>Checking the command in VERBOSE=1 mode, I get that the c++ command is linking against python using `-lpython2.7` instead of the fullpath to the library.</div><div><br>To confirm that, explicitly adding to LDFLAGS the path to the python library:<br>LDFLAGS='-L/path/to/the/dir/of/<a href="http://libpython2.7.so">libpython2.7.so</a>' cmake -DBUILD_TESTS:BOOL=ON' allows the project to compile correctly.</div><div><br></div><div>So now, why the linker does not look into LD_LIBRARY_PATH? Is that normal? And if it is, how should I be supposed to make the linker look into LD_LIBRARY_PATH?</div><div><br></div><div>Thanks in advance, <br><br><br></div><div><br><br></div><div><br></div><div><br></div><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><font face="monospace, monospace">          _  </font></div><div><font face="monospace, monospace">-.     .´  |∞∞∞∞</font></div><div><font face="monospace, monospace">  ',  ;    |∞∞∞∞∞∞</font></div><div><font face="monospace, monospace">    ˜˜     |∞∞∞∞∞∞∞∞∞ RdB </font></div><div><font face="monospace, monospace">    ,.,    |∞∞∞∞∞∞</font></div><div><font face="monospace, monospace">  .'   '.  |∞∞∞∞</font></div><div><font face="monospace, monospace">-'       `'</font></div><div><font face="monospace, monospace"><a href="http://rdb.is" target="_blank">http://rdb.is</a></font></div><div><br></div></div></div></div></div>