【问题标题】:commandline works, same command in Makefile doesn't命令行有效,Makefile 中的相同命令无效
【发布时间】: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


【解决方案1】:

您没有将 OpenGL 库传递给链接器。你应该输入l,而不是I

all:
    gcc main.c -lglut -lGL -lGLEW -lGLU  -o OpenGLExample

您还应该传递您的编译器可以找到 OpenGL 头文件的目录,这可以通过 -I 完成,并且可能还有一个选项(或多个选项)指定链接器应在何处查找库 (-L)

【讨论】:

  • 您可能还必须传递一个(或多个)选项,指定链接器应在何处查找库 (-L)。
猜你喜欢
  • 1970-01-01
  • 2016-07-05
  • 2015-03-26
  • 2022-01-23
  • 2015-03-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多