c++ - 尝试使用 SFML 时出错(一些 LNK 错误)

标签 c++ compiler-errors include sfml

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

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

这是我的代码:

#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)

时钟工作正常(我单独尝试过)但是当我尝试加载图像然后将其放入 Sprite 时,出现了这些错误。

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

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

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

谢谢!!!

注意:对不起我的英语,这不是我的母语。

最佳答案

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

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

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

关于c++ - 尝试使用 SFML 时出错(一些 LNK 错误),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16310435/

相关文章:

php - include_once() 和条件包含之间是否存在开销差异?

javascript - 无法通过静态 URL 包含外部 javascript 文件

c++ - 是否有可能像在 C++ 中那样在 C 中实现模板化

c - 错误 : Redefinition of union

C++ 错误 : Not declared in scope; Member function

java - 包不存在?

php - 在站点上放置大量 PHP 包含项可以吗?

c++ - WinRT W8 C++创建WebView并添加到主视图

c++ - 使用 C++ 解析来自添加到任务栏的程序的信息

c++ - Boost API 检查目录路径是否在 C++ 中的网络上