【发布时间】:2013-10-17 15:40:03
【问题描述】:
我通过this 教程了解如何安装 Mesa(OpenGL)。一切都按描述工作。但是,当我尝试将运行良好的构建命令放入 makefile 时却没有。
这是我的生成文件:
all:
gcc -lglut -IGL -IGLEW -IGLU main.c -o OpenGLExample
如果我输入 make,我会得到:
gcc -lglut -IGL -IGLEW -IGLU main.c -o OpenGLExample
/tmp/ccKVrQAu.o:main.c:function renderFunction: error: undefined reference to 'glClearColor'
/tmp/ccKVrQAu.o:main.c:function renderFunction: error: undefined reference to 'glClear'
/tmp/ccKVrQAu.o:main.c:function renderFunction: error: undefined reference to 'glColor3f'
/tmp/ccKVrQAu.o:main.c:function renderFunction: error: undefined reference to 'glOrtho'
/tmp/ccKVrQAu.o:main.c:function renderFunction: error: undefined reference to 'glBegin'
/tmp/ccKVrQAu.o:main.c:function renderFunction: error: undefined reference to 'glVertex2f'
/tmp/ccKVrQAu.o:main.c:function renderFunction: error: undefined reference to 'glVertex2f'
/tmp/ccKVrQAu.o:main.c:function renderFunction: error: undefined reference to 'glVertex2f'
/tmp/ccKVrQAu.o:main.c:function renderFunction: error: undefined reference to 'glVertex2f'
/tmp/ccKVrQAu.o:main.c:function renderFunction: error: undefined reference to 'glEnd'
/tmp/ccKVrQAu.o:main.c:function renderFunction: error: undefined reference to 'glFlush'
collect2: ld returned 1 exit status
make: *** [all] Error 1
我使用的是 Ubuntu,而不是教程中的 Mint。
我做错了什么?
【问题讨论】:
-
我很惊讶第一次调用成功了。您必须将
-lXXX链接器标志放在命令行的末尾。 -
@H2CO3 或者至少在使用它们的任何源文件之后。 (我认为您可以毫无问题地将
-I选项放在-l之后。) -
@JamesKanze 是的,没错。
标签: c++ command-line makefile