SFML 对 impl 的未定义引用 [英] SFML undefined reference to impl

查看:34
本文介绍了SFML 对 impl 的未定义引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将 SFML 用于 GCC 4.7 MinGW (DW2) - 32 位时,我收到以下未定义的引用:

I'm getting the following undefined references when using SFML for GCC 4.7 MinGW (DW2) - 32 bits:

g++ -std=c++11 -Wall -I$(SFML_INCLUDE) -o pong main.o

main.o:main.cpp: undefined reference to `_imp___ZN2sf6StringC1EPKc
RKSt6locale'
main.o:main.cpp: undefined reference to `_imp___ZN2sf9VideoModeC1E
jjj'
main.o:main.cpp: undefined reference to `_imp___ZN2sf12RenderWindo
wC1ENS_9VideoModeERKNS_6StringEjRKNS_15ContextSettingsE'
main.o:main.cpp: undefined reference to `_imp___ZN2sf11CircleShape
C1Efj'
....
....
....
collect2.exe: error: ld returned 1 exit status
make: *** [all] Error 1

还有很多.这就是我的链接方式:

There are many more than this. This is how I am linking:

LIBRARIES = -lsfml-graphics -lsfml-window -lglu32 -lopengl32 -lglew32
g++ -c include/main.cpp -L/lib  $(LIBRARIES)

我使用的是 Windows.如何摆脱这些未定义的引用?

I'm on Windows. How do I get rid of these undefined references?

这是程序:

#define SFML_STATIC

#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
    sf::CircleShape shape(100.f);
    shape.setFillColor(sf::Color::Green);

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        window.clear();
        window.draw(shape);
        window.display();
    }

    return 0;
}

推荐答案

你把编译和链接搞混了.这是链接:

You have compiling and linking mixed up. This is linking:

g++ -std=c++11 -Wall -I$(SFML_INCLUDE) -o pong main.o

这是编译:

g++ -c include/main.cpp -L/lib  $(LIBRARIES)

链接,而不是编译,需要 $(LIBRARIES) 变量和 -L 选项.

The linking, not the compiling, needs the $(LIBRARIES) variable and the -L option.

g++ main.o -o pong -L/lib $(LIBRARIES)

编译需要-std=c++11-Wall-I.

g++ -std=c++11 -Wall -c -I$(SFML_INCLUDE) include/main.cpp

这篇关于SFML 对 impl 的未定义引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