Search code examples
c++linuxcmakeassimp

Cannot link assimp with cmake


So I've set up a CMakeLists.txt script (runs fine), which sets up my project : Problem is when I run the makefile, everything runs fine, until it prints me :

PS : I installed assimp like this (I'm on linux/ubuntu) : sudo apt-get install libassimp-dev; The library is for sure well installed; because I laready used it, in the same project using code::blocks !

Linking CXX executable Test
CMakeFiles/Test.dir/src/Mesh.cpp.o: In function `Mesh::Mesh(char const*)':
Mesh.cpp:(.text+0x1db): undefined reference to `Assimp::Importer::Importer()'
Mesh.cpp:(.text+0x1f9): undefined reference to `Assimp::Importer::ReadFile(char const*, unsigned int)'
Mesh.cpp:(.text+0x625): undefined reference to `Assimp::Importer::~Importer()'
Mesh.cpp:(.text+0x672): undefined reference to `Assimp::Importer::~Importer()'
collect2: error: ld returned 1 exit status
make[2]: *** [Test] Error 1
make[1]: *** [CMakeFiles/Test.dir/all] Error 2
make: *** [all] Error 2

Here is my CMakeLists.txt :

CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
project(Test)

set(CMAKE_CXX_FLAGS "-std=c++11")

################INCLUDE LIBRARIES###################
#specify module path
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)

#OPENGL
find_package(OpenGL REQUIRED)
if(OPENGL_FOUND)
    include_directories(${OpenGL_INCLUDE_DIRS})
endif()

#SDL2
find_package(SDL2 REQUIRED)
if(SDL2_FOUND)
    include_directories(${SDL2_INCLUDE_DIR})
endif()

#GLEW
find_package(GLEW REQUIRED)
if(GLEW_FOUND)
    include_directories(${GLEW_INCLUDE_DIR})
endif() 

#BOOST
find_package(BOOST REQUIRED)
if(BOOST_FOUND)
    include_directories(${BOOST_INCLUDE_DIR})
endif() 

#LUA
find_package(LUA REQUIRED)
if(LUA_FOUND)
    include_directories(${LUA_INCLUDE_DIR})
endif() 


#LUABIND
find_package(LUABIND REQUIRED)
if(LUABIND_FOUND)
    include_directories(${LUABIND_INCLUDE_DIR})
endif() 

#ASSIMP
find_package(ASSIMP REQUIRED)
if(ASSIMP_FOUND)
    include_directories(${ASSIMP_INCLUDE_DIR})
endif() 


include_directories(
        #include directories are here...
    )



add_executable(
    ${PROJECT_NAME}

    #I won't list cpp files, bcause there are a lot !
 )


################LINK LIBRARIES#####################

target_link_libraries(Test ${OPENGL_LIBRARY})
target_link_libraries(Test ${SDL2_LIBRARY})
target_link_libraries(Test ${GLEW_LIBRARY})
target_link_libraries(Test ${BOOST_LIBRARY})
target_link_libraries(Test ${LUA_LIBRARY})
target_link_libraries(Test ${LUABIND_LIBRARY})
target_link_libraries(Test ${CMAKE_DL_LIBS})
target_link_libraries(Test ${ASSIMP_LIBRARY})

Solution

  • Please try to use

    target_link_libraries(${PROJECT_NAME} ${ASSIMP_LIBRARIES})
    

    I am not sure, if the library will be linked to the right executable.