不能用cmake链接assimp

时间:2015-07-03 17:16:20

标签: c++ linux cmake assimp

所以我设置了一个CMakeLists.txt脚本(运行正常),它设置我的项目:问题是当我运行makefile时,一切运行正常,直到它打印出来:

PS:我安装了这样的assimp(我在linux / ubuntu上):sudo apt-get install libassimp-dev;该库肯定安装良好;因为我已经在同一个项目中使用了代码:: 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

这是我的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})

2 个答案:

答案 0 :(得分:2)

我想正确答案更多:

target_link_libraries(${PROJECT_NAME} ${ASSIMP_LIBRARIES})

图书馆不是图书馆

答案 1 :(得分:0)

请尝试使用

target_link_libraries(${PROJECT_NAME} ${ASSIMP_LIBRARIES})

我不确定,该库是否会链接到正确的可执行文件。