我涉足 Python 一年,现在开始使用 C++,所以我是个菜鸟。我安装了 MinGW 并且一切正常,直到我安装了 freeglut。当我运行以下代码时:
#include <gl/glut.h>
int main()
{
return 0;
}
Run Code Online (Sandbox Code Playgroud)
使用:
C:\code\cpp>g++ GLtest1.cpp
Run Code Online (Sandbox Code Playgroud)
我明白了:
C:\Users\User\AppData\Local\Temp\ccABWOyv.o:GLtest1.cpp:(.text+0x1c): undefined
reference to `_imp____glutInitWithExit@12'
C:\Users\User\AppData\Local\Temp\ccABWOyv.o:GLtest1.cpp:(.text+0x3e): undefined
reference to `_imp____glutCreateWindowWithExit@8'
C:\Users\User\AppData\Local\Temp\ccABWOyv.o:GLtest1.cpp:(.text+0x60): undefined
reference to `_imp____glutCreateMenuWithExit@8'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: C:\Users\U
ser\AppData\Local\Temp\ccABWOyv.o: bad reloc address 0x20 in section `.eh_frame'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: final link
failed: Invalid operation
collect2.exe: error: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
我多次安装并重新安装 MinGW 以试图解决该问题,但无济于事。我尝试使用
#include <windows.h>
Run Code Online (Sandbox Code Playgroud)
以及。我尝试安装 64 位 .dll 文件 - 没有。如果有人以前经历过这种情况,或者熟悉我的问题,欢迎提供帮助。谢谢你。我猜我需要对“链接”做一些事情,但我真的不明白为什么“glut.h”应该与“gl.h”或“glu.h”有什么不同。太令人沮丧了!
更新:
我试图链接一些东西。首先我这样做:
C:\code\cpp>g++ -c -o GLtest1.exe GLtest1.cpp -I"C:\MinGW\include"
Run Code Online (Sandbox Code Playgroud)
一切顺利。没有错误。然后我尝试将事情联系起来并最终出现错误:
C:\code\cpp>g++ -o …Run Code Online (Sandbox Code Playgroud) 我最近安装了GLUT和GLEW,并且前几天运行了一些OpenGL示例代码.我回到我的项目并尝试运行一些基本的c ++代码:
#include <iostream>
int main()
{
using namespace std;
cout << "Come up and C++ me some time.";
cout << endl;
cout << "You won’t regret it!" << endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我使用的是Visual Studio 2013,文件是C++.无论如何,我得到这些错误:
1>------ Build started: Project: testGlut1, Configuration: Debug Win32 ------
1> Source.cpp
1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\xtgmath.h(214): error C2220: warning treated as error - no 'object' file generated
1>c:\program files (x86)\microsoft visual studio 12.0\vc\include\xtgmath.h(214): warning C4602: #pragma pop_macro : 'new' no previous #pragma push_macro …Run Code Online (Sandbox Code Playgroud)