Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: SFML 2.0 Graphics linking error  (Read 14184 times)

0 Members and 1 Guest are viewing this topic.

Zaid

  • Newbie
  • *
  • Posts: 11
    • View Profile
SFML 2.0 Graphics linking error
« on: August 23, 2012, 04:20:18 am »
#include <iostream>
#include <SFML/Graphics.hpp>

#ifdef _DEBUG
#pragma comment (lib, "sfml-system-s-d.lib")
#pragma comment (lib, "sfml-window-s-d.lib")
#pragma comment (lib, "sfml-graphics-s-d.lib")
#else
#pragma comment (lib, "sfml-system-s.lib")
#pragma comment (lib, "sfml-window-s.lib")
#pragma comment (lib, "sfml-graphics-s.lib")
#endif

int main()
{
   sf::RenderWindow App(sf::VideoMode(640, 480, 32), "SFML 2.0 Test");
   sf::Event Event;
   
   sf::Texture texture;
   texture.loadFromFile("media/person.PNG");

   sf::Sprite Sprite;
   Sprite.setTexture(texture);
   Sprite.setPosition(100, 100);

   while(App.isOpen())
   {
      while (App.pollEvent(Event))
         {
             // Close window : exit
             if (Event.type == sf::Event::Closed)
                 App.close();
         }

      App.clear();
      App.draw(Sprite);
      App.display();
   }

   return 0;
}


--------------------------------------------------------------------------------------------------------

So this is the chunk of code I am trying to compile. I have it all statically linked and I've defined so in VC++ 2010's properties or whatever. So all of that is correct. I have the latest version of 2.0 for VC++ 2010 installed on my computer. But yet, every time I still get this error.

--------------------------------------------------------------------------------------------------------

1>------ Rebuild All started: Project: SFML2Test, Configuration: Debug Win32 ------
1>  main.cpp
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall sf::RenderWindow::~RenderWindow(void)" (__imp_??1RenderWindow@sf@@UAE@XZ) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::Texture::~Texture(void)" (__imp_??1Texture@sf@@QAE@XZ) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall sf::Sprite::~Sprite(void)" (__imp_??1Sprite@sf@@UAE@XZ) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall sf::Window::display(void)" (__imp_?display@Window@sf@@QAEXXZ) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall sf::RenderTarget::draw(class sf::Drawable const &,class sf::RenderStates const &)" (__imp_?draw@RenderTarget@sf@@QAEXABVDrawable@2@ABVRenderStates@2@@Z) referenced in function _main
1>main.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: static class sf::RenderStates const sf::RenderStates::Default" (__imp_?Default@RenderStates@sf@@2V12@B)
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall sf::RenderTarget::clear(class sf::Color const &)" (__imp_?clear@RenderTarget@sf@@QAEXABVColor@2@@Z) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::Color::Color(unsigned char,unsigned char,unsigned char,unsigned char)" (__imp_??0Color@sf@@QAE@EEEE@Z) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall sf::Window::close(void)" (__imp_?close@Window@sf@@QAEXXZ) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: bool __thiscall sf::Window::pollEvent(class sf::Event &)" (__imp_?pollEvent@Window@sf@@QAE_NAAVEvent@2@@Z) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: bool __thiscall sf::Window::isOpen(void)const " (__imp_?isOpen@Window@sf@@QBE_NXZ) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall sf::Transformable::setPosition(float,float)" (__imp_?setPosition@Transformable@sf@@QAEXMM@Z) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall sf::Sprite::setTexture(class sf::Texture const &,bool)" (__imp_?setTexture@Sprite@sf@@QAEXABVTexture@2@_N@Z) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::Sprite::Sprite(void)" (__imp_??0Sprite@sf@@QAE@XZ) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: bool __thiscall sf::Texture::loadFromFile(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class sf::Rect<int> const &)" (__imp_?loadFromFile@Texture@sf@@QAE_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@ABV?$Rect@H@2@@Z) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::Texture::Texture(void)" (__imp_??0Texture@sf@@QAE@XZ) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::RenderWindow::RenderWindow(class sf::VideoMode,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,unsigned int,struct sf::ContextSettings const &)" (__imp_??0RenderWindow@sf@@QAE@VVideoMode@1@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@IABUContextSettings@1@@Z) referenced in function _main
1>main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::VideoMode::VideoMode(unsigned int,unsigned int,unsigned int)" (__imp_??0VideoMode@sf@@QAE@III@Z) referenced in function _main
1>S:\Users\Logan\documents\visual studio 2010\Projects\SFML2Test\Debug\SFML2Test.exe : fatal error LNK1120: 18 unresolved externals
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========


