MinGW's linker (ld.exe) gives dozens of errors regarding the glfw3.lib static library file. Unlike the Visual Studio's (link.exe)

Advertisements

I’m not using any IDE.

Here is my only cmake file :

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}
)

If my mind doesn’t deceives me I handled the same issue in the mac environment using this cmake function :

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")

Linker error messages :

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

(Half of the error message lines are deleted)

I’m using these commands :

Generate build files :
cmake -G "MinGW Makefiles" ..

Compile the build folder :
cmake –build .

Visual Studio’s linker (link.exe) is linking the binary files successfuly.

How can I get the MinGW to link the binaries without a single error.

And also there are few ASSIMP linking errors tho.

I tried to switch from Visual Studio’s compiler to the MinGW compiler. However, MinGW’s linker couldn’t handle the GLFW library unlike the Visual Studio’s linker.

>Solution :

GNU ld cannot link 64-bit static libraries built with MSVC, where it can link 32-bit static libraries built with MSVC.

It’s best to use a 64-bit GCC-built glfw3.a.
You can obtain this for example by using MSYS2, which has prebuilt binary packages for a gigantic amount of libraries, including glfw3.

Leave a ReplyCancel reply