其他分享
首页 > 其他分享> > c – 错误:“对’gluNewQuadric @ 0’的未定义引用”

c – 错误:“对’gluNewQuadric @ 0’的未定义引用”

作者:互联网

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

undefined reference to `gluNewQuadric@0′

undefined reference to `gluQuadricDrawStyle@8′

undefined reference to `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程序,之前我没有这样的问题.

解决方法:

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

-lGLU

编辑:上面的工作在Linux上,但对于Windows,它是:

-lglu32

标签:sfml,c,opengl,mingw
来源: https://codeday.me/bug/20190729/1575653.html