【问题标题】:Error: "undefined reference to `gluNewQuadric@0'"错误:“未定义对‘gluNewQuadric@0’的引用”
【发布时间】:2012-01-12 16:32:25
【问题描述】:

在 Eclipse 中编译 OpenGL SFML C++ 项目时出现错误(使用 MinGW 作为工具链):

对 `gluNewQuadric@0' 的未定义引用

对 `gluQuadricDrawStyle@8' 的未定义引用

对 `gluDeleteQuadric@4 的未定义引用

有问题的代码在这里:

#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>   
 
sf::WindowSettings Settings;
Settings.AntialiasingLevel = 2;
Settings.DepthBits = 24;
Settings.StencilBits = 8;
sf::Window  App(sf::VideoMode(1024, 768, 32), "SFML Window", sf::Style::Close, Settings);
App.SetFramerateLimit(30);
prepareGL(App.GetWidth(), App.GetHeight());
sf::Clock Clock;
App.SetActive();
// GL goes here:
GLUquadricObj *qw1 = gluNewQuadric();
gluQuadricDrawStyle(qw1,GLU_POINT);
App.Display();
while (App.IsOpened()) {
    sf::Event Event;
    while (App.GetEvent(Event)) {
        if (((Event.Type == sf::Event::KeyPressed)
            && (Event.Key.Code == sf::Key::Escape))
            || (Event.Type == sf::Event::Closed)) {
            gluDeleteQuadric(qw1);
            App.Close();
        }
        if (Event.Type == sf::Event::Resized) {
            glViewport(0, 0, Event.Size.Width, Event.Size.Height);
        }
    }
}
return EXIT_SUCCESS;

我做错了什么?通常,我用 Java 编写代码,我正在做这个项目来学习更多关于 C/C++ 的知识。我之前做过其他的OpenGL程序,之前没有遇到过这样的问题。

【问题讨论】:

    标签: c++ opengl mingw sfml


    【解决方案1】:

    您需要将适当的标志传递给编译器。要包含 GLU 库,请将其传递给编译和链接选项:

    -lGLU
    

    编辑:以上适用于linux,但对于windows,它是:

    -lglu32
    

    【讨论】:

    • 没有帮助...**** Internal Builder is used for build **** g++ -O0 -g3 -Wall -c -fmessage-length=0 -Wl,--subsystem,windows -mwindows -o src\main.o ..\src\main.cpp g++ -o OpenGL.exe src\main.o -lsfml-graphics-s-d -lsfml-window-s-d -lsfml-system-s-d -lGLU c:/program files/mingw/bin/../lib/gcc/mingw32/4.5.2/../../../../mingw32/bin/ld.exe: cannot find -lGLU
    • @DoktorNo 你安装了 GLU 和 opengl 库吗?
    • @Doktor 不使用 -lglu32,windows 对 opengl 库有自己的命名(-lGLU 适用于 linux)
    • @VJovic 正如我所说,在使用完全相同的设置之前,我做了一些 OpenGL 程序。在我制作这个程序之前,它应该使用 GLUquadricObj... 我想,SFML 在 Window.hpp 中提供了与 OpenGL 相关的所有内容:sfml-dev.org/tutorials/1.3/window-opengl.php
    • 如何在 cmake 中添加这个标志?我是 cmake 新手,正在尝试在 ubuntu 上编译 g20。
    猜你喜欢
    • 1970-01-01
    • 2016-10-03
    • 1970-01-01
    • 2021-09-07
    • 2012-02-27
    • 2012-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多