--------------------------------------------------------------------------------------------------------

Any ideas? Thank you very much for taking the time to read and possibly respond.

binary1248

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1405
  • I am awesome.
    • View Profile
    • The server that really shouldn't be running
Re: SFML 2.0 Graphics linking error
« Reply #1 on: August 23, 2012, 08:07:34 am »
The fact that the error messages indicate that the linker is still looking for __declspec(dllimport) functions means that you didn't define SFML_STATIC properly.
SFGUI # SFNUL # GLS # Wyrm <- Why do I waste my time on such a useless project? Because I am awesome (first meaning).

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: SFML 2.0 Graphics linking error
« Reply #2 on: August 23, 2012, 09:29:19 am »
Additionally it's not a good practice to use pragma comment for linker settings, because such setting do not hace anything to do with the code but are project settings and should be set in the project settings of VS.
If you'd follow the official tutorial you'd see this all as well. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Zaid

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: SFML 2.0 Graphics linking error
« Reply #3 on: August 25, 2012, 11:08:31 pm »
The fact that the error messages indicate that the linker is still looking for __declspec(dllimport) functions means that you didn't define SFML_STATIC properly.

I'm not sure I understand? I never had this problem in SFML 1.6. How would I define SFML_STATIC?

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: SFML 2.0 Graphics linking error
« Reply #4 on: August 25, 2012, 11:26:16 pm »
Everything is explained in the tutorial. Check here for VS.

BTW, a lot of things have changed since 1.6. Before you had to define SFML_DYNAMIC to use dynamic libraries, now you do it for the static version.
SFML / OS X developer

Zaid

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: SFML 2.0 Graphics linking error
« Reply #5 on: August 25, 2012, 11:29:44 pm »
Everything is explained in the tutorial. Check here for VS.

BTW, a lot of things have changed since 1.6. Before you had to define SFML_DYNAMIC to use dynamic libraries, now you do it for the static version.

