我正在关注OpenGL教程(在Windows上)。我正在尝试使用glfw创建图形上下文,但是无法获得我下载的静态库以链接到我的源代码。如果我改用glfw dll,则一切正常,并且可以运行我的程序,但是我不想对glfw dll具有运行时依赖性。
我当前的目录结构如下:
root_folder:
externs:
GLFW:
glfw3.lib
glfw3.h
glfw3native.h
window.c
我使用以下命令编译代码:
gcc window.c -o window.exe -L externs/GLFW -lglfw3 -lopengl32
但是,当我执行此操作时,会得到以下令人讨厌(且令人发指的长)输出:
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
externs/GLFW/glfw3.lib(glfw.dir/Release/window.obj):(.text$mn+0x29e): undefined reference to `__security_check_cookie'
externs/GLFW/glfw3.lib(glfw.dir/Release/window.obj):(.xdata[$unwind$glfwCreateWindow]+0x10): undefined reference to `__GSHandlerCheck'
externs/GLFW/glfw3.lib(glfw.dir/Release/input.obj):(.text$mn+0x286): undefined reference to `__security_check_cookie'
externs/GLFW/glfw3.lib(glfw.dir/Release/input.obj):(.text$mn+0x790): undefined reference to `__security_check_cookie'
externs/GLFW/glfw3.lib(glfw.dir/Release/input.obj):(.xdata[$unwind$glfwUpdateGamepadMappings]+0xc): undefined reference to `__GSHandlerCheck'
externs/GLFW/glfw3.lib(glfw.dir/Release/input.obj):(.xdata[$unwind$parseMapping]+0x10): undefined reference to `__GSHandlerCheck'
externs/GLFW/glfw3.lib(glfw.dir/Release/init.obj):(.text$mn+0x73): undefined reference to `__imp___stdio_common_vsprintf'
externs/GLFW/glfw3.lib(glfw.dir/Release/init.obj):(.text$mn+0x327): undefined reference to `__security_check_cookie'
externs/GLFW/glfw3.lib(glfw.dir/Release/init.obj):(.xdata[$unwind$_glfwInputError]+0xc): undefined reference to `__GSHandlerCheck'
externs/GLFW/glfw3.lib(glfw.dir/Release/context.obj):(.text$mn+0x3be): undefined reference to `__security_check_cookie'
externs/GLFW/glfw3.lib(glfw.dir/Release/context.obj):(.xdata[$unwind$_glfwRefreshContextAttribs]+0x18): undefined reference to `__GSHandlerCheck'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_window.obj):(.text$mn+0x50): undefined reference to `__security_check_cookie'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_window.obj):(.text$mn+0x1a7): undefined reference to `__security_check_cookie'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_window.obj):(.text$mn+0x50): undefined reference to `__security_check_cookie'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_window.obj):(.text$mn+0x1cb): undefined reference to `__security_check_cookie'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_window.obj):(.text$mn+0x84): undefined reference to `__security_check_cookie'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_window.obj):(.text$mn+0x3ec): more undefined references to `__security_check_cookie' follow
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_window.obj):(.text$mn+0xcb): undefined reference to `__imp_CreateDIBSection'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_window.obj):(.text$mn+0x10f): undefined reference to `__imp_CreateBitmap'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_window.obj):(.text$mn+0x131): undefined reference to `__imp_DeleteObject'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_window.obj):(.text$mn+0x1d3): undefined reference to `__imp_DeleteObject'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_window.obj):(.text$mn+0x1dc): undefined reference to `__imp_DeleteObject'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_window.obj):(.text$mn+0x20d): undefined reference to `__security_check_cookie'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_window.obj):(.text$mn+0x36e): undefined reference to `__security_check_cookie'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_window.obj):(.text$mn+0x91): undefined reference to `__security_check_cookie'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_window.obj):(.text$mn+0x8e): undefined reference to `__security_check_cookie'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_window.obj):(.text$mn+0x67): undefined reference to `__security_check_cookie'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_window.obj):(.text$mn+0x50): undefined reference to `__imp_CreateRectRgn'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_window.obj):(.text$mn+0xd6): undefined reference to `__imp_DeleteObject'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_window.obj):(.text$mn+0x167): undefined reference to `__security_check_cookie'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_window.obj):(.text$mn+0x76a): undefined reference to `__security_check_cookie'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_window.obj):(.xdata[$unwind$_glfwPlatformSetWindowPos]+0xc): undefined reference to `__GSHandlerCheck'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_window.obj):(.xdata[$unwind$_glfwPlatformGetWindowSize]+0xc): undefined reference to `__GSHandlerCheck'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_window.obj):(.xdata[$unwind$_glfwPlatformSetWindowSize]+0x8): undefined reference to `__GSHandlerCheck'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_window.obj):(.xdata[$unwind$_glfwPlatformSetWindowSizeLimits]+0x8): undefined reference to `__GSHandlerCheck'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_window.obj):(.xdata[$unwind$_glfwPlatformSetWindowAspectRatio]+0x8): undefined reference to `__GSHandlerCheck'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_window.obj):(.xdata[$unwind$_glfwPlatformGetFramebufferSize]+0xc): more undefined references to `__GSHandlerCheck' follow
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_monitor.obj):(.text$mn+0x57): undefined reference to `__imp_GetDeviceCaps'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_monitor.obj):(.text$mn+0x69): undefined reference to `__imp_GetDeviceCaps'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_monitor.obj):(.text$mn+0x38): undefined reference to `__imp_CreateDCW'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_monitor.obj):(.text$mn+0x49): undefined reference to `__imp_GetDeviceGammaRamp'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_monitor.obj):(.text$mn+0x52): undefined reference to `__imp_DeleteDC'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_monitor.obj):(.text$mn+0x196): undefined reference to `__security_check_cookie'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_monitor.obj):(.text$mn+0x5b): undefined reference to `__imp_GetDeviceCaps'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_monitor.obj):(.text$mn+0x6d): undefined reference to `__imp_GetDeviceCaps'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_monitor.obj):(.text$mn+0x82): undefined reference to `__security_check_cookie'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_monitor.obj):(.text$mn+0x91): undefined reference to `__security_check_cookie'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_monitor.obj):(.text$mn+0x9b): undefined reference to `__security_check_cookie'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_monitor.obj):(.text$mn+0x207): undefined reference to `__security_check_cookie'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_monitor.obj):(.text$mn+0x45): undefined reference to `__security_check_cookie'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_monitor.obj):(.text$mn+0x19a): undefined reference to `__imp_CreateDCW'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_monitor.obj):(.text$mn+0x1ab): undefined reference to `__imp_SetDeviceGammaRamp'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_monitor.obj):(.text$mn+0x1b4): undefined reference to `__imp_DeleteDC'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_monitor.obj):(.text$mn+0x1cc): undefined reference to `__security_check_cookie'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_monitor.obj):(.text$mn+0x2f3): undefined reference to `__security_check_cookie'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_monitor.obj):(.text$mn+0x17f): undefined reference to `__security_check_cookie'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_monitor.obj):(.text$mn+0xa8): undefined reference to `__imp_CreateDCW'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_monitor.obj):(.text$mn+0xcc): undefined reference to `__imp_GetDeviceCaps'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_monitor.obj):(.text$mn+0xdd): undefined reference to `__imp_GetDeviceCaps'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_monitor.obj):(.text$mn+0x10c): undefined reference to `__imp_GetDeviceCaps'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_monitor.obj):(.text$mn+0x141): undefined reference to `__imp_GetDeviceCaps'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_monitor.obj):(.text$mn+0x162): undefined reference to `__imp_DeleteDC'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_monitor.obj):(.text$mn+0x2c0): undefined reference to `__security_check_cookie'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_monitor.obj):(.text$mn+0xb7): undefined reference to `__security_check_cookie'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_monitor.obj):(.xdata[$unwind$_glfwPollMonitorsWin32]+0x20): undefined reference to `__GSHandlerCheck'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_monitor.obj):(.xdata[$unwind$_glfwSetVideoModeWin32]+0x10): undefined reference to `__GSHandlerCheck'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_monitor.obj):(.xdata[$unwind$_glfwPlatformGetMonitorPos]+0x14): undefined reference to `__GSHandlerCheck'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_monitor.obj):(.xdata[$unwind$_glfwPlatformGetMonitorWorkarea]+0x10): undefined reference to `__GSHandlerCheck'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_monitor.obj):(.xdata[$unwind$_glfwPlatformGetVideoModes]+0x10): undefined reference to `__GSHandlerCheck'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_monitor.obj):(.xdata[$unwind$_glfwPlatformGetVideoMode]+0x14): more undefined references to `__GSHandlerCheck' follow
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_joystick.obj):(.text$mn+0x1d3): undefined reference to `__security_check_cookie'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_joystick.obj):(.text$mn+0x10e): undefined reference to `__security_check_cookie'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_joystick.obj):(.text$mn+0x233): undefined reference to `__security_check_cookie'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_joystick.obj):(.text$mn+0x39b): undefined reference to `__security_check_cookie'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_joystick.obj):(.text$mn+0x60): undefined reference to `__security_check_cookie'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_joystick.obj):(.text$mn+0x518): more undefined references to `__security_check_cookie' follow
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_joystick.obj):(.xdata[$unwind$_glfwInitJoysticksWin32]+0x8): undefined reference to `__GSHandlerCheck'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_joystick.obj):(.xdata[$unwind$_glfwDetectJoystickConnectionWin32]+0x8): undefined reference to `__GSHandlerCheck'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_joystick.obj):(.xdata[$unwind$_glfwDetectJoystickDisconnectionWin32]+0x14): undefined reference to `__GSHandlerCheck'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_joystick.obj):(.xdata[$unwind$_glfwPlatformPollJoystick]+0x28): undefined reference to `__GSHandlerCheck'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_joystick.obj):(.xdata[$unwind$_glfwPlatformUpdateGamepadGUID]+0x8): undefined reference to `__GSHandlerCheck'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_joystick.obj):(.xdata[$unwind$deviceObjectCallback]+0x10): more undefined references to `__GSHandlerCheck' follow
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_init.obj):(.text$mn+0xe7): undefined reference to `__security_check_cookie'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_init.obj):(.text$mn+0x97): undefined reference to `__security_check_cookie'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_init.obj):(.text$mn+0xbc): undefined reference to `__security_check_cookie'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_init.obj):(.text$mn+0x3bc): undefined reference to `__security_check_cookie'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_init.obj):(.text$mn+0x1d2): undefined reference to `__security_check_cookie'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_init.obj):(.text$mn+0x48): more undefined references to `__security_check_cookie' follow
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_init.obj):(.xdata[$unwind$_glfwIsWindowsVersionOrGreaterWin32]+0x10): undefined reference to `__GSHandlerCheck'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_init.obj):(.xdata[$unwind$_glfwIsWindows10BuildOrGreaterWin32]+0xc): undefined reference to `__GSHandlerCheck'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_init.obj):(.xdata[$unwind$_glfwInputErrorWin32]+0x10): undefined reference to `__GSHandlerCheck'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_init.obj):(.xdata[$unwind$_glfwUpdateKeyNamesWin32]+0x20): undefined reference to `__GSHandlerCheck'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_init.obj):(.xdata[$unwind$_glfwPlatformInit]+0xc): undefined reference to `__GSHandlerCheck'
externs/GLFW/glfw3.lib(glfw.dir/Release/win32_init.obj):(.xdata[$unwind$loadLibraries]+0x8): more undefined references to `__GSHandlerCheck' follow
externs/GLFW/glfw3.lib(glfw.dir/Release/osmesa_context.obj):(.text$mn+0x21b): undefined reference to `__security_check_cookie'
externs/GLFW/glfw3.lib(glfw.dir/Release/osmesa_context.obj):(.text$mn+0x4c): undefined reference to `__security_check_cookie'
externs/GLFW/glfw3.lib(glfw.dir/Release/osmesa_context.obj):(.text$mn+0x1cd): undefined reference to `__security_check_cookie'
externs/GLFW/glfw3.lib(glfw.dir/Release/osmesa_context.obj):(.xdata[$unwind$_glfwInitOSMesa]+0xc): undefined reference to `__GSHandlerCheck'
externs/GLFW/glfw3.lib(glfw.dir/Release/osmesa_context.obj):(.xdata[$unwind$_glfwCreateContextOSMesa]+0x10): undefined reference to `__GSHandlerCheck'
externs/GLFW/glfw3.lib(glfw.dir/Release/egl_context.obj):(.text$mn+0x4b7): undefined reference to `__security_check_cookie'
externs/GLFW/glfw3.lib(glfw.dir/Release/egl_context.obj):(.text$mn+0x49): undefined reference to `__security_check_cookie'
externs/GLFW/glfw3.lib(glfw.dir/Release/egl_context.obj):(.text$mn+0x534): undefined reference to `__security_check_cookie'
externs/GLFW/glfw3.lib(glfw.dir/Release/egl_context.obj):(.xdata[$unwind$_glfwInitEGL]+0x10): undefined reference to `__GSHandlerCheck'
externs/GLFW/glfw3.lib(glfw.dir/Release/egl_context.obj):(.xdata[$unwind$_glfwCreateContextEGL]+0x18): undefined reference to `__GSHandlerCheck'
externs/GLFW/glfw3.lib(glfw.dir/Release/wgl_context.obj):(.text$mn+0x94): undefined reference to `__imp_DescribePixelFormat'
externs/GLFW/glfw3.lib(glfw.dir/Release/wgl_context.obj):(.text$mn+0xc2): undefined reference to `__imp_SetPixelFormat'
externs/GLFW/glfw3.lib(glfw.dir/Release/wgl_context.obj):(.text$mn+0x447): undefined reference to `__security_check_cookie'
externs/GLFW/glfw3.lib(glfw.dir/Release/wgl_context.obj):(.text$mn+0x2d): undefined reference to `__security_check_cookie'
externs/GLFW/glfw3.lib(glfw.dir/Release/wgl_context.obj):(.text$mn+0x6c): undefined reference to `__security_check_cookie'
externs/GLFW/glfw3.lib(glfw.dir/Release/wgl_context.obj):(.text$mn+0x17c): undefined reference to `__imp_ChoosePixelFormat'
externs/GLFW/glfw3.lib(glfw.dir/Release/wgl_context.obj):(.text$mn+0x18c): undefined reference to `__imp_SetPixelFormat'
externs/GLFW/glfw3.lib(glfw.dir/Release/wgl_context.obj):(.text$mn+0x3a3): undefined reference to `__security_check_cookie'
externs/GLFW/glfw3.lib(glfw.dir/Release/wgl_context.obj):(.text$mn+0x158): undefined reference to `__imp_DescribePixelFormat'
externs/GLFW/glfw3.lib(glfw.dir/Release/wgl_context.obj):(.text$mn+0x61c): undefined reference to `__imp_DescribePixelFormat'
externs/GLFW/glfw3.lib(glfw.dir/Release/wgl_context.obj):(.text$mn+0x77f): undefined reference to `__security_check_cookie'
externs/GLFW/glfw3.lib(glfw.dir/Release/wgl_context.obj):(.text$mn+0x81): undefined reference to `__imp_SwapBuffers'
externs/GLFW/glfw3.lib(glfw.dir/Release/wgl_context.obj):(.xdata[$unwind$_glfwInitWGL]+0xc): undefined reference to `__GSHandlerCheck'
externs/GLFW/glfw3.lib(glfw.dir/Release/wgl_context.obj):(.xdata[$unwind$_glfwCreateContextWGL]+0x14): undefined reference to `__GSHandlerCheck'
externs/GLFW/glfw3.lib(glfw.dir/Release/wgl_context.obj):(.xdata[$unwind$choosePixelFormat]+0x10): undefined reference to `__GSHandlerCheck'
collect2.exe: error: ld returned 1 exit status
只为踢球,我用glfw3.dll(在同一下载中)替换了glfw3.lib。如果运行相同的编译命令,则gcc将成功生成window.exe,如果将glfw3.dll复制到root_folder,则会按预期方式创建一个窗口。目前,这很好,但是显然我不喜欢在运行时拥有glfw.dll,尤其是在我的顶级目录中。
这是window.c中的代码,但我怀疑它是否与我的问题有关(这正是GLFW website上的入门代码,包含针对我的目录结构进行了调整的包含路径):
#include "externs/GLFW/glfw3.h"
int main(void)
{
GLFWwindow* window;
/* Initialize the library */
if (!glfwInit())
return -1;
/* Create a windowed mode window and its OpenGL context */
window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
if (!window)
{
glfwTerminate();
return -1;
}
/* Make the window's context current */
glfwMakeContextCurrent(window);
/* Loop until the user closes the window */
while (!glfwWindowShouldClose(window))
{
/* Render here */
glClear(GL_COLOR_BUFFER_BIT);
/* Swap front and back buffers */
glfwSwapBuffers(window);
/* Poll for and process events */
glfwPollEvents();
}
glfwTerminate();
return 0;
}
我已经进行了一些谷歌搜索,听起来.lib文件还要求我与其他Windows库链接(即使我编译为64位,互联网也建议与user32链接),但是添加了-luser32
对我的编译似乎没有帮助。我不明白的是为什么dll似乎没有此问题。在我看来,在这两种情况下我都应该链接到Windows库,或者根本不需要链接。如何解决静态库中的其他依赖项?
另外(这是一个附带问题,仅是为了满足我的好奇心,而不是本文中实际问题的一部分),为什么我必须将glfw3.dll与可执行文件放在同一文件夹中才能运行它?当然这不是一般要求-我可以在gcc中添加一个标志来指定它在运行时应在哪里查找dll吗?
我希望这是一个相对简单的问题,我在学校使用gcc来编译我的作业,但这是我第一次尝试与外部库进行链接,因此很可能会遗漏一些明显的问题。< / p>
非常感谢!
更新:本教程只是让我添加了GLEW,并且出现了相同类型的问题;我可以使用GLEW dll运行,但是如果尝试与静态库链接,则在尝试链接时会遇到很多错误。