我已经将 SFML 和 TGUI 库链接到我的项目中。我还将这些库包含在该项目的另一个 CMakeLists 中。当我开始构建项目时,我收到一条消息,提示无法找到这些库中的文件。而且每次它似乎都只与 TGUI 连接。我甚至尝试使用 target_include_directories 来包含库头文件,但没有帮助。此外,该项目在搜索路径标头中列出了这两个库。
C:\Users\vinog\CLionProjects\url-player\ui\include\music_list.h(3): fatal error C1083: Cannot open include file: 'TGUI/Backend/SFML-Graphics.hpp': No such file or directory
mingw32-make[3]: *** [CMakeFiles\url_player.dir\build.make:75: CMakeFiles/url_player.dir/main.cpp.obj] Error 2
mingw32-make[2]: *** [CMakeFiles\Makefile2:137: CMakeFiles/url_player.dir/all] Error 2
mingw32-make[1]: *** [CMakeFiles\Makefile2:144: CMakeFiles/url_player.dir/rule] Error 2
mingw32-make: *** [Makefile:123: url_player] Error 2
我知道图书馆已经建立了。因为我看到了信息的内容。
我包括这样的库:
set(SFML_DIR ${SFML_PATH})
find_package(SFML COMPONENTS system window graphics REQUIRED PATHS ${SFML_DIR})
set(TGUI_DIR ${TGUI_PATH})
find_package(TGUI REQUIRED PATHS ${TGUI_DIR})
我尝试包含以下文件:
#include <TGUI/Backend/SFML-Graphics.hpp>
#include <TGUI/Widgets/Panel.hpp>
Cmake列表:
add_library(ui STATIC
src/music_list.cpp
src/button.cpp
ui-config/src/json-ui-config.cpp
src/menu.cpp
)
target_include_directories(ui PRIVATE ${TGUI_INCLUDE_DIR} include ${CMAKE_SOURCE_DIR}/json ui-config/include)
target_link_libraries(ui PRIVATE tgui sfml-system sfml-graphics sfml-window sfml-main music-storage json-storage)
我尝试清除缓存,重新加载 CMake 项目,重新链接库并重新创建发生错误的类。
完整命令行:
"C:\Program Files\JetBrains\CLion 2024.1.4\bin\cmake\win\x64\bin\cmake.exe" -SC:\Users\vinog\CLionProjects\url-player -BC:\Users\vinog\CLionProjects\url-player\cmake-build-debug --check-build-system CMakeFiles\Makefile.cmake 0
C:/mingw/bin/mingw32-make.exe -f CMakeFiles\Makefile2 url_player
mingw32-make[1]: Entering directory 'C:/Users/vinog/CLionProjects/url-player/cmake-build-debug'
"C:\Program Files\JetBrains\CLion 2024.1.4\bin\cmake\win\x64\bin\cmake.exe" -SC:\Users\vinog\CLionProjects\url-player -BC:\Users\vinog\CLionProjects\url-player\cmake-build-debug --check-build-system CMakeFiles\Makefile.cmake 0
"C:\Program Files\JetBrains\CLion 2024.1.4\bin\cmake\win\x64\bin\cmake.exe" -E cmake_progress_start C:\Users\vinog\CLionProjects\url-player\cmake-build-debug\CMakeFiles 11
C:/mingw/bin/mingw32-make.exe -f CMakeFiles\Makefile2 CMakeFiles/url_player.dir/all
mingw32-make[2]: Entering directory 'C:/Users/vinog/CLionProjects/url-player/cmake-build-debug'
C:/mingw/bin/mingw32-make.exe -f storage\CMakeFiles\json-storage.dir\build.make storage/CMakeFiles/json-storage.dir/depend
mingw32-make[3]: Entering directory 'C:/Users/vinog/CLionProjects/url-player/cmake-build-debug'
"C:\Program Files\JetBrains\CLion 2024.1.4\bin\cmake\win\x64\bin\cmake.exe" -E cmake_depends "MinGW Makefiles" C:\Users\vinog\CLionProjects\url-player C:\Users\vinog\CLionProjects\url-player\storage C:\Users\vinog\CLionProjects\url-player\cmake-build-debug C:\Users\vinog\CLionProjects\url-player\cmake-build-debug\storage C:\Users\vinog\CLionProjects\url-player\cmake-build-debug\storage\CMakeFiles\json-storage.dir\DependInfo.cmake "--color="
mingw32-make[3]: Leaving directory 'C:/Users/vinog/CLionProjects/url-player/cmake-build-debug'
C:/mingw/bin/mingw32-make.exe -f storage\CMakeFiles\json-storage.dir\build.make storage/CMakeFiles/json-storage.dir/build
mingw32-make[3]: Entering directory 'C:/Users/vinog/CLionProjects/url-player/cmake-build-debug'
[ 9%] Linking CXX static library json-storage.lib
cd /d C:\Users\vinog\CLionProjects\url-player\cmake-build-debug\storage && "C:\Program Files\JetBrains\CLion 2024.1.4\bin\cmake\win\x64\bin\cmake.exe" -P CMakeFiles\json-storage.dir\cmake_clean_target.cmake
cd /d C:\Users\vinog\CLionProjects\url-player\cmake-build-debug\storage && "C:\Program Files\JetBrains\CLion 2024.1.4\bin\cmake\win\x64\bin\cmake.exe" -E cmake_link_script CMakeFiles\json-storage.dir\link.txt --verbose=1
C:\PROGRA~1\MICROS~1\2022\COMMUN~1\VC\Tools\MSVC\1440~1.338\bin\Hostx64\x64\lib.exe /nologo /machine:x64 /out:json-storage.lib @CMakeFiles\json-storage.dir\objects1.rsp
mingw32-make[3]: Leaving directory 'C:/Users/vinog/CLionProjects/url-player/cmake-build-debug'
[ 18%] Built target json-storage
C:/mingw/bin/mingw32-make.exe -f music-storage\CMakeFiles\music-storage.dir\build.make music-storage/CMakeFiles/music-storage.dir/depend
mingw32-make[3]: Entering directory 'C:/Users/vinog/CLionProjects/url-player/cmake-build-debug'
"C:\Program Files\JetBrains\CLion 2024.1.4\bin\cmake\win\x64\bin\cmake.exe" -E cmake_depends "MinGW Makefiles" C:\Users\vinog\CLionProjects\url-player C:\Users\vinog\CLionProjects\url-player\music-storage C:\Users\vinog\CLionProjects\url-player\cmake-build-debug C:\Users\vinog\CLionProjects\url-player\cmake-build-debug\music-storage C:\Users\vinog\CLionProjects\url-player\cmake-build-debug\music-storage\CMakeFiles\music-storage.dir\DependInfo.cmake "--color="
mingw32-make[3]: Leaving directory 'C:/Users/vinog/CLionProjects/url-player/cmake-build-debug'
C:/mingw/bin/mingw32-make.exe -f music-storage\CMakeFiles\music-storage.dir\build.make music-storage/CMakeFiles/music-storage.dir/build
mingw32-make[3]: Entering directory 'C:/Users/vinog/CLionProjects/url-player/cmake-build-debug'
[ 27%] Linking CXX static library music-storage.lib
cd /d C:\Users\vinog\CLionProjects\url-player\cmake-build-debug\music-storage && "C:\Program Files\JetBrains\CLion 2024.1.4\bin\cmake\win\x64\bin\cmake.exe" -P CMakeFiles\music-storage.dir\cmake_clean_target.cmake
cd /d C:\Users\vinog\CLionProjects\url-player\cmake-build-debug\music-storage && "C:\Program Files\JetBrains\CLion 2024.1.4\bin\cmake\win\x64\bin\cmake.exe" -E cmake_link_script CMakeFiles\music-storage.dir\link.txt --verbose=1
C:\PROGRA~1\MICROS~1\2022\COMMUN~1\VC\Tools\MSVC\1440~1.338\bin\Hostx64\x64\lib.exe /nologo /machine:x64 /out:music-storage.lib @CMakeFiles\music-storage.dir\objects1.rsp
mingw32-make[3]: Leaving directory 'C:/Users/vinog/CLionProjects/url-player/cmake-build-debug'
[ 36%] Built target music-storage
C:/mingw/bin/mingw32-make.exe -f ui\CMakeFiles\ui.dir\build.make ui/CMakeFiles/ui.dir/depend
mingw32-make[3]: Entering directory 'C:/Users/vinog/CLionProjects/url-player/cmake-build-debug'
"C:\Program Files\JetBrains\CLion 2024.1.4\bin\cmake\win\x64\bin\cmake.exe" -E cmake_depends "MinGW Makefiles" C:\Users\vinog\CLionProjects\url-player C:\Users\vinog\CLionProjects\url-player\ui C:\Users\vinog\CLionProjects\url-player\cmake-build-debug C:\Users\vinog\CLionProjects\url-player\cmake-build-debug\ui C:\Users\vinog\CLionProjects\url-player\cmake-build-debug\ui\CMakeFiles\ui.dir\DependInfo.cmake "--color="
mingw32-make[3]: Leaving directory 'C:/Users/vinog/CLionProjects/url-player/cmake-build-debug'
C:/mingw/bin/mingw32-make.exe -f ui\CMakeFiles\ui.dir\build.make ui/CMakeFiles/ui.dir/build
mingw32-make[3]: Entering directory 'C:/Users/vinog/CLionProjects/url-player/cmake-build-debug'
[ 45%] Linking CXX static library ui.lib
cd /d C:\Users\vinog\CLionProjects\url-player\cmake-build-debug\ui && "C:\Program Files\JetBrains\CLion 2024.1.4\bin\cmake\win\x64\bin\cmake.exe" -P CMakeFiles\ui.dir\cmake_clean_target.cmake
cd /d C:\Users\vinog\CLionProjects\url-player\cmake-build-debug\ui && "C:\Program Files\JetBrains\CLion 2024.1.4\bin\cmake\win\x64\bin\cmake.exe" -E cmake_link_script CMakeFiles\ui.dir\link.txt --verbose=1
C:\PROGRA~1\MICROS~1\2022\COMMUN~1\VC\Tools\MSVC\1440~1.338\bin\Hostx64\x64\lib.exe /nologo /machine:x64 /out:ui.lib @CMakeFiles\ui.dir\objects1.rsp
mingw32-make[3]: Leaving directory 'C:/Users/vinog/CLionProjects/url-player/cmake-build-debug'
[ 81%] Built target ui
C:/mingw/bin/mingw32-make.exe -f CMakeFiles\url_player.dir\build.make CMakeFiles/url_player.dir/depend
mingw32-make[3]: Entering directory 'C:/Users/vinog/CLionProjects/url-player/cmake-build-debug'
"C:\Program Files\JetBrains\CLion 2024.1.4\bin\cmake\win\x64\bin\cmake.exe" -E cmake_depends "MinGW Makefiles" C:\Users\vinog\CLionProjects\url-player C:\Users\vinog\CLionProjects\url-player C:\Users\vinog\CLionProjects\url-player\cmake-build-debug C:\Users\vinog\CLionProjects\url-player\cmake-build-debug C:\Users\vinog\CLionProjects\url-player\cmake-build-debug\CMakeFiles\url_player.dir\DependInfo.cmake "--color="
mingw32-make[3]: Leaving directory 'C:/Users/vinog/CLionProjects/url-player/cmake-build-debug'
C:/mingw/bin/mingw32-make.exe -f CMakeFiles\url_player.dir\build.make CMakeFiles/url_player.dir/build
mingw32-make[3]: Entering directory 'C:/Users/vinog/CLionProjects/url-player/cmake-build-debug'
[ 90%] Building CXX object CMakeFiles/url_player.dir/main.cpp.obj
"C:\Program Files\JetBrains\CLion 2024.1.4\bin\cmake\win\x64\bin\cmake.exe" -E cmake_cl_compile_depends --dep-file=CMakeFiles\url_player.dir\main.cpp.obj.d --working-dir=C:\Users\vinog\CLionProjects\url-player\cmake-build-debug --filter-prefix="Note: including file: " -- C:\PROGRA~1\MICROS~1\2022\COMMUN~1\VC\Tools\MSVC\1440~1.338\bin\Hostx64\x64\cl.exe /nologo /TP /DWIN32 /D_WINDOWS /EHsc /Ob0 /Od /RTC1 -std:c++17 -MDd -Zi /showIncludes /FoCMakeFiles\url_player.dir\main.cpp.obj /FdCMakeFiles\url_player.dir/ /FS -c C:\Users\vinog\CLionProjects\url-player\main.cpp
main.cpp
C:\Users\vinog\CLionProjects\url-player\ui\include\music_list.h(3): fatal error C1083: Cannot open include file: 'TGUI/Backend/SFML-Graphics.hpp': No such file or directory
mingw32-make[3]: Leaving directory 'C:/Users/vinog/CLionProjects/url-player/cmake-build-debug'
mingw32-make[2]: Leaving directory 'C:/Users/vinog/CLionProjects/url-player/cmake-build-debug'
mingw32-make[1]: Leaving directory 'C:/Users/vinog/CLionProjects/url-player/cmake-build-debug'
mingw32-make[3]: *** [CMakeFiles\url_player.dir\build.make:78: CMakeFiles/url_player.dir/main.cpp.obj] Error 2
mingw32-make[2]: *** [CMakeFiles\Makefile2:140: CMakeFiles/url_player.dir/all] Error 2
mingw32-make[1]: *** [CMakeFiles\Makefile2:147: CMakeFiles/url_player.dir/rule] Error 2
mingw32-make: *** [Makefile:126: url_player] Error 2
问题出在你的
url_player
目标上,而不是ui
目标本身。你传递PRIVATE
给命令的target_include_directories
命令意味着它url_player
没有收到你为设置的包含路径ui
。要么改变
PRIVATE
为PUBLIC
(这样它才能传播),要么添加一个明确的另外,研究现代 CMake,其中包含目录是 TGUI 库目标的一部分,您只需链接到它,而不是单独设置包含目录。