2013-04-30 48 views
0

我一直在寻找答案,但是我发现的所有问题都是类似的问题,但答案根本无法帮助我。尝试使用SFML时出错(某些LNK错误)

我正在尝试使用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 [email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected] (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 [email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected] (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 [email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected] (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 [email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected] (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 [email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected] (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 [email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected] (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)" ([email protected]@@[email protected]) 
1>sfml-graphics-s.lib(Image.obj) : warning LNK4217: symbole défini localement [email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected] (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 [email protected]@@[email protected][email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@Z 
1>sfml-graphics-s.lib(Sprite.obj) : warning LNK4049: symbole défini localement [email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected] (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 [email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected] (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 &)" ([email protected]@@[email protected][email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@Z) 
1>sfml-window-s.lib(WindowImplWin32.obj) : warning LNK4049: symbole défini localement [email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@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 [email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@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 [email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@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 [email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@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 [email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@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 [email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@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)" ([email protected][email protected][email protected]@[email protected]@@[email protected]@KAXXZ) 
1>sfml-graphics-s.lib(Image.obj) : warning LNK4049: symbole défini localement [email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@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 [email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@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 [email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@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 &)" ([email protected]@@[email protected]@@Z) 
1>sfml-graphics-s.lib(ImageLoader.obj) : warning LNK4217: symbole défini localement [email protected][email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@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)" ([email protected]@[email protected]@@[email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@@[email protected]@@[email protected]@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 &)" ([email protected][email protected]@[email protected]@V[email protected]@[email protected]@[email protected]@[email protected]@@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 &)" ([email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@@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 &)" ([email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@@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 &)" ([email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@@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 &)" ([email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@@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 &)" ([email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@@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 &)" ([email protected]@@[email protected][email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@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 &)" ([email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@@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 &)" ([email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@@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 &)" ([email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@@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)" ([email protected][email protected][email protected]@[email protected]@@[email protected]@[email protected]) 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 *)" ([email protected]@[email protected]@@[email protected]@[email protected][email protected]@[email protected]@@[email protected]@[email protected]) 
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)" ([email protected][email protected][email protected]@[email protected]@@[email protected]@[email protected]) 
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)" ([email protected][email protected][email protected]@[email protected]@@[email protected]@[email protected]) 
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)" ([email protected][email protected][email protected]@[email protected]@@[email protected]@[email protected]) 
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 &)" ([email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected][email protected]@[email protected]@@[email protected]@[email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@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 &)" ([email protected]@[email protected]@@[email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@@[email protected]@@[email protected]@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 *)" ([email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@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)" ([email protected]@[email protected]@@QAE[email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@@[email protected]@@[email protected]@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 " ([email protected][email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@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)" ([email protected]@[email protected]@@[email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]@@[email protected]@@[email protected]@Z) 

时钟完美地工作(我已经尝试过了单独的),但是当我试图加载图像,然后把它变成一个精灵,这些错误出现。

我曾尝试包括那些librairies到我的项目,但错误依然存在 - SFML-main.lib - SFML系统-s.lib和SFML系统-sd.lib - SFML,图形 - s.lib和SFML-图形sd.lib - SFML用窗s.lib和SFML窗口,sd.lib

我真的不知道whta现在要做的:/

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

谢谢!

注意:对不起我的英语,这不是我最不熟悉的语言。

回答

1

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

在Visual Studio中,你可以做到这一点,在预处理设置(“预处理器定义”),如下所示:http://sfml-dev.org/tutorials/2.0/start-vc.php

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

+0

谢谢,但我不确定如何去做。我如何定义一个SFML_STATIC宏? 把我需要的DLL是不够的? – Kaptin 2013-05-02 18:22:09

+0

只需将SFML_STATIC放入预处理器定义中,如下所示:http://sfml-dev.org/tutorials/2.0/images/start-vc-static.png。 然后总是链接到静态(sfml - * - s.lib)库 – psibar 2013-05-02 18:25:25

+0

当我这样做时,我又回到17个错误的开始:/我真的很讨厌sfml ... btw我使用1.6 – Kaptin 2013-05-02 19:04:44

0

你有一个错误的斜线在包括声明

#include <SFML\Graphics.hpp> 

应该是:

#include <SFML/Graphics.hpp> 
+0

你是对的,但编译器错误都没有因为它:/谢谢你让我知道虽然 – Kaptin 2013-05-01 12:05:31

1

发现家伙,

我不得不投入链接器输入馆藏

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

没有把-s ....

一个为你们最后一个问题,是正常的,我不得不把所有三个.dll文件在我的项目,原因是Visual Studio在说,它无法找到的档案?

非常感谢!

+1

是的,你必须把它们全部3它们在sfml中这些库保持分开(以备用内存如果组件不需要)。如果你使用的音频也包括sfml-audio.lib – psibar 2013-05-01 15:15:34