【问题标题】:How can i static link an external library using g++?如何使用 g++ 静态链接外部库?
【发布时间】:2020-03-30 17:53:05
【问题描述】:

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

我用来编译的确切行是:

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

【问题讨论】:

  • GLFW 依赖于一个或多个其他库(至少看起来像 GDI)。您还需要链接到它们。

标签: c++ g++ mingw opengl-3


【解决方案1】:

手册说你必须链接到更多,而不仅仅是glfw3

GLFW: Building applications

在 Windows 上使用 MinGW 或 Visual C++

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-02-23
    • 1970-01-01
    • 2011-09-03
    • 1970-01-01
    • 1970-01-01
    • 2023-03-03
    • 1970-01-01
    相关资源
    最近更新 更多