CMake 和 vcpkg x86_64-w64-mingw32/bin/ld: 交叉编译时找不到 -lOpenGL32
CMake and vcpkg x86_64-w64-mingw32/bin/ld: cannot find -lOpenGL32 when cross compiling
我正在制作使用 sfml、imgui-sfml 和 nlohmann 的项目 json。对于我的依赖,我正在使用 vcpkg。我的主机是 Arch,我想交叉构建到 Windows x64。我收到奇怪的链接错误,我在这里错过了一些简单的东西吗?这是我的工具链文件:
set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_SYSTEM_PROCESSOR x64)
# which tools to use
set(CMAKE_PREFIX_PATH /usr/x86_64-w64-mingw32/)
set(CMAKE_C_COMPILER /usr/bin/x86_64-w64-mingw32-gcc)
set(CMAKE_CXX_COMPILER /usr/bin/x86_64-w64-mingw32-g++)
set(CMAKE_FIND_ROOT_PATH /usr/x86_64-w64-mingw32)
# search headers and libraries in the target environment
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
这是我的自定义三胞胎:
set(VCPKG_TARGET_ARCHITECTURE x64)
set(VCPKG_CRT_LINKAGE dynamic)
set(VCPKG_LIBRARY_LINKAGE static)
set(VCPKG_CMAKE_SYSTEM_NAME MinGW)
set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE /home/bor/Dokumenty/proj/sokoban/toolchain-minwin.cmake)
我的 CMakeLists.txt(我没有在任何地方使用原始 opengl,只有 sfml)
cmake_minimum_required(VERSION 3.5)
cmake_policy(SET CMP0079 NEW)
project(sokoban VERSION 0.0.0
DESCRIPTION "Sokoban"
LANGUAGES CXX)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)
endif()
#c++17 standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
add_compile_options(-std=c++17)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
add_subdirectory(src)
#commented or not same error
find_package(OpenGL REQUIRED)
find_package(freetype CONFIG REQUIRED)
find_package(nlohmann_json CONFIG REQUIRED)
find_package(SFML COMPONENTS system window graphics CONFIG REQUIRED)
find_package(ImGui-SFML CONFIG REQUIRED)
find_package(imgui CONFIG REQUIRED)
target_link_libraries(sokoban PRIVATE nlohmann_json nlohmann_json::nlohmann_json)
target_link_libraries(sokoban PRIVATE sfml-system sfml-network sfml-graphics sfml-window)
target_link_libraries(sokoban PRIVATE ImGui-SFML::ImGui-SFML)
target_link_libraries(sokoban PRIVATE imgui::imgui)
target_link_libraries(sokoban PRIVATE freetype)
和我的错误
[bor@b0x build]$ cmake .. -DCMAKE_TOOLCHAIN_FILE=/home/bor/Dokumenty/proj/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-custom -DVCPKG_CHAINLOAD_TOOLCHAIN_FILE=/home/bor/Dokumenty/proj/sokoban/toolchain-minwin.cmake
-- The CXX compiler identification is GNU 10.2.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/x86_64-w64-mingw32-g++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found OpenGL: opengl32
-- Found ZLIB: optimized;/home/bor/Dokumenty/proj/vcpkg/installed/x64-custom/lib/libzlib.a;debug;/home/bor/Dokumenty/proj/vcpkg/installed/x64-custom/debug/lib/libzlibd.a (found version "1.2.11")
-- Found BZip2: optimized;/home/bor/Dokumenty/proj/vcpkg/installed/x64-custom/lib/libbz2.a;debug;/home/bor/Dokumenty/proj/vcpkg/installed/x64-custom/debug/lib/libbz2d.a (found version "1.0.8")
-- Looking for BZ2_bzCompressInit
-- Looking for BZ2_bzCompressInit - found
-- Found PNG: optimized;/home/bor/Dokumenty/proj/vcpkg/installed/x64-custom/debug/lib/libpng.a;debug;/home/bor/Dokumenty/proj/vcpkg/installed/x64-custom/debug/lib/libpng16d.a (found version "1.6.37")
-- Found nlohmann_json: /home/bor/Dokumenty/proj/vcpkg/installed/x64-custom/share/nlohmann_json/nlohmann_jsonConfig.cmake (found version "3.9.1")
-- Found Freetype: optimized;/home/bor/Dokumenty/proj/vcpkg/installed/x64-custom/lib/libfreetype.a;debug;/home/bor/Dokumenty/proj/vcpkg/installed/x64-custom/debug/lib/libfreetyped.a (found version "2.10.4")
-- Found SFML 2.5.1 in /home/bor/Dokumenty/proj/vcpkg/installed/x64-custom/share/sfml
-- Configuring done
-- Generating done
-- Build files have been written to: /home/bor/Dokumenty/proj/sokoban/build
[bor@b0x build]$ make
Scanning dependencies of target sokoban
[ 10%] Building CXX object src/CMakeFiles/sokoban.dir/main.cpp.obj
[ 20%] Building CXX object src/CMakeFiles/sokoban.dir/Game.cpp.obj
[ 30%] Building CXX object src/CMakeFiles/sokoban.dir/states/PlayingState.cpp.obj
[ 40%] Building CXX object src/CMakeFiles/sokoban.dir/states/MainMenuState.cpp.obj
[ 50%] Building CXX object src/CMakeFiles/sokoban.dir/states/LevelEditorState.cpp.obj
[ 60%] Building CXX object src/CMakeFiles/sokoban.dir/Level.cpp.obj
[ 70%] Building CXX object src/CMakeFiles/sokoban.dir/LevelConfig.cpp.obj
[ 80%] Building CXX object src/CMakeFiles/sokoban.dir/objects/Player.cpp.obj
[ 90%] Building CXX object src/CMakeFiles/sokoban.dir/map/Map.cpp.obj
[100%] Linking CXX executable ../sokoban.exe
/usr/lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld: cannot find -lOpenGL32
collect2: error: ld returned 1 exit status
make[2]: *** [src/CMakeFiles/sokoban.dir/build.make:255: sokoban.exe] Error 1
make[1]: *** [CMakeFiles/Makefile2:133: src/CMakeFiles/sokoban.dir/all] Error 2
make: *** [Makefile:103: all] Error 2
我设法通过将 libopengl32.a 与 libOpenGL32.a 进行符号链接来实现它。也许它很脏但至少它有效。我不知道这是 imgui/sfml 包中的拼写错误还是什么。
ln -s /usr/x86_64-w64-mingw32/lib/libopengl32.a /usr/x86_64-w64-mingw32/lib/libOpenGL32.a
我正在制作使用 sfml、imgui-sfml 和 nlohmann 的项目 json。对于我的依赖,我正在使用 vcpkg。我的主机是 Arch,我想交叉构建到 Windows x64。我收到奇怪的链接错误,我在这里错过了一些简单的东西吗?这是我的工具链文件:
set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_SYSTEM_PROCESSOR x64)
# which tools to use
set(CMAKE_PREFIX_PATH /usr/x86_64-w64-mingw32/)
set(CMAKE_C_COMPILER /usr/bin/x86_64-w64-mingw32-gcc)
set(CMAKE_CXX_COMPILER /usr/bin/x86_64-w64-mingw32-g++)
set(CMAKE_FIND_ROOT_PATH /usr/x86_64-w64-mingw32)
# search headers and libraries in the target environment
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
这是我的自定义三胞胎:
set(VCPKG_TARGET_ARCHITECTURE x64)
set(VCPKG_CRT_LINKAGE dynamic)
set(VCPKG_LIBRARY_LINKAGE static)
set(VCPKG_CMAKE_SYSTEM_NAME MinGW)
set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE /home/bor/Dokumenty/proj/sokoban/toolchain-minwin.cmake)
我的 CMakeLists.txt(我没有在任何地方使用原始 opengl,只有 sfml)
cmake_minimum_required(VERSION 3.5)
cmake_policy(SET CMP0079 NEW)
project(sokoban VERSION 0.0.0
DESCRIPTION "Sokoban"
LANGUAGES CXX)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)
endif()
#c++17 standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
add_compile_options(-std=c++17)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
add_subdirectory(src)
#commented or not same error
find_package(OpenGL REQUIRED)
find_package(freetype CONFIG REQUIRED)
find_package(nlohmann_json CONFIG REQUIRED)
find_package(SFML COMPONENTS system window graphics CONFIG REQUIRED)
find_package(ImGui-SFML CONFIG REQUIRED)
find_package(imgui CONFIG REQUIRED)
target_link_libraries(sokoban PRIVATE nlohmann_json nlohmann_json::nlohmann_json)
target_link_libraries(sokoban PRIVATE sfml-system sfml-network sfml-graphics sfml-window)
target_link_libraries(sokoban PRIVATE ImGui-SFML::ImGui-SFML)
target_link_libraries(sokoban PRIVATE imgui::imgui)
target_link_libraries(sokoban PRIVATE freetype)
和我的错误
[bor@b0x build]$ cmake .. -DCMAKE_TOOLCHAIN_FILE=/home/bor/Dokumenty/proj/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET=x64-custom -DVCPKG_CHAINLOAD_TOOLCHAIN_FILE=/home/bor/Dokumenty/proj/sokoban/toolchain-minwin.cmake
-- The CXX compiler identification is GNU 10.2.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/x86_64-w64-mingw32-g++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found OpenGL: opengl32
-- Found ZLIB: optimized;/home/bor/Dokumenty/proj/vcpkg/installed/x64-custom/lib/libzlib.a;debug;/home/bor/Dokumenty/proj/vcpkg/installed/x64-custom/debug/lib/libzlibd.a (found version "1.2.11")
-- Found BZip2: optimized;/home/bor/Dokumenty/proj/vcpkg/installed/x64-custom/lib/libbz2.a;debug;/home/bor/Dokumenty/proj/vcpkg/installed/x64-custom/debug/lib/libbz2d.a (found version "1.0.8")
-- Looking for BZ2_bzCompressInit
-- Looking for BZ2_bzCompressInit - found
-- Found PNG: optimized;/home/bor/Dokumenty/proj/vcpkg/installed/x64-custom/debug/lib/libpng.a;debug;/home/bor/Dokumenty/proj/vcpkg/installed/x64-custom/debug/lib/libpng16d.a (found version "1.6.37")
-- Found nlohmann_json: /home/bor/Dokumenty/proj/vcpkg/installed/x64-custom/share/nlohmann_json/nlohmann_jsonConfig.cmake (found version "3.9.1")
-- Found Freetype: optimized;/home/bor/Dokumenty/proj/vcpkg/installed/x64-custom/lib/libfreetype.a;debug;/home/bor/Dokumenty/proj/vcpkg/installed/x64-custom/debug/lib/libfreetyped.a (found version "2.10.4")
-- Found SFML 2.5.1 in /home/bor/Dokumenty/proj/vcpkg/installed/x64-custom/share/sfml
-- Configuring done
-- Generating done
-- Build files have been written to: /home/bor/Dokumenty/proj/sokoban/build
[bor@b0x build]$ make
Scanning dependencies of target sokoban
[ 10%] Building CXX object src/CMakeFiles/sokoban.dir/main.cpp.obj
[ 20%] Building CXX object src/CMakeFiles/sokoban.dir/Game.cpp.obj
[ 30%] Building CXX object src/CMakeFiles/sokoban.dir/states/PlayingState.cpp.obj
[ 40%] Building CXX object src/CMakeFiles/sokoban.dir/states/MainMenuState.cpp.obj
[ 50%] Building CXX object src/CMakeFiles/sokoban.dir/states/LevelEditorState.cpp.obj
[ 60%] Building CXX object src/CMakeFiles/sokoban.dir/Level.cpp.obj
[ 70%] Building CXX object src/CMakeFiles/sokoban.dir/LevelConfig.cpp.obj
[ 80%] Building CXX object src/CMakeFiles/sokoban.dir/objects/Player.cpp.obj
[ 90%] Building CXX object src/CMakeFiles/sokoban.dir/map/Map.cpp.obj
[100%] Linking CXX executable ../sokoban.exe
/usr/lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld: cannot find -lOpenGL32
collect2: error: ld returned 1 exit status
make[2]: *** [src/CMakeFiles/sokoban.dir/build.make:255: sokoban.exe] Error 1
make[1]: *** [CMakeFiles/Makefile2:133: src/CMakeFiles/sokoban.dir/all] Error 2
make: *** [Makefile:103: all] Error 2
我设法通过将 libopengl32.a 与 libOpenGL32.a 进行符号链接来实现它。也许它很脏但至少它有效。我不知道这是 imgui/sfml 包中的拼写错误还是什么。
ln -s /usr/x86_64-w64-mingw32/lib/libopengl32.a /usr/x86_64-w64-mingw32/lib/libOpenGL32.a