SFML loadFromFile未定义参考 [英] SFML loadFromFile undefined reference
问题描述
我正在学习使用SFML来制作小游戏的想法,到目前为止,我已经创建了一个窗口并弄乱了它的设置,并设置了绘制循环和事件处理程序.
I'm learning to use SFML with the idea of making a small game, so far I've created a window and messed about with it's settings, and set up a draw loop and event handler.
一旦我尝试使用以下代码添加我的第一个纹理,麻烦就开始了:
The trouble started once I tried to add my first texture using the following code:
#include "SpaceNomad.ih"
void MainMenu(GameEngine &Engine)
{
sf::Texture texture;
if(!texture.loadFromFile("MenuBackGround.png"))
{
cout << "couldn't load background texture\n";
}
sf::Sprite *sprite = new sf::Sprite;
sprite->setTexture(texture);
Engine.AddEntity(sprite, 5);
}
完全在另一张图片的外面,实际上是上给出的示例代码SFML教程页面.
which is outside of a different image literally the example code given on the SFML tutorial page.
当我尝试对此进行编译时,出现以下错误:
When I try to compile this I get the following error:
||=== Build: Debug in space nomad (compiler: GNU GCC Compiler) ===|
obj\Debug\projects\st\take2\MainMenu.o||In function `Z8MainMenuR10GameEngine':|
D:\projects\st\take2\MainMenu.cpp|7|undefined reference to `_imp___ZN2sf7Texture12loadFromFileERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKNS_4RectIiEE'|
||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
我检查了所有sfml库是否都包含在构建选项中(我在GCC MinGW中使用code :: Blocks).
I have checked that all the sfml libraries are included in the build options(I'm using code::Blocks with GCC MinGW).
https://drive.google.com/file/d/0B4qzXcgqbLZtcHJWUy1vSUhpdVk/view?usp = sharing
我见过的其他主题涉及人们对自己创建的函数的未定义引用,但是这里我使用的是库.
Other topics I've seen deal with undefined references to functions people have made themselves, but here I'm using a library.
我刚刚尝试了同一库中的基本形状:
edit: I've just tried with the basic shape from the same libary:
sf::CircleShape *shape = new sf::CircleShape(50);
// set the shape color to green
shape->setFillColor(sf::Color(100, 250, 50));
Engine.AddEntity(shape, 5);
编译和显示都没有问题.
Which compiles and displays without a problem.
推荐答案
您正在使用SFML库,这些库是通过与应用程序链接所针对的不同运行时或不同运行时ABI编译的.
You're using SFML libraries which were compiled with a different runtime or a different runtime ABI than you link your application against.
如果未使用相同的编译器来编译SFML库,则需要重新构建.
If your SFML libraries weren't compiled with the same compiler that you have, then you need to rebuild.
如果您在应用程序上设置了任何特殊标志(例如,不同的ABI,C ++ 14等),则还必须使用相同的标志重建SFML,或者将其从项目中删除.
If you have set any special flags on your application (e.g. different ABI, C++14, etc.) you'll have to rebuild SFML with the same flags as well or remove them from your project.
它也只会在某些时候发生,因为它不会影响整个运行时库,而是会影响 std :: string
之类的部分,这些部分会在调用 loadFromFile
函数时使用.
Also it only happens sometimes because it doesn't affect the whole runtime libraries but parts like std::string
which get used when calling the loadFromFile
function.
这篇关于SFML loadFromFile未定义参考的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!