构建 sfml 时 Cmake 不链接
Cmake not linking when building sfml
我有我的项目,嵌套在另一个目录中,其中包含我的项目所需的库。我正在使用与 Clion 3.14 捆绑在一起的 cmake。我在 cmake 中使用子目录。我构建得很好,但它没有链接 SFML
根-|
-lib1
-smfl
-lib3
-my_project
我试过使用 'target_link_directories()' 之类的东西,但要么我做错了,要么绝对不是正确的选择。
根目录CMakeList.txt
cmake_minimum_required(VERSION 3.10)
include_directories("ChaiScript/include" Catch2/include freetype2/include SFML/include )
add_subdirectory(Catch2)
add_subdirectory(ChaiScript)
add_subdirectory(freetype2)
add_subdirectory(SFML)
add_subdirectory(Purrmaid)
./Purrmaid/CMakeList.txt
cmake_minimum_required (VERSION 3.10)
set(CMAKE_CXX_STANDARD 17)
project (purrmaid)
add_executable( purrmaid
main.cpp
Base_Object.cpp
...
ThreadManager.cpp)
target_link_libraries(purrmaid sfml-system sfml-window sfml-graphics sfml-network sfml-audio pthread dl)
../SFML/lib/libsfml-graphics-d.so.2.5.1: undefined reference to `FT_MulFix'
../SFML/lib/libsfml-graphics-d.so.2.5.1: undefined reference to `FT_Init_FreeType'
../SFML/lib/libsfml-graphics-d.so.2.5.1: undefined reference to `FT_Get_Char_Index'
../SFML/lib/libsfml-graphics-d.so.2.5.1: undefined reference to `FT_Get_Kerning'
../SFML/lib/libsfml-graphics-d.so.2.5.1: undefined reference to `FT_Get_Glyph'
../SFML/lib/libsfml-graphics-d.so.2.5.1: undefined reference to `FT_New_Face'
../SFML/lib/libsfml-graphics-d.so.2.5.1: undefined reference to `FT_Stroker_Set'
../SFML/lib/libsfml-graphics-d.so.2.5.1: undefined reference to `FT_Glyph_To_Bitmap'
../SFML/lib/libsfml-graphics-d.so.2.5.1: undefined reference to `FT_Outline_Embolden'
../SFML/lib/libsfml-graphics-d.so.2.5.1: undefined reference to `FT_Load_Char'
../SFML/lib/libsfml-graphics-d.so.2.5.1: undefined reference to `FT_Done_Glyph'
../SFML/lib/libsfml-graphics-d.so.2.5.1: undefined reference to `FT_Stroker_New'
../SFML/lib/libsfml-graphics-d.so.2.5.1: undefined reference to `FT_Open_Face'
../SFML/lib/libsfml-graphics-d.so.2.5.1: undefined reference to `FT_Glyph_Stroke'
../SFML/lib/libsfml-graphics-d.so.2.5.1: undefined reference to `FT_Bitmap_Embolden'
../SFML/lib/libsfml-graphics-d.so.2.5.1: undefined reference to `FT_Done_Face'
../SFML/lib/libsfml-graphics-d.so.2.5.1: undefined reference to `FT_New_Memory_Face'
../SFML/lib/libsfml-graphics-d.so.2.5.1: undefined reference to `FT_Stroker_Done'
../SFML/lib/libsfml-graphics-d.so.2.5.1: undefined reference to `FT_Done_FreeType'
../SFML/lib/libsfml-graphics-d.so.2.5.1: undefined reference to `FT_Set_Pixel_Sizes'
../SFML/lib/libsfml-graphics-d.so.2.5.1: undefined reference to `FT_Select_Charmap'
显示的错误是 SFML 无法 link,因为它找不到对不同 FT_
符号(FT_MulFix
、FT_Init_FreeType
等)的引用
这些由 FreeType 库定义。我假设您在 add_subdirectory(SFML)
时正在构建不同的 SFML 目标
在SFML
子目录下的CMakeLists.txt
文件中,你link针对自由类型的sfml-graphics
目标吗?
add_library(sfml-graphics
...)
# This is assuming you have a "freetype2" target available
# please replace by the actual name of the freetype target
target_link_libraries(sfml-graphics freetype2 ...)
编辑:感谢 Tsyvarev 为我指明了无法 link 的实际目标方向.
我有我的项目,嵌套在另一个目录中,其中包含我的项目所需的库。我正在使用与 Clion 3.14 捆绑在一起的 cmake。我在 cmake 中使用子目录。我构建得很好,但它没有链接 SFML
根-| -lib1 -smfl -lib3 -my_project
我试过使用 'target_link_directories()' 之类的东西,但要么我做错了,要么绝对不是正确的选择。
根目录CMakeList.txt
cmake_minimum_required(VERSION 3.10)
include_directories("ChaiScript/include" Catch2/include freetype2/include SFML/include )
add_subdirectory(Catch2)
add_subdirectory(ChaiScript)
add_subdirectory(freetype2)
add_subdirectory(SFML)
add_subdirectory(Purrmaid)
./Purrmaid/CMakeList.txt
cmake_minimum_required (VERSION 3.10)
set(CMAKE_CXX_STANDARD 17)
project (purrmaid)
add_executable( purrmaid
main.cpp
Base_Object.cpp
...
ThreadManager.cpp)
target_link_libraries(purrmaid sfml-system sfml-window sfml-graphics sfml-network sfml-audio pthread dl)
../SFML/lib/libsfml-graphics-d.so.2.5.1: undefined reference to `FT_MulFix'
../SFML/lib/libsfml-graphics-d.so.2.5.1: undefined reference to `FT_Init_FreeType'
../SFML/lib/libsfml-graphics-d.so.2.5.1: undefined reference to `FT_Get_Char_Index'
../SFML/lib/libsfml-graphics-d.so.2.5.1: undefined reference to `FT_Get_Kerning'
../SFML/lib/libsfml-graphics-d.so.2.5.1: undefined reference to `FT_Get_Glyph'
../SFML/lib/libsfml-graphics-d.so.2.5.1: undefined reference to `FT_New_Face'
../SFML/lib/libsfml-graphics-d.so.2.5.1: undefined reference to `FT_Stroker_Set'
../SFML/lib/libsfml-graphics-d.so.2.5.1: undefined reference to `FT_Glyph_To_Bitmap'
../SFML/lib/libsfml-graphics-d.so.2.5.1: undefined reference to `FT_Outline_Embolden'
../SFML/lib/libsfml-graphics-d.so.2.5.1: undefined reference to `FT_Load_Char'
../SFML/lib/libsfml-graphics-d.so.2.5.1: undefined reference to `FT_Done_Glyph'
../SFML/lib/libsfml-graphics-d.so.2.5.1: undefined reference to `FT_Stroker_New'
../SFML/lib/libsfml-graphics-d.so.2.5.1: undefined reference to `FT_Open_Face'
../SFML/lib/libsfml-graphics-d.so.2.5.1: undefined reference to `FT_Glyph_Stroke'
../SFML/lib/libsfml-graphics-d.so.2.5.1: undefined reference to `FT_Bitmap_Embolden'
../SFML/lib/libsfml-graphics-d.so.2.5.1: undefined reference to `FT_Done_Face'
../SFML/lib/libsfml-graphics-d.so.2.5.1: undefined reference to `FT_New_Memory_Face'
../SFML/lib/libsfml-graphics-d.so.2.5.1: undefined reference to `FT_Stroker_Done'
../SFML/lib/libsfml-graphics-d.so.2.5.1: undefined reference to `FT_Done_FreeType'
../SFML/lib/libsfml-graphics-d.so.2.5.1: undefined reference to `FT_Set_Pixel_Sizes'
../SFML/lib/libsfml-graphics-d.so.2.5.1: undefined reference to `FT_Select_Charmap'
显示的错误是 SFML 无法 link,因为它找不到对不同 FT_
符号(FT_MulFix
、FT_Init_FreeType
等)的引用
这些由 FreeType 库定义。我假设您在 add_subdirectory(SFML)
在SFML
子目录下的CMakeLists.txt
文件中,你link针对自由类型的sfml-graphics
目标吗?
add_library(sfml-graphics
...)
# This is assuming you have a "freetype2" target available
# please replace by the actual name of the freetype target
target_link_libraries(sfml-graphics freetype2 ...)
编辑:感谢 Tsyvarev 为我指明了无法 link 的实际目标方向.