ubuntu linux上的opengl - 链接器错误:未定义的引用

Akr*_*nix 2 c++ linux opengl gcc linker-errors

我只想从openGL编程开始,所以我从ubuntu的存储库安装了freeglut3,我安装了所有的mesa软件包,以及build-essentials.

后来,我复制的一个简单的例子openGL的维基
在第一,我试图编译它:gcc triangle.c -o triangle.o;
但是,稍后,我在这里阅读:链接器错误:未定义引用符号'glOrtho',我必须将库链接到-l.
所以,我尝试过gcc triangle.c -lglut -lGL -Wall -o triangle.o

两者都返回相同的错误:

/tmp/ccKLT4ac.o: In function `main':
triangle.c:(.text+0x2b): undefined reference to `glutInit'
triangle.c:(.text+0x37): undefined reference to `glutInitDisplayMode'
triangle.c:(.text+0x4b): undefined reference to `glutInitWindowSize'
triangle.c:(.text+0x57): undefined reference to `glutCreateWindow'
triangle.c:(.text+0x5c): undefined reference to `glewInit'
triangle.c:(.text+0x73): undefined reference to `glewGetErrorString'
triangle.c:(.text+0xaa): undefined reference to `glutDisplayFunc'
triangle.c:(.text+0xaf): undefined reference to `glutMainLoop'
collect2: error: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)

我试图包含gl.h和glu.h库,尝试使用cpp中的许多不同的示例程序,......以及许多组合.所有返回类似的错误.

啊,在/ usr/include我有所有的库:

akronix@ASJ-Netbook:~$ ls /usr/include/GL

freeglut_ext.h  glext.h      glu_mangle.h  glx.h         glxproto.h
freeglut.h      gl.h         glut.h        glxint.h      glxtokens.h
freeglut_std.h  gl_mangle.h  glxew.h       glx_mangle.h  internal
glew.h          glu.h        glxext.h      glxmd.h       wglew.h
Run Code Online (Sandbox Code Playgroud)

Kun*_*nal 5

尝试通过将库放在最后进行编译

gcc triangle.c -Wall -o triangle -lglut -lGL 
Run Code Online (Sandbox Code Playgroud)