提问人:LucasSokol 提问时间:7/4/2023 最后编辑:Rabbid76LucasSokol 更新时间:7/7/2023 访问量:148
MinGW的链接器(ld.exe)给出了关于glfw3.lib静态库文件的数十个错误。与Visual Studio的(link.exe)不同
MinGW's linker (ld.exe) gives dozens of errors regarding the glfw3.lib static library file. Unlike the Visual Studio's (link.exe)
问:
我没有使用任何IDE。
这是我唯一的cmake文件:
cmake_minimum_required(VERSION 3.8)
project(App VERSION 1.3)
file(GLOB_RECURSE APP_SOURCES
${PROJECT_SOURCE_DIR}/*.cpp
${PROJECT_SOURCE_DIR}/*.c
)
# Set C++ standard to C++17
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Define CMAKE_HAS_X
add_definitions(-DCMAKE_HAS_X)
if(WIN32)
# Add Windows-specific configurations
add_executable(
MyApp
${APP_SOURCES}
${CMAKE_SOURCE_DIR}/Installer/AppIcon.rc
)
target_compile_definitions(MyApp PRIVATE CRT)
else()
# Add non-Windows configurations
add_executable(
MyApp
${APP_SOURCES}
)
endif(WIN32)
# Installer
install(TARGETS MyApp)
install(
FILES
${CMAKE_SOURCE_DIR}/freetype.dll
${CMAKE_SOURCE_DIR}/assimp-vc142-mtd.dll
${CMAKE_SOURCE_DIR}/OpenAL32.dll
DESTINATION bin
)
install(
DIRECTORY
${CMAKE_SOURCE_DIR}/Resources
DESTINATION bin
)
# Add include directories for MyApp target
target_include_directories(MyApp PRIVATE ${PROJECT_SOURCE_DIR}/Main/thirdparty/include/)
target_include_directories(MyApp PRIVATE ${PROJECT_SOURCE_DIR}/Main/thirdparty)
target_include_directories(MyApp PRIVATE ${PROJECT_SOURCE_DIR}/Main/src)
# Add link directories for MyApp target
target_link_directories(MyApp PRIVATE
${PROJECT_SOURCE_DIR}/Main/thirdparty/lib
${PROJECT_SOURCE_DIR}/Main/thirdparty/lib/freetype
${PROJECT_SOURCE_DIR}
)
# Include directories for X11 and GLFW
include_directories(${X11_INCLUDE_DIR})
include_directories(${GLFW_INCLUDE_DIRS})
# Link libraries for MyApp target
target_link_libraries(MyApp PRIVATE
freetype
assimp-vc142-mtd
OpenAL32
glfw3
${X11_LIBRARIES}
${GLFW_LIBRARIES}
)
如果我的思想没有欺骗我,我使用这个 cmake 函数在 mac 环境中处理了同样的问题:
set(CMAKE_EXE_LINKER_FLAGS “${CMAKE_EXE_LINKER_FLAGS} ${GCC_COVERAGE_LINKER_FLAGS} -I/usr/local/lib -framework Cocoa -framework IOKit -framework CoreVideo -framework OpenGL -lglfw3”)
链接器错误消息:
Warning: corrupt .drectve at end of def file
Warning: corrupt .drectve at end of def file
Warning: corrupt .drectve at end of def file
Warning: corrupt .drectve at end of def file
Warning: corrupt .drectve at end of def file
Warning: corrupt .drectve at end of def file
Warning: corrupt .drectve at end of def file
Warning: corrupt .drectve at end of def file
Warning: corrupt .drectve at end of def file
Warning: corrupt .drectve at end of def file
Warning: corrupt .drectve at end of def file
Warning: corrupt .drectve at end of def file
Warning: corrupt .drectve at end of def file
Warning: corrupt .drectve at end of def file
Warning: corrupt .drectve at end of def file
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\App.dir/objects.a(ExportModel.cpp.obj):ExportModel.cp:(.text+0x86):
undefined reference to `Assimp::Exporter::Exporter()'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\App.dir/objects.a(ExportModel.cpp.obj):ExportModel.cp:(.text+0x9a):
undefined reference to `Assimp::Exporter::GetExportFormatDescription(unsigned long long) const'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\App.dir/objects.a(ExportModel.cpp.obj):ExportModel.cp:(.text+0x1bc): undefined reference to `Assimp::Exporter::~Exporter()'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\App.dir/objects.a(ExportModel.cpp.obj):ExportModel.cp:(.text+0x22c): undefined reference to `Assimp::Exporter::~Exporter()'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\App.dir/objects.a(ExportModel.cpp.obj):ExportModel.cp:(.text+0x273): undefined reference to `aiScene::aiScene()'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\App.dir/objects.a(ExportModel.cpp.obj):ExportModel.cp:(.text+0x497): undefined reference to `aiNode::aiNode()'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\App.dir/objects.a(ExportModel.cpp.obj):ExportModel.cp:(.text$_ZN6Assimp8Exporter6ExportEPK7aiSceneRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESB_jPKNS_16ExportPropertiesE[_ZN6Assimp8Exporter6ExportEPK7aiSceneRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESB_jPKNS_16ExportPropertiesE]+0x5d): undefined reference to `Assimp::Exporter::Export(aiScene const*, char const*, char const*, unsigned int, Assimp::ExportProperties const*)'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\App.dir/objects.a(LoadModel.cpp.obj):LoadModel.cpp:(.text+0x116): undefined reference to `Assimp::Importer::Importer()'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\App.dir/objects.a(LoadModel.cpp.obj):LoadModel.cpp:(.text+0x1a4): undefined reference to `Assimp::Importer::GetErrorString() const'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\App.dir/objects.a(LoadModel.cpp.obj):LoadModel.cpp:(.text+0x247): undefined reference to `Assimp::Importer::~Importer()'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\App.dir/objects.a(LoadModel.cpp.obj):LoadModel.cpp:(.text+0x295): undefined reference to `Assimp::Importer::~Importer()'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\App.dir/objects.a(LoadModel.cpp.obj):LoadModel.cpp:(.text+0x88d): undefined reference to `aiMaterial::GetName() const'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\App.dir/objects.a(LoadModel.cpp.obj):LoadModel.cpp:(.text$_ZN6Assimp8Importer8ReadFileERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEj[_ZN6Assimp8Importer8ReadFileERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEj]+0x31): undefined reference to `Assimp::Importer::ReadFile(char const*, unsigned int)'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/PrimaryUser/source/repos/App/Main/thirdparty/lib/glfw3.lib(glfw.dir/Debug/window.obj):(.text$mn+0x8f4): undefined reference to `__security_cookie'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/PrimaryUser/source/repos/App/Main/thirdparty/lib/glfw3.lib(glfw.dir/Debug/window.obj):(.text$mn+0xc41): undefined reference to `_RTC_CheckStackVars'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/PrimaryUser/source/repos/App/Main/thirdparty/lib/glfw3.lib(glfw.dir/Debug/window.obj):(.text$mn+0xc54): undefined reference to `__security_check_cookie'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/PrimaryUser/source/repos/App/Main/thirdparty/lib/glfw3.lib(glfw.dir/Debug/window.obj):(.xdata+0x24): undefined reference to `__GSHandlerCheck'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/PrimaryUser/source/repos/App/Main/thirdparty/lib/glfw3.lib(glfw.dir/Debug/window.obj):(.rtc$IMZ+0x0): undefined reference to `_RTC_InitBase'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/PrimaryUser/source/repos/App/Main/thirdparty/lib/glfw3.lib(glfw.dir/Debug/window.obj):(.rtc$TMZ+0x0): undefined reference to `_RTC_Shutdown'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/PrimaryUser/source/repos/App/Main/thirdparty/lib/glfw3.lib(glfw.dir/Debug/monitor.obj):(.text$mn+0xa1e): undefined reference to `_RTC_CheckStackVars'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/PrimaryUser/source/repos/App/Main/thirdparty/lib/glfw3.lib(glfw.dir/Debug/monitor.obj):(.text$mn+0xf27): undefined reference to `_RTC_CheckStackVars'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/PrimaryUser/source/repos/App/Main/thirdparty/lib/glfw3.lib(glfw.dir/Debug/monitor.obj):(.text$mn+0x1689): undefined reference to `_RTC_CheckStackVars'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/PrimaryUser/source/repos/App/Main/thirdparty/lib/glfw3.lib(glfw.dir/Debug/input.obj):(.text$mn+0x1d68): undefined reference to `__security_cookie'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/PrimaryUser/source/repos/App/Main/thirdparty/lib/glfw3.lib(glfw.dir/Debug/input.obj):(.text$mn+0x1ec1): undefined reference to `__report_rangecheckfailure'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/PrimaryUser/source/repos/App/Main/thirdparty/lib/glfw3.lib(glfw.dir/Debug/input.obj):(.text$mn+0x2067): undefined reference to `_RTC_CheckStackVars'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/PrimaryUser/source/repos/App/Main/thirdparty/lib/glfw3.lib(glfw.dir/Debug/input.obj):(.text$mn+0x207a): undefined reference to `__security_check_cookie'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/PrimaryUser/source/repos/App/Main/thirdparty/lib/glfw3.lib(glfw.dir/Debug/input.obj):(.text$mn+0x33a6): undefined reference to `_RTC_CheckStackVars'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/PrimaryUser/source/repos/App/Main/thirdparty/lib/glfw3.lib(glfw.dir/Debug/input.obj):(.text$mn+0x35fc): undefined reference to `__security_cookie'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/PrimaryUser/source/repos/App/Main/thirdparty/lib/glfw3.lib(glfw.dir/Debug/input.obj):(.text$mn+0x3e35): undefined reference to `_RTC_CheckStackVars'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/PrimaryUser/source/repos/App/Main/thirdparty/lib/glfw3.lib(glfw.dir/Debug/input.obj):(.text$mn+0x3e48): undefined reference to `__security_check_cookie'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/PrimaryUser/source/repos/App/Main/thirdparty/lib/glfw3.lib(glfw.dir/Debug/input.obj):(.xdata+0x104): undefined reference to `__GSHandlerCheck'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/PrimaryUser/source/repos/App/Main/thirdparty/lib/glfw3.lib(glfw.dir/Debug/input.obj):(.xdata+0x1e8): undefined reference to `__GSHandlerCheck'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/PrimaryUser/source/repos/App/Main/thirdparty/lib/glfw3.lib(glfw.dir/Debug/init.obj):(.text$mn+0x394): undefined reference to `__security_cookie'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/PrimaryUser/source/repos/App/Main/thirdparty/lib/glfw3.lib(glfw.dir/Debug/init.obj):(.text$mn+0x3d9): undefined reference to `vsnprintf'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/PrimaryUser/source/repos/App/Main/thirdparty/lib/glfw3.lib(glfw.dir/Debug/init.obj):
collect2.exe: error: ld returned 1 exit status
(删除了一半的错误消息行)
我正在使用这些命令:
生成构建文件: cmake -G “MinGW Makefiles” ..
编译构建文件夹: cmake --构建。
Visual Studio 的链接器 (link.exe) 正在成功链接二进制文件。
如何让 MinGW 链接二进制文件而不会出现任何错误。
而且ASSIMP链接错误也很少。
我尝试从 Visual Studio 的编译器切换到 MinGW 编译器。但是,与 Visual Studio 的链接器不同,MinGW 的链接器无法处理 GLFW 库。
答:
2赞
rubenvb
7/4/2023
#1
GNU ld 无法链接使用 MSVC 构建的 64 位静态库,而它可以链接使用 MSVC 构建的 32 位静态库。
最好使用 64 位 GCC 构建的 .
例如,您可以使用 MSYS2 来获取此信息,MSYS2 为大量库(包括 glfw3)预构建了二进制包。glfw3.a
评论