简体   繁体   中英

How can i static link an external library using g++?

I'm trying to build a program to test the use of an external library. When I try to build it I get a bunch of "undefined reference" errors.

The exact line that I'm using to compile is:

g++ main.cpp -L"../Dependencies/GLFW" -lglfw3

And the errors are:

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:\Users\SubSm\AppData\Local\Temp\ccQmEHZX.o:main.cpp:(.text+0x96): undefined reference to `_imp__glClear@4'
../Dependencies/GLFW/glfw3.lib(glfw.dir/Release/window.obj):(.text$mn+0xa): undefined reference to `__security_cookie'
../Dependencies/GLFW/glfw3.lib(glfw.dir/Release/window.obj):(.text$mn+0x45): undefined reference to `@__security_check_cookie@4'
../Dependencies/GLFW/glfw3.lib(glfw.dir/Release/window.obj):(.text$mn+0x237): undefined reference to `@__security_check_cookie@4'
../Dependencies/GLFW/glfw3.lib(glfw.dir/Release/init.obj):(.text$mn+0xa): undefined reference to `__security_cookie'
../Dependencies/GLFW/glfw3.lib(glfw.dir/Release/init.obj):(.text$mn+0x41): undefined reference to `_imp____stdio_common_vsprintf'
../Dependencies/GLFW/glfw3.lib(glfw.dir/Release/init.obj):(.text$mn+0x32b): undefined reference to `@__security_check_cookie@4'
../Dependencies/GLFW/glfw3.lib(glfw.dir/Release/context.obj):(.text$mn+0x7): undefined reference to `__security_cookie'
../Dependencies/GLFW/glfw3.lib(glfw.dir/Release/context.obj):(.text$mn+0x3d0): undefined reference to `@__security_check_cookie@4'
../Dependencies/GLFW/glfw3.lib(glfw.dir/Release/context.obj):(.text$mn+0x405): undefined reference to `@__security_check_cookie@4'
../Dependencies/GLFW/glfw3.lib(glfw.dir/Release/context.obj):(.text$mn+0x44e): undefined reference to `@__security_check_cookie@4'
../Dependencies/GLFW/glfw3.lib(glfw.dir/Release/context.obj):(.text$mn+0x4d6): undefined reference to `@__security_check_cookie@4'
../Dependencies/GLFW/glfw3.lib(glfw.dir/Release/context.obj):(.text$mn+0x508): undefined reference to `@__security_check_cookie@4'
../Dependencies/GLFW/glfw3.lib(glfw.dir/Release/context.obj):(.text$mn+0x54e): more undefined references to `@__security_check_cookie@4' follow
../Dependencies/GLFW/glfw3.lib(glfw.dir/Release/win32_window.obj):(.text$mn+0x7): undefined reference to `__security_cookie'
../Dependencies/GLFW/glfw3.lib(glfw.dir/Release/win32_window.obj):(.text$mn+0x3a): undefined reference to `@__security_check_cookie@4'
../Dependencies/GLFW/glfw3.lib(glfw.dir/Release/win32_window.obj):(.text$mn+0x143): undefined reference to `@__security_check_cookie@4'
../Dependencies/GLFW/glfw3.lib(glfw.dir/Release/win32_window.obj):(.text$mn+0x7): undefined reference to `__security_cookie'
../Dependencies/GLFW/glfw3.lib(glfw.dir/Release/win32_window.obj):(.text$mn+0xa): undefined reference to `__security_cookie'
../Dependencies/GLFW/glfw3.lib(glfw.dir/Release/win32_window.obj):(.text$mn+0x98): undefined reference to `_imp__CreateDIBSection@24'
../Dependencies/GLFW/glfw3.lib(glfw.dir/Release/win32_window.obj):(.text$mn+0xc8): undefined reference to `@__security_check_cookie@4'
../Dependencies/GLFW/glfw3.lib(glfw.dir/Release/win32_window.obj):(.text$mn+0xdd): undefined reference to `_imp__CreateBitmap@20'
../Dependencies/GLFW/glfw3.lib(glfw.dir/Release/win32_window.obj):(.text$mn+0x100): undefined reference to `_imp__DeleteObject@4'
../Dependencies/GLFW/glfw3.lib(glfw.dir/Release/win32_window.obj):(.text$mn+0x10f): undefined reference to `@__security_check_cookie@4'
../Dependencies/GLFW/glfw3.lib(glfw.dir/Release/win32_window.obj):(.text$mn+0x1b5): undefined reference to `_imp__DeleteObject@4'
../Dependencies/GLFW/glfw3.lib(glfw.dir/Release/win32_window.obj):(.text$mn+0x1fc): undefined reference to `@__security_check_cookie@4'
../Dependencies/GLFW/glfw3.lib(glfw.dir/Release/win32_window.obj):(.text$mn+0x7): undefined reference to `__security_cookie'
../Dependencies/GLFW/glfw3.lib(glfw.dir/Release/win32_window.obj):(.text$mn+0x187): undefined reference to `@__security_check_cookie@4'
../Dependencies/GLFW/glfw3.lib(glfw.dir/Release/win32_window.obj):(.text$mn+0x33c): undefined reference to `@__security_check_cookie@4'
../Dependencies/GLFW/glfw3.lib(glfw.dir/Release/win32_window.obj):(.text$mn+0x7): undefined reference to `__security_cookie'
../Dependencies/GLFW/glfw3.lib(glfw.dir/Release/win32_window.obj):(.text$mn+0x7a): undefined reference to `@__security_check_cookie@4'
../Dependencies/GLFW/glfw3.lib(glfw.dir/Release/win32_window.obj):(.text$mn+0x8c): undefined reference to `@__security_check_cookie@4'
../Dependencies/GLFW/glfw3.lib(glfw.dir/Release/win32_window.obj):(.text$mn+0x7): undefined reference to `__security_cookie'
../Dependencies/GLFW/glfw3.lib(glfw.dir/Release/win32_window.obj):(.text$mn+0x115): undefined reference to `@__security_check_cookie@4'
../Dependencies/GLFW/glfw3.lib(glfw.dir/Release/win32_window.obj):(.text$mn+0x7): undefined reference to `__security_cookie'
../Dependencies/GLFW/glfw3.lib(glfw.dir/Release/win32_window.obj):(.text$mn+0x6b): undefined reference to `@__security_check_cookie@4'
../Dependencies/GLFW/glfw3.lib(glfw.dir/Release/win32_window.obj):(.text$mn+0x7): undefined reference to `__security_cookie'
../Dependencies/GLFW/glfw3.lib(glfw.dir/Release/win32_monitor.obj):(.text$mn+0x49): undefined reference to `_imp__GetDeviceCaps@8'
../Dependencies/GLFW/glfw3.lib(glfw.dir/Release/win32_monitor.obj):(.text$mn+0xa): undefined reference to `__security_cookie'
../Dependencies/GLFW/glfw3.lib(glfw.dir/Release/win32_monitor.obj):(.text$mn+0x2b): undefined reference to `_imp__CreateDCW@16'
../Dependencies/GLFW/glfw3.lib(glfw.dir/Release/win32_monitor.obj):(.text$mn+0x3b): undefined reference to `_imp__GetDeviceGammaRamp@8'
../Dependencies/GLFW/glfw3.lib(glfw.dir/Release/win32_monitor.obj):(.text$mn+0x42): undefined reference to `_imp__DeleteDC@4'
../Dependencies/GLFW/glfw3.lib(glfw.dir/Release/win32_monitor.obj):(.text$mn+0x91): undefined reference to `@__security_check_cookie@4'
../Dependencies/GLFW/glfw3.lib(glfw.dir/Release/win32_monitor.obj):(.text$mn+0x3b): undefined reference to `_imp__GetDeviceCaps@8'
../Dependencies/GLFW/glfw3.lib(glfw.dir/Release/win32_monitor.obj):(.text$mn+0xa): undefined reference to `__security_cookie'
../Dependencies/GLFW/glfw3.lib(glfw.dir/Release/win32_monitor.obj):(.text$mn+0x77): undefined reference to `@__security_check_cookie@4'
../Dependencies/GLFW/glfw3.lib(glfw.dir/Release/win32_monitor.obj):(.text$mn+0x7): undefined reference to `__security_cookie'
../Dependencies/GLFW/glfw3.lib(glfw.dir/Release/win32_monitor.obj):(.text$mn+0x7f): undefined reference to `@__security_check_cookie@4'
../Dependencies/GLFW/glfw3.lib(glfw.dir/Release/wgl_context.obj):(.text$mn+0x87): undefined reference to `@__security_check_cookie@4'
../Dependencies/GLFW/glfw3.lib(glfw.dir/Release/wgl_context.obj):(.text$mn+0x13e): undefined reference to `_imp__DescribePixelFormat@16'
../Dependencies/GLFW/glfw3.lib(glfw.dir/Release/wgl_context.obj):(.text$mn+0x6e0): undefined reference to `_imp__DescribePixelFormat@16'
../Dependencies/GLFW/glfw3.lib(glfw.dir/Release/wgl_context.obj):(.text$mn+0x814): undefined reference to `@__security_check_cookie@4'
../Dependencies/GLFW/glfw3.lib(glfw.dir/Release/wgl_context.obj):(.text$mn+0x857): undefined reference to `@__security_check_cookie@4'
../Dependencies/GLFW/glfw3.lib(glfw.dir/Release/wgl_context.obj):(.text$mn+0x6c): undefined reference to `_imp__SwapBuffers@4'
collect2.exe: error: ld returned 1 exit status

I'm trying to link the GLFW library

Manual says that you have to link to more then just glfw3

GLFW: Building applications

With MinGW or Visual C++ on Windows

The static version of the GLFW library is named glfw3 . When using this version, it is also necessary to link with some libraries that GLFW uses.

When using MinGW to link an application with the static version of GLFW, you must also explicitly link with gdi32 . Other toolchains including MinGW-w64 include it in the set of default libraries along with other dependencies like user32 and kernel32 .

The link library for the GLFW DLL is named glfw3dll . When compiling an application that uses the DLL version of GLFW, you need to define the GLFW_DLL macro before any inclusion of the GLFW header. This can be done either with a compiler switch or by defining it in your source code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM