c - 构建 GLFW/OpenGL 程序时未定义的引用?
问题描述
我正在尝试使用 C、MINGW 和 GLFW 来创建程序,并且在编译时不断收到此错误。
cc1.exe: warning: unrecognized gcc debugging option: y
cc1.exe: warning: unrecognized gcc debugging option: n
cc1.exe: warning: unrecognized gcc debugging option: m
cc1.exe: warning: unrecognized gcc debugging option: i
cc1.exe: warning: unrecognized gcc debugging option: c
./libs/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x127): undefined reference to `CreateDCW@16'
./libs/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x160): undefined reference to `GetDeviceCaps@8'
./libs/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x179): undefined reference to `GetDeviceCaps@8'
./libs/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x1ca): undefined reference to `GetDeviceCaps@8'
./libs/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x24b): undefined reference to `GetDeviceCaps@8'
./libs/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x291): undefined reference to `DeleteDC@4'
./libs/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x9ee): undefined reference to `GetDeviceCaps@8'
./libs/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0xa07): undefined reference to `GetDeviceCaps@8'
./libs/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0xe9f): undefined reference to `CreateDCW@16'
./libs/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0xeba): undefined reference to `GetDeviceGammaRamp@8'
./libs/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0xec8): undefined reference to `DeleteDC@4'
./libs/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x100e): undefined reference to `CreateDCW@16'
./libs/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x1029): undefined reference to `SetDeviceGammaRamp@8'
./libs/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x1037): undefined reference to `DeleteDC@4'
./libs/libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0x1f3): undefined reference to `CreateDIBSection@24'
./libs/libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0x262): undefined reference to `CreateBitmap@20'
./libs/libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0x28d): undefined reference to `DeleteObject@4'
./libs/libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0x37b): undefined reference to `DeleteObject@4'
./libs/libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0x389): undefined reference to `DeleteObject@4'
./libs/libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0xb55): undefined reference to `CreateRectRgn@16'
./libs/libglfw3.a(win32_window.c.obj):win32_window.c:(.text+0xc2c): undefined reference to `DeleteObject@4'
./libs/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0x6c4): undefined reference to `DescribePixelFormat@16'
./libs/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0xbbd): undefined reference to `DescribePixelFormat@16'
./libs/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0xf46): undefined reference to `SwapBuffers@4'
./libs/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0x1254): undefined reference to `ChoosePixelFormat@8'
./libs/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0x126f): undefined reference to `SetPixelFormat@12'
./libs/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0x1592): undefined reference to `DescribePixelFormat@16'
./libs/libglfw3.a(wgl_context.c.obj):wgl_context.c:(.text+0x15d9): undefined reference to `SetPixelFormat@12'
collect2.exe: error: ld returned 1 exit status
这是我的代码
#include "GLFW/glfw3.h"
#include <stdio.h>
#define GLFW_INCLUDE_GLCOREARB
int main() {
GLFWwindow* window;
if (!glfwInit()) return -1;
window = glfwCreateWindow(640, 480, "Test", NULL, NULL);
if (!window)
{
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
while (!glfwWindowShouldClose(window))
{
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwTerminate();
return 0;
}
所以它基本上只是glfw网站上给定的例子。
我使用这个命令来构建:
gcc -o Test.o Main.c -IGLFW -IGL -dynamic ./libs/glfw3.dll ./libs/glew32.dll -lopengl32 -static ./libs/libglfw3.a ./libs/glew32.lib ./libs/glew32s.lib
我在编译 glfw 时没有任何问题,但我在使用 GLEW 时遇到问题,可能是因为它是 lib 文件而不是 a.
解决方案
推荐阅读
- react-native - 如何仅在特定屏幕上启用抽屉?
- c - 分配 char 数组和字符串
- swift - 试图使这个类可编码和可解码
- android - 无法使用“altbeacon”库 android 监控信标区域
- java - JNI Java使用以对象为参数的DLL函数
- xamarin.ios - 通过 URL 方案将数据从一个应用程序传递到另一个应用程序?
- python - 索引超出范围,同时尝试在 Python 中创建字典
- python - 如何使用 sqlite3 在 python 中为我的两种用户类型提供单独的菜单
- python - 在不更改批量大小的情况下,ai 引擎上的内存不足
- swift - 在 Swift 中使用 Core Graphics 填充多边形