【发布时间】:2020-07-08 18:31:40
【问题描述】:
我正在尝试使用 freeglut 编译 64 位版本的 OpenGL C++ 程序。我按照this website 上的确切说明使用 MinGW 设置 freeglut。我在C:\MinGW\include\GL 中有头文件,在C:\MinGW\lib 中有32 位库,在C:\MinGW\lib\x64 中有64 位库,在我的项目目录中有64 位freeglut.dll。但是,即使是最简单的 OpenGL 程序也无法成功链接...
我的代码很少:
// test.cpp
#include <GL/glut.h>
int main(int argc, char *argv[]) {
glutInit(&argc, argv);
}
我使用自述文件/网站上给出的确切命令对其进行编译:
g++ -c -o test.o test.cpp -I"C:\MinGW\include"
g++ -o test.exe test.o -L"C:\MinGW\lib\x64" -lfreeglut -lopengl32 -Wl,--subsystem,windows
(当然除了我更改了目录并将 gcc 更改为 g++)
编译运行良好,但链接抛出这些错误消息:
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: test.o:test.cpp:(.text+0x1c): undefined reference to `_imp____glutInitWithExit@12'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: test.o:test.cpp:(.text+0x3f): undefined reference to `_imp____glutCreateWindowWithExit@8'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: test.o:test.cpp:(.text+0x61): undefined reference to `_imp____glutCreateMenuWithExit@8'
collect2.exe: error: ld returned 1 exit status
我尝试将命令中的-lopengl32 更改为-lopengl64 和-lopengl,但链接器找不到这些库。
【问题讨论】:
-
原来的mingw只有32位。使用 M.M 建议的 64 位版本
-
@TheGoldKnight23 mingw-w64 有 32 位和 64 位版本。它添加了 64 位支持,但没有删除 32 位
-
@M.M 就像我说的 origional mingw 只有 32 位,而您对 mjngw-w64 的建议完全有效。