0

So i managed to link FreeType2 with dynamically by just including the dependencies directories and not linking anything. Dynamically is cool and all but i would really like to link it statically. I tested precompiled binaries (which i got the dll from) and build my own (which i did by downloading, using cmake gui to build with the default options a .sln workspace and then clicked build all). But whatever i try to link or use statically, it will give me undefined references.

Heres the output:

MAKEFLAGS=s -j9 
COMPILER_PATH=c:/progra~1/mingw64/bin/../libexec/gcc/x86_64-w64-mingw32/10.2.0/;c:/progra~1/mingw64/bin/../libexec/gcc/;c:/progra~1/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/
LIBRARY_PATH=c:/progra~1/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/;c:/progra~1/mingw64/bin/../lib/gcc/;c:/progra~1/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/lib/../lib/;c:/progra~1/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../lib/;c:/progra~1/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/lib/;c:/progra~1/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../
COLLECT_GCC_OPTIONS='-g' '-v' '-o' 'UI.exe' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 c:/progra~1/mingw64/bin/../libexec/gcc/x86_64-w64-mingw32/10.2.0/collect2.exe -plugin c:/progra~1/mingw64/bin/../libexec/gcc/x86_64-w64-mingw32/10.2.0/liblto_plugin-0.dll -plugin-opt=c:/progra~1/mingw64/bin/../libexec/gcc/x86_64-w64-mingw32/10.2.0/lto-wrapper.exe -plugin-opt=-fresolution=C:\Users\Eric\AppData\Local\Temp\ccoaWDLZ.res -plugin-opt=-pass-through=-lmingw32 -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lmoldname -plugin-opt=-pass-through=-lmingwex -plugin-opt=-pass-through=-lmsvcrt -plugin-opt=-pass-through=-lpthread -plugin-opt=-pass-through=-ladvapi32 -plugin-opt=-pass-through=-lshell32 -plugin-opt=-pass-through=-luser32 -plugin-opt=-pass-through=-lkernel32 -plugin-opt=-pass-through=-lmingw32 -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lmoldname -plugin-opt=-pass-through=-lmingwex -plugin-opt=-pass-through=-lmsvcrt -m i386pep -Bdynamic -o UI.exe c:/progra~1/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/lib/../lib/crt2.o c:/progra~1/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/crtbegin.o -Lc:/progra~1/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0 -Lc:/progra~1/mingw64/bin/../lib/gcc -Lc:/progra~1/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/lib/../lib -Lc:/progra~1/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../lib -Lc:/progra~1/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/lib -Lc:/progra~1/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../.. @C:\Users\Eric\AppData\Local\Temp\ccmOOCrP -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt -lpthread -ladvapi32 -lshell32 -luser32 -lkernel32 -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt c:/progra~1/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/crtend.o
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:/progra~1/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ../Dependencies/FreeType/freetype.lib(../../../objs/x64/Release Static/bdf.obj):(.xdata[$unwind$_bdf_parse_properties]+0x18): undefined reference to `__GSHandlerCheck'
c:/progra~1/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
-This repeats for a while-
../Dependencies/FreeType/freetype.lib(../../../objs/x64/Release Static/bdf.obj):(.xdata[$unwind$_bdf_parse_start]+0x1c): undefined reference to `__GSHandlerCheck'
c:/progra~1/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ../Dependencies/FreeType/freetype.lib(../../../objs/x64/Release Static/bdf.obj):(.xdata[$unwind$bdf_interpret_style]+0x1c): undefined reference to `__GSHandlerCheck'
c:/progra~1/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: ../Dependencies/FreeType/freetype.lib(../../../objs/x64/Release Static/bdf.obj):(.xdata[$unwind$BDF_Face_Init]+0x14): undefined reference to `__GSHandlerCheck'
collect2.exe: error: ld returned 1 exit status
mingw32-make[3]: *** [CMakeFiles\UI.dir\build.make:269: UI.exe] Error 1
mingw32-make[2]: *** [CMakeFiles\Makefile2:94: CMakeFiles/UI.dir/all] Error 2
mingw32-make[1]: *** [CMakeFiles\Makefile2:101: CMakeFiles/UI.dir/rule] Error 2
mingw32-make: *** [makefile:136: UI] Error 2

