【问题标题】:Freeglut 64 bit program linking errorsFreeglut 64 位程序链接错误
【发布时间】: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 的建议完全有效。

标签: c++ opengl g++ freeglut


【解决方案1】:

我无法回答您的具体情况,但另一种方法是使用 mingw-w64,将 MSYS2 作为包管理器。与 mingw-w64 和 MSYS2 包数据库不同,旧的 mingw.org 项目维护得不好。您的预编译二进制文件的构建方式与您当前使用的编译器之间可能存在一些不匹配。

在我的系统上,我使用g++ -o gl gl.cpp -lfreeglut 编译了您的代码,并且它第一次运行。

How to install MinGW-w64 and MSYS2?

然后使用pacman -Ss glut 找到freeglut 包。

【讨论】:

  • 所以你是说 mingw 本身就是问题所在?谢谢,我试试看。
猜你喜欢
  • 2010-12-28
  • 1970-01-01
  • 2016-06-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-02
  • 2019-07-06
  • 1970-01-01
  • 2017-01-22
相关资源
最近更新 更多