I am struggling with linking the Assimp library with the find_package() function of CMake.
# ASSIMP search path
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ${CMAKE_CURRENT_LIST_DIR}/assimp/)
find_package(assimp REQUIRED)
if (assimp_FOUND)
link_directories(${ASSIMP_LIBRARY_DIRS})
include_directories(${ASSIMP_INCLUDE_DIRS})
target_link_libraries (NervousEngine ${ASSIMP_LIBRARIES})
endif(assimp_FOUND)
My first question is why Cmake is not throwing an error for find_package() while compiling the project with gcc it says that -lassimp is not found. Ofcourse i can get it to fail when i remove the CMAKE_PREFIX_PATH for assimp directory. Somehow CMake fails to instruct the compile command to link it???
The second question is why the library cannot be linked. This is the compile command along with the ld linking error
/usr/bin/c++ -std=gnu++11 -g sourceFiles... o NervousEngine -Wl,-rpath,/home/jointts/CLionProjects/OpenGL/lib/bullet/lib ../lib/bullet/lib/libBulletDynamics.so ../lib/bullet/lib/libBulletCollision.so ../lib/bullet/lib/libLinearMath.so ../lib/bullet/lib/libBulletSoftBody.so -lassimp -lfreetype
/usr/bin/ld: cannot find -lassimp
collect2: error: ld returned 1 exit status
I just don't understand why isn't it linking properly I even used the link_directories directive to guide the library search.
Debugging the paths of the library i get the following
message(${ASSIMP_LIBRARY_DIRS}) -> /home/jointts/CLionProjects/OpenGL/lib/assimp/lib
message(${ASSIMP_LIBRARIES}) -> assimp
So I would presume the library location itself is correct and it would result in a library search I typed below?
${ASSIMP_LIBRARY_DIRS} + ${ASSIMP_LIBRARIES}
/home/jointts/CLionProjects/OpenGL/lib/assimp/lib/libassimp.so
- This is my folder structure
- This is my CMakeLists.txt in root directory
- This is my CMakeLists.txt for library linking (included via root CmakeLists.txt)
- This is assimp-config.cmake that should handle find_package linking (unmodified)
gcc --version yields the following
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
CMake version is 3.9.6