Heres my cmake file:

make_minimum_required(VERSION 3.7)
project(UI)

set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)

set(FREETYPE_LIBRARIES ${CMAKE_CURRENT_LIST_DIR}/Dependencies/FreeType/freetype.lib)
set(FREETYPE_INCLUDE_DIRS ${CMAKE_CURRENT_LIST_DIR}/Dependencies/FreeType/include)

set(CMAKE_CXX_STANDARD 20)

file(GLOB_RECURSE SOURCE_FILES "UI/*.cpp" "UI/*.h" "Sandbox/*.cpp" "Sandbox/*.h")
file(GLOB_RECURSE DEP_FILES "Dependencies/FreeType/src/*.c" "Dependencies/FreeType/src/*.h")

set(dir ${CMAKE_CURRENT_SOURCE_DIR})

include_directories(Dependencies)

include_directories(${PROJECT_NAME} "Dependencies/OpenGL/include")
include_directories(${PROJECT_NAME} "Dependencies/Math/include")
include_directories(${PROJECT_NAME} "Dependencies/GLFW/include")
include_directories(${PROJECT_NAME} "Dependencies/FreeType/include")

include_directories(${PROJECT_NAME})

add_executable(${PROJECT_NAME} ${SOURCE_FILES})

target_link_libraries(${PROJECT_NAME}
        ${CMAKE_CURRENT_LIST_DIR}/Dependencies/FreeType/freetype.lib
        ${CMAKE_CURRENT_LIST_DIR}/Dependencies/OpenGL/OpenGL.a
        ${CMAKE_CURRENT_LIST_DIR}/Dependencies/Math/Math.a
        ${CMAKE_CURRENT_LIST_DIR}/Dependencies/GLFW/libglfw3.a
        )

If anyone has any idea youre welcome to help me out :) Have a great day.

  • Please, show (add to the question post) the **exact error message** you got. In case of several error messages it is sufficient to show only the first one. – Tsyvarev Apr 30 '21 at 09:15
  • Sure thing, doubt thats gonna help but ill do everything – Eric Böwer Apr 30 '21 at 09:50
  • 1
    It seems your `freetype.lib` library is built for Visual Studio. You cannot use this library when build the project in MinGW. And the `Warning: corrupt .drectve at end of def file` hints about that incompatibility. – Tsyvarev Apr 30 '21 at 10:23
  • OOoooohhh, alright. Thank you, uhm, how can i build it for Mingw/CMake? The thing is that i build it myself using cmake gui, but obviously using VS 16 Compiler or something along those lines. So how can i build it for mingw/cmake? – Eric Böwer Apr 30 '21 at 14:31
  • When build FreeType using CMake GUI, select appropriate [generator](https://cmake.org/cmake/help/latest/manual/cmake-generators.7.html): it should be `MinGW Makefiles`. – Tsyvarev Apr 30 '21 at 14:34
  • Alright, but how do i build it now? It gives me two header files and says it generated everything without a problem. But i cant find a dll nor a .lib/.a – Eric Böwer Apr 30 '21 at 18:32
  • "Generated" means that it prepares Makefiles. These Makefiles could be built using `mingw32-make` from the build directory. Also there is universal way for build a CMake project: `cmake --build .` See that question: https://stackoverflow.com/questions/8558703/building-msvc-project-with-cmake-and-command-line – Tsyvarev Apr 30 '21 at 19:00
  • OMG THANK YOU YAAAAAAAAAAAAAAAAAAAAAAAA Ive been trying to do this for a year now. Never realised i had to scroll down. Everyone hated cmake. And so do i. But you did the trick, thank you so much man. My god you are one hell of a person. If you ever come to germany ill owe you a beer or two. – Eric Böwer Apr 30 '21 at 19:05

0 Answers0