【问题标题】:OpenGL Ubuntu 13.10 QtCreator - undefined reference to `glutMainLoop`OpenGL Ubuntu 13.10 QtCreator - 未定义对“glutMainLoop”的引用
【发布时间】:2014-02-02 10:12:37
【问题描述】:

如果我尝试从here, the OpenGLBook 执行代码,我会收到以下错误消息:

undefined reference to glutMainLoop
undefined reference to glGetString
undefined reference to glClearColor

等等...我安装了以下软件包:

libglew-devliblglew1.8freeglut3-devfreeglut3

我在带有 Qt Creator v3.0.0 的 Ubuntu 13.10 上运行。

我的.pro 文件如下所示:

TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt

SOURCES += main.cpp

调试的构建步骤是qmake Project.pro -r -spec linux-g++ CONFIG += debug

如何修复我的项目?

【问题讨论】:

  • 只安装开发包是不够的,还得和实际的库链接。
  • 我对 Qt pro 文件不太熟悉,但我相信您可以借助您选择的搜索引擎轻松找到。

标签: c++ qt opengl ubuntu


【解决方案1】:

必须将我的 pro 文件更改为

TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt

SOURCES += main.cpp

# this is the important part
unix|win32: LIBS += -lGLU
unix|win32: LIBS += -lGL
unix|win32: LIBS += -lglut

【讨论】:

    【解决方案2】:

    欢迎来到 C++! 您正在使用一个库(我收集了 freeglut),为此您需要两件事:

    1) 包含声明您需要的函数/类/方法的标头(*.h 文件)

    2) 你的程序需要链接到实际的共享库(Linux 中的.so 文件)

    在您的 .pro 文件中,您需要指定要链接的库的路径。添加这个:

    LIBS += -lglut

    这意味着将库过剩添加到要链接的库列表中。

    【讨论】:

    • 感谢您的回答,但正如您所见,我已经想通了。
    猜你喜欢
    • 2014-02-10
    • 2014-05-24
    • 2014-11-11
    • 2021-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-13
    • 1970-01-01
    相关资源
    最近更新 更多