无法 link 使用 cmake 进行 assimp
Cannot link assimp with cmake
所以我设置了一个 CMakeLists.txt 脚本(运行 没问题),它设置了我的项目:问题是当我 运行 生成文件时,所有内容 运行 很好,直到它打印出我:
PS : 我这样安装 assimp (我在 linux/ubuntu) : sudo apt-get install libassimp-dev
;该库 肯定 安装良好;因为我已经在使用 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
这是我的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})
请尝试使用
target_link_libraries(${PROJECT_NAME} ${ASSIMP_LIBRARIES})
我不确定库是否会链接到正确的可执行文件。
我猜正确答案是:
target_link_libraries(${PROJECT_NAME} ${ASSIMP_LIBRARIES})
图书馆不是图书馆
所以我设置了一个 CMakeLists.txt 脚本(运行 没问题),它设置了我的项目:问题是当我 运行 生成文件时,所有内容 运行 很好,直到它打印出我:
PS : 我这样安装 assimp (我在 linux/ubuntu) : sudo apt-get install libassimp-dev
;该库 肯定 安装良好;因为我已经在使用 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
这是我的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})
请尝试使用
target_link_libraries(${PROJECT_NAME} ${ASSIMP_LIBRARIES})
我不确定库是否会链接到正确的可执行文件。
我猜正确答案是:
target_link_libraries(${PROJECT_NAME} ${ASSIMP_LIBRARIES})
图书馆不是图书馆