0

我一直在寻找答案,但我发现的只是一些类似的问题,但答案对我一点帮助都没有。

我正在尝试将 SFML 用于最终项目(我们想创建像 Minigore 这样的游戏),我们正在尝试加载图像,然后将其放入精灵中。

这是我的代码:

#include <SFML/System.hpp>
#include <SFML\Graphics.hpp>
#include <iostream>

int main()
{
sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Graphics");

while(App.IsOpened())
{
    sf::Clock Clock;
    while (Clock.GetElapsedTime() < 5.f)
    {
        std::cout << Clock.GetElapsedTime() << std::endl;
        sf::Sleep(0.5f);
    }

    sf::Image image;
    sf::Sprite sprite;

    if(!image.LoadFromFile("BaronsheetBas1.gif"))
    {

    }
    else
    {
        sprite.SetImage(image);
    }
}



    return 0;
}

当我编译时,我一直有这些错误。

1>------ Début de la génération : Projet : SFML_Affiche_image, Configuration : Debug Win32 ------
1>La génération a démarré 2013-04-30 19:07:23.
1>InitializeBuildStatus:
1>  Mise à jour de l'horodatage "Debug\SFML_Affiche_image.unsuccessfulbuild".
1>ClCompile:
1>  Toutes les sorties sont à jour.
1>LINK : warning LNK4098: conflit entre la bibliothèque par défaut 'MSVCRT' et les autres bibliothèques ; utilisez /NODEFAULTLIB:library
1>sfml-window-s.lib(WindowImplWin32.obj) : warning LNK4049: symbole défini localement ??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ (public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::~basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(void)) importé
1>sfml-window-s.lib(Window.obj) : warning LNK4049: symbole défini localement ??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ (public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::~basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(void)) importé
1>sfml-window-s.lib(VideoMode.obj) : warning LNK4049: symbole défini localement ??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ (public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::~basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(void)) importé
1>sfml-window-s.lib(WindowImpl.obj) : warning LNK4049: symbole défini localement ??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ (public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::~basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(void)) importé
1>sfml-window-s.lib(VideoModeSupport.obj) : warning LNK4049: symbole défini localement ??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ (public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::~basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(void)) importé
1>sfml-graphics-s.lib(RenderWindow.obj) : warning LNK4217: symbole défini localement ??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ (public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::~basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(void)) importé dans la fonction "public: virtual __thiscall std::logic_error::~logic_error(void)" (??1logic_error@std@@UAE@XZ)
1>sfml-graphics-s.lib(Image.obj) : warning LNK4217: symbole défini localement ??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ (public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::~basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(void)) importé dans la fonction __ehhandler$??0logic_error@std@@QAE@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@1@@Z
1>sfml-graphics-s.lib(Sprite.obj) : warning LNK4049: symbole défini localement ??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ (public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::~basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(void)) importé
1>sfml-graphics-s.lib(ImageLoader.obj) : warning LNK4217: symbole défini localement ??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ (public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::~basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(void)) importé dans la fonction "public: __thiscall std::logic_error::logic_error(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (??0logic_error@std@@QAE@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@1@@Z)
1>sfml-window-s.lib(WindowImplWin32.obj) : warning LNK4049: symbole défini localement ??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@PBD@Z (public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(char const *)) importé
1>sfml-window-s.lib(Window.obj) : warning LNK4049: symbole défini localement ??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@PBD@Z (public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(char const *)) importé
1>sfml-window-s.lib(VideoMode.obj) : warning LNK4049: symbole défini localement ??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@PBD@Z (public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(char const *)) importé
1>sfml-window-s.lib(WindowImpl.obj) : warning LNK4049: symbole défini localement ??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@PBD@Z (public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(char const *)) importé
1>sfml-window-s.lib(VideoModeSupport.obj) : warning LNK4049: symbole défini localement ??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@PBD@Z (public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(char const *)) importé
1>sfml-graphics-s.lib(RenderWindow.obj) : warning LNK4217: symbole défini localement ??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@PBD@Z (public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(char const *)) importé dans la fonction "protected: static void __cdecl std::vector<unsigned char,class std::allocator<unsigned char> >::_Xlen(void)" (?_Xlen@?$vector@EV?$allocator@E@std@@@std@@KAXXZ)
1>sfml-graphics-s.lib(Image.obj) : warning LNK4049: symbole défini localement ??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@PBD@Z (public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(char const *)) importé
1>sfml-graphics-s.lib(Sprite.obj) : warning LNK4049: symbole défini localement ??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@PBD@Z (public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(char const *)) importé
1>sfml-graphics-s.lib(ImageLoader.obj) : warning LNK4217: symbole défini localement ??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@PBD@Z (public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(char const *)) importé dans la fonction "public: __thiscall std::logic_error::logic_error(class std::logic_error const &)" (??0logic_error@std@@QAE@ABV01@@Z)
1>sfml-graphics-s.lib(ImageLoader.obj) : warning LNK4217: symbole défini localement ?npos@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@2IB (public: static unsigned int const std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::npos) importé dans la fonction "public: bool __thiscall sf::priv::ImageLoader::SaveImageToFile(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::vector<class sf::Color,class std::allocator<class sf::Color> > const &,unsigned int,unsigned int)" (?SaveImageToFile@ImageLoader@priv@sf@@QAE_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@ABV?$vector@VColor@sf@@V?$allocator@VColor@sf@@@std@@@5@II@Z)
1>sfml-window-s.lib(WindowImplWin32.obj) : error LNK2001: symbole externe non résolu "__declspec(dllimport) public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (__imp_??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@ABV01@@Z)
1>sfml-window-s.lib(Window.obj) : error LNK2001: symbole externe non résolu "__declspec(dllimport) public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (__imp_??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@ABV01@@Z)
1>sfml-window-s.lib(VideoMode.obj) : error LNK2001: symbole externe non résolu "__declspec(dllimport) public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (__imp_??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@ABV01@@Z)
1>sfml-window-s.lib(WindowImpl.obj) : error LNK2001: symbole externe non résolu "__declspec(dllimport) public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (__imp_??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@ABV01@@Z)
1>sfml-window-s.lib(VideoModeSupport.obj) : error LNK2001: symbole externe non résolu "__declspec(dllimport) public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (__imp_??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@ABV01@@Z)
1>sfml-graphics-s.lib(RenderWindow.obj) : error LNK2019: symbole externe non résolu "__declspec(dllimport) public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (__imp_??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@ABV01@@Z) référencé dans la fonction "public: __thiscall std::logic_error::logic_error(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (??0logic_error@std@@QAE@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@1@@Z)
1>sfml-graphics-s.lib(Image.obj) : error LNK2001: symbole externe non résolu "__declspec(dllimport) public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (__imp_??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@ABV01@@Z)
1>sfml-graphics-s.lib(Sprite.obj) : error LNK2001: symbole externe non résolu "__declspec(dllimport) public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (__imp_??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@ABV01@@Z)
1>sfml-graphics-s.lib(ImageLoader.obj) : error LNK2001: symbole externe non résolu "__declspec(dllimport) public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (__imp_??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@ABV01@@Z)
1>sfml-graphics-s.lib(Image.obj) : error LNK2019: symbole externe non résolu "__declspec(dllimport) public: int __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::sputn(char const *,int)" (__imp_?sputn@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QAEHPBDH@Z) référencé dans la fonction "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl std::operator<<<struct std::char_traits<char> >(class std::basic_ostream<char,struct std::char_traits<char> > &,char const *)" (??$?6U?$char_traits@D@std@@@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@0@AAV10@PBD@Z)
1>sfml-graphics-s.lib(ImageLoader.obj) : error LNK2001: symbole externe non résolu "__declspec(dllimport) public: int __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::sputn(char const *,int)" (__imp_?sputn@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QAEHPBDH@Z)
1>sfml-window-s.lib(Window.obj) : error LNK2001: symbole externe non résolu "__declspec(dllimport) public: int __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::sputn(char const *,int)" (__imp_?sputn@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QAEHPBDH@Z)
1>sfml-window-s.lib(WindowImplWin32.obj) : error LNK2001: symbole externe non résolu "__declspec(dllimport) public: int __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::sputn(char const *,int)" (__imp_?sputn@?$basic_streambuf@DU?$char_traits@D@std@@@std@@QAEHPBDH@Z)
1>sfml-graphics-s.lib(ImageLoader.obj) : error LNK2019: symbole externe non résolu "__declspec(dllimport) class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl std::operator<<<char,struct std::char_traits<char>,class std::allocator<char> >(class std::basic_ostream<char,struct std::char_traits<char> > &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (__imp_??$?6DU?$char_traits@D@std@@V?$allocator@D@1@@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@0@AAV10@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@0@@Z) référencé dans la fonction "public: bool __thiscall sf::priv::ImageLoader::LoadImageFromFile(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::vector<class sf::Color,class std::allocator<class sf::Color> > &,unsigned int &,unsigned int &)" (?LoadImageFromFile@ImageLoader@priv@sf@@QAE_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AAV?$vector@VColor@sf@@V?$allocator@VColor@sf@@@std@@@5@AAI2@Z)
1>sfml-graphics-s.lib(ImageLoader.obj) : error LNK2019: symbole externe non résolu "__declspec(dllimport) bool __cdecl std::operator==<char,struct std::char_traits<char>,class std::allocator<char> >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,char const *)" (__imp_??$?8DU?$char_traits@D@std@@V?$allocator@D@1@@std@@YA_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@0@PBD@Z) référencé dans la fonction "public: bool __thiscall sf::priv::ImageLoader::SaveImageToFile(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::vector<class sf::Color,class std::allocator<class sf::Color> > const &,unsigned int,unsigned int)" (?SaveImageToFile@ImageLoader@priv@sf@@QAE_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@ABV?$vector@VColor@sf@@V?$allocator@VColor@sf@@@std@@@5@II@Z)
1>sfml-graphics-s.lib(ImageLoader.obj) : error LNK2019: symbole externe non résolu "__declspec(dllimport) public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::substr(unsigned int,unsigned int)const " (__imp_?substr@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBE?AV12@II@Z) référencé dans la fonction "public: bool __thiscall sf::priv::ImageLoader::SaveImageToFile(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::vector<class sf::Color,class std::allocator<class sf::Color> > const &,unsigned int,unsigned int)" (?SaveImageToFile@ImageLoader@priv@sf@@QAE_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@ABV?$vector@VColor@sf@@V?$allocator@VColor@sf@@@std@@@5@II@Z)

时钟运行良好(我已经单独尝试过)但是当我尝试加载图像然后将其放入精灵时,出现了这些错误。

我试图将这些库包含到我的项目中,但错误仍然存​​在 - sfml-main.lib - sfml-system-s.lib 和 sfml-system-sd.lib - sfml-graphics-s.lib 和 sfml-graphics -sd.lib - sfml-window-s.lib 和 sfml-window-sd.lib

我真的不知道现在该做什么:/

如果你们中的任何人有答案或可以帮助我找到它,那么分享它会很高兴:)

谢谢 !!!

注意:对不起我的英语,这不是我的福斯特语言。

4

3 回答 3

1

找到了,伙计们,

我不得不将库放入链接器输入

sfml-graphics.lib, sfml-window.lib, sfml-system.lib

没有放 -s ....

最后一个问题,我必须将所有三个 .dll 都放在我的项目中是否正常,因为 Visual Studio 说它找不到文件?

非常感谢你 !

于 2013-05-01T12:38:11.363 回答
1

如果您要链接到 sfml 的静态库(sfml-system-s.lib 等),请确保在预处理定义中设置了 SFML_STATIC 变量。

在 Visual Studio 中,您可以在预处理设置(“预处理器定义”)中执行此操作,如下所示:http: //sfml-dev.org/tutorials/2.0/start-vc.php

如果你想创建一个在其他没有安装 sfml dll 的机器上运行的游戏,你绝对应该链接到 Windows 上的静态库。

于 2013-05-01T15:27:52.683 回答
0

您的包含语句中有一个错误的斜杠

#include <SFML\Graphics.hpp>

应该:

#include <SFML/Graphics.hpp>
于 2013-05-01T10:30:07.763 回答