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

Author Topic: Tutorial - Window - Opening a window - doesn't work  (Read 3351 times)

0 Members and 1 Guest are viewing this topic.

yoni0505

  • Newbie
  • *
  • Posts: 9
    • View Profile
Tutorial - Window - Opening a window - doesn't work
« on: August 26, 2011, 09:28:35 pm »
It works fine when I use DLLs, but when I try to statically link the libs it give me errors.

Using SFML 1.6 and VC++ 2010 (with recompiled files):

I open empty win32 project.
use the code from the tutorial example.
change from "debug" to "release".
link:
sfml-system-s.lib
sfml-window-s.lib
sfml-main.lib

and I get these errors:

Code: [Select]
1>------ Build started: Project: SFML - Opening a window, Configuration: Release Win32 ------
1>  main.cpp
1>sfml-window-s.lib(WindowImplWin32.obj) : error LNK2001: unresolved external symbol "__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: unresolved external symbol "__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: unresolved external symbol "__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: unresolved external symbol "__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: unresolved external symbol "__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: unresolved external symbol "__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: unresolved external symbol "__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>c:\users\home-2\documents\visual studio 2010\Projects\SFML - Opening a window\Release\SFML - Opening a window.exe : fatal error LNK1120: 2 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


*the first SFML program example at the "SFML and Visual Studio" tutorial works for me.

I used to use SFML before and it used to work. What do I do wrong?
"There is no knowledge that is not power."

OniLinkPlus

  • Hero Member
  • *****
  • Posts: 500
    • View Profile
Tutorial - Window - Opening a window - doesn't work
« Reply #1 on: August 27, 2011, 02:00:48 am »
Add SFML_STATIC to your defines.
I use the latest build of SFML2

yoni0505

  • Newbie
  • *
  • Posts: 9
    • View Profile
Tutorial - Window - Opening a window - doesn't work
« Reply #2 on: August 27, 2011, 05:49:30 am »
Quote from: "OniLink10"
Add SFML_STATIC to your defines.

I tried add "SFML_STATIC" to my defines (preprocessor definitions) but I still get the same errors.

I also notice that all the errors related to the sfml-window-s.lib
"There is no knowledge that is not power."

Serapth

  • Full Member
  • ***
  • Posts: 105
    • View Profile
Tutorial - Window - Opening a window - doesn't work
« Reply #3 on: August 28, 2011, 11:56:22 pm »
The problem is for Visual Studio 2010 at least, the build process is a bit broken, and the Debug-Static project settings build incorrectly.  Even though you build them yourself, some of the static libs get compiled with the wrong linker flags.  A single lib linking to the wrong runtime, or not recompiled for VC2010 is going to be a showstopper.


Here is the easiest way to fix it, if you want to use static libraries.

Import the solution from SFML-1.6-sdk-windows-vc2008 in Visual Studio 2010.

Delete all of the example projects from your solution ( to make your life a hell of a lot easier )

Now for each of the SFML libraries, right click the project, select Properties.  Make sure "Configuration:" is set to Active(Debug static).

Then select Configuration Properties-> Code Generation, on the right find Runtime Library and make sure it is changed to Multi-threaded Debug  ( instead of Multi Threaded Debug DLL as it is now ).

Rebuild your libraries.  After the build is completed, your static libraries will be located at <Project Root>\SFML-1.6\lib\vc2008.

Copy these 5 freshly created libs to your new project, and make sure it's runtime setting it set the same.  Keep in mind, you will also need to build for static release as well when you are ready to deploy.

If you run into problems, here are the libs precompiled for you.  Just add them to your project, make sure your Runtime Library is set right and you should be good to go.



Or save yourself a ton of effort and link to the dynamic libs. :)

yoni0505

  • Newbie
  • *
  • Posts: 9
    • View Profile
Tutorial - Window - Opening a window - doesn't work
« Reply #4 on: September 10, 2011, 12:31:46 pm »
Thank you Serapth, your solution is working.  :)
"There is no knowledge that is not power."

 

anything