【问题标题】:Cmake not linking when building sfml构建 sfml 时 Cmake 未链接
【发布时间】:2019-10-30 19:09:12
【问题描述】:

我有我的项目,嵌套在另一个目录中,其中包含我的项目所需的库。我正在使用与 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'

【问题讨论】:

  • 现在您显示的代码中没有target_link_libraries。应该有。
  • Root CmakeList.txt中应该有吗?此外,已编辑。
  • undefined reference 是您遇到的第一个错误吗?可能链接器找不到链接到libsfml-graphics one 的 FreeType 库。

标签: c++ cmake sfml


【解决方案1】:

显示的错误是 SFML 无法链接,因为它找不到对不同 FT_ 符号的引用(FT_MulFixFT_Init_FreeType 等)

这些是由 FreeType 库定义的。我假设您在add_subdirectory(SFML)

时正在构建不同的 SFML 目标

SFML 子目录下的CMakeLists.txt 文件中,是否将sfml-graphics 目标与Free 类型相关联?

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 将我指向无法链接的实际目标的方向。

【讨论】:

  • 一个动态 (.so) 库总是 存储指向它所需库的链接。无需链接到 dymanic 所需的库。
  • 原来是cmake ... sfml_add_library(sfml-graphics SOURCES ${SRC} ${DRAWABLES_SRC} ${RENDER_TEXTURE_SRC} ${STB_SRC}) # setup dependencies target_link_libraries(sfml-graphics PUBLIC sfml-window freetype)
猜你喜欢
  • 1970-01-01
  • 2020-06-19
  • 2018-01-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-10
  • 1970-01-01
  • 2021-10-24
相关资源
最近更新 更多