And by doing that... this happens:
1>------ Build started: Project: SFML2Test, Configuration: Debug Win32 ------
1>  main.cpp
1>msvcprtd.lib(MSVCP100D.dll) : error LNK2005: "void __cdecl std::_Debug_message(wchar_t const *,wchar_t const *,unsigned int)" (?_Debug_message@std@@YAXPB_W0I@Z) already defined in libcpmtd.lib(stdthrow.obj)
1>msvcprtd.lib(MSVCP100D.dll) : error LNK2005: "public: __thiscall std::_Lockit::~_Lockit(void)" (??1_Lockit@std@@QAE@XZ) already defined in libcpmtd.lib(xlock.obj)
1>msvcprtd.lib(MSVCP100D.dll) : error LNK2005: "public: __thiscall std::_Lockit::_Lockit(int)" (??0_Lockit@std@@QAE@H@Z) already defined in libcpmtd.lib(xlock.obj)
1>msvcprtd.lib(MSVCP100D.dll) : error LNK2005: "public: void __thiscall std::_Container_base12::_Orphan_all(void)" (?_Orphan_all@_Container_base12@std@@QAEXXZ) already defined in main.obj
1>msvcprtd.lib(MSVCP100D.dll) : error LNK2005: "public: __thiscall std::_Container_base12::~_Container_base12(void)" (??1_Container_base12@std@@QAE@XZ) already defined in main.obj
1>msvcprtd.lib(MSVCP100D.dll) : error LNK2005: "public: __thiscall std::_Container_base12::_Container_base12(void)" (??0_Container_base12@std@@QAE@XZ) already defined in main.obj
1>msvcprtd.lib(MSVCP100D.dll) : error LNK2005: "void __cdecl std::_Xlength_error(char const *)" (?_Xlength_error@std@@YAXPBD@Z) already defined in libcpmtd.lib(xthrow.obj)
1>msvcprtd.lib(MSVCP100D.dll) : error LNK2005: "void __cdecl std::_Xout_of_range(char const *)" (?_Xout_of_range@std@@YAXPBD@Z) already defined in libcpmtd.lib(xthrow.obj)
1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: __invalid_parameter already defined in LIBCMTD.lib(invarg.obj)
1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: __CrtDbgReportW already defined in LIBCMTD.lib(dbgrptw.obj)
1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: "public: __thiscall std::exception::exception(char const * const &)" (??0exception@std@@QAE@ABQBD@Z) already defined in LIBCMTD.lib(stdexcpt.obj)
1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: "public: virtual __thiscall std::exception::~exception(void)" (??1exception@std@@UAE@XZ) already defined in LIBCMTD.lib(stdexcpt.obj)
1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: "public: __thiscall std::exception::exception(class std::exception const &)" (??0exception@std@@QAE@ABV01@@Z) already defined in LIBCMTD.lib(stdexcpt.obj)
1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: _memmove already defined in LIBCMTD.lib(memmove.obj)
1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: __lock_file already defined in LIBCMTD.lib(_file.obj)
1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: __unlock_file already defined in LIBCMTD.lib(_file.obj)
1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: _fwrite already defined in LIBCMTD.lib(fwrite.obj)
1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: _ungetc already defined in LIBCMTD.lib(ungetc.obj)
1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: _memcpy_s already defined in LIBCMTD.lib(memcpy_s.obj)
1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: _fflush already defined in LIBCMTD.lib(fflush.obj)
1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: _fclose already defined in LIBCMTD.lib(fclose.obj)
1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: _free already defined in LIBCMTD.lib(dbgfree.obj)
1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: "public: __thiscall std::bad_cast::bad_cast(char const *)" (??0bad_cast@std@@QAE@PBD@Z) already defined in LIBCMTD.lib(stdexcpt.obj)
1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: _feof already defined in LIBCMTD.lib(feoferr.obj)
1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: _malloc already defined in LIBCMTD.lib(dbgmalloc.obj)
1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: _strtol already defined in LIBCMTD.lib(strtol.obj)
1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: _strncmp already defined in LIBCMTD.lib(strncmp.obj)
1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: _ldexp already defined in LIBCMTD.lib(_ldexp_.obj)
1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: _tolower already defined in LIBCMTD.lib(tolower.obj)
1>MSVCRTD.lib(ti_inst.obj) : error LNK2005: "private: __thiscall type_info::type_info(class type_info const &)" (??0type_info@@AAE@ABV0@@Z) already defined in LIBCMTD.lib(typinfo.obj)
1>MSVCRTD.lib(ti_inst.obj) : error LNK2005: "private: class type_info & __thiscall type_info::operator=(class type_info const &)" (??4type_info@@AAEAAV0@ABV0@@Z) already defined in LIBCMTD.lib(typinfo.obj)
1>MSVCRTD.lib(MSVCR100D.dll) : error LNK2005: ___iob_func already defined in LIBCMTD.lib(_file.obj)
1>LINK : warning LNK4098: defaultlib 'MSVCRTD' conflicts with use of other libs; use /NODEFAULTLIB:library
1>LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library
1>S:\Users\Logan\documents\visual studio 2010\Projects\SFML2Test\Debug\SFML2Test.exe : fatal error LNK1169: one or more multiply defined symbols found
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

jtjin

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: SFML 2.0 Graphics linking error
« Reply #6 on: August 26, 2012, 07:57:03 am »
Have not encountered this, but it looks like the version of SFML you're linking to has the std libs built-in, and your project is also set to link them in directly, which will result in duplicate definitions in the binary.

If you built the SFML libs from CMAKE, try unchecking the SFML_USE_STATIC_STD_LIBS option and building the library again. This will give you a set of sfml static libs that don't have the std libs included.

If you just downloaded SFML binaries from somewhere, try going to Linker -> Input -> Ignore Specific Default Libraries in your project settings and adding libcmtd;libcpmtd;msvcrtd to the list for debug and libcmt;libcpmt;msvcrt for release. This will tell the linker to not try linking in the stdlibs directly, as you're already linking to sfml libs that already have them.

More info here: http://msdn.microsoft.com/en-us/library/abx4dbyh(v=vs.110).aspx


eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: SFML 2.0 Graphics linking error
« Reply #7 on: August 26, 2012, 08:20:30 am »
Well you can link the runtime library statically in the library and the application you just have to make sure to use the right runtime library, that is /MTd or /MT which can be set in Project->Preferences->C++->Code Generator
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/