【问题标题】:SFML undefined reference to implSFML 未定义对 impl 的引用
【发布时间】:2014-10-25 00:32:54
【问题描述】:

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

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

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

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

我在 Windows 上。如何摆脱这些未定义的引用?

编辑:这是程序:

#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;
}

【问题讨论】:

  • 你确定你已经定义了所有的指针、函数等吗?
  • @zyboxinternational 是的。 main.cpp 里面唯一的东西就是 SFML 提供的示例程序。
  • 我认为您必须为核心功能添加 -lsfml-system。 (您的链接命令中缺少它)
  • 我不赞成投票-.-
  • @Kapichu 添加它没有帮助。可能是顺序错了?

标签: c++ windows sfml


【解决方案1】:

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

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

这是编译:

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

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

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

【讨论】:

  • @T.C.没错。谢谢。
  • 消除了原来的错误。但现在我得到“找不到-lsfml-windows/graphics/system
  • 您是否真的按照教程进行操作 (sfml-dev.org/tutorials/2.1/start-linux.php) ? (由于您使用的是 GNU 工具,它应该会有所帮助,尽管它是为 linux 设计的)
  • @user2030677:想想看,-L/lib 应该是什么?工作目录的子目录中的库是否名为“lib”?试试-L"./lib"
  • @BenjaminLindley 是的,/lib 是我从 SFML bin 目录复制所有 DLL 文件的子目录。当我做-L"./lib" 时,它仍然给出同样的错误。
猜你喜欢
  • 1970-01-01
  • 2017-03-11
  • 2018-07-17
  • 2015-02-14
  • 1970-01-01
  • 1970-01-01
  • 2013-12-26
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多