繁体   English   中英

如何使用 g++ 静态链接外部库?

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

我正在尝试构建一个程序来测试外部库的使用。 当我尝试构建它时,我收到了一堆“未定义的引用”错误。

我用来编译的确切行是:

g++ main.cpp -L"../Dependencies/GLFW" -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
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

我正在尝试链接GLFW

手册说你必须链接到更多然后只是glfw3

GLFW:构建应用程序

在 Windows 上使用 MinGW 或 Visual C++

GLFW 库的静态版本名为glfw3 使用这个版本的时候,还需要链接一些GLFW使用的库。

当使用 MinGW 将应用程序与 GLFW 的静态版本链接时,您还必须显式链接gdi32 包括 MinGW-w64 在内的其他工具链将它与其他依赖项(如user32kernel32一起包含在默认库集中。

GLFW DLL 的链接库名为glfw3dll 在编译使用 GLFW DLL 版本的应用程序时,您需要包含 GLFW 头文件之前定义GLFW_DLL宏。 这可以通过编译器开关或通过在源代码中定义来完成。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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