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

Author Topic: Linker errors with SFML 2.0  (Read 6683 times)

0 Members and 1 Guest are viewing this topic.

mitchgc

  • Newbie
  • *
  • Posts: 27
    • View Profile
Linker errors with SFML 2.0
« on: May 26, 2011, 03:04:05 pm »
So after getting SFML 1.6 working, I find out that people on the project I'm working on can't get 1.6 working but can get 2.0 working. So I follow the tutorial that explains how to create the VS project files using CMake. I tried both VS 2010 and VS2005 (changing the settings in CMake accordingly) and both gave me the same behaviour when I tried to link statically to the libraries:
Quote
Error   1   error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall sf::Text::~Text(void)" (__imp_??1Text@sf@@UAE@XZ) referenced in function _main   main.obj
Error   2   error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall sf::Window::Display(void)" (__imp_?Display@Window@sf@@QAEXXZ) referenced in function _main   main.obj
Error   3   error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall sf::RenderTarget::Draw(class sf::Drawable const &)" (__imp_?Draw@RenderTarget@sf@@QAEXABVDrawable@2@@Z) referenced in function _main   main.obj
Error   4   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   main.obj
Error   5   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   main.obj
Error   6   error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall sf::Window::Close(void)" (__imp_?Close@Window@sf@@QAEXXZ) referenced in function _main   main.obj
Error   7   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   main.obj
Error   8   error LNK2019: unresolved external symbol "__declspec(dllimport) public: bool __thiscall sf::Window::IsOpened(void)const " (__imp_?IsOpened@Window@sf@@QBE_NXZ) referenced in function _main   main.obj
Error   9   error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::String::~String(void)" (__imp_??1String@sf@@QAE@XZ) referenced in function _main   main.obj
Error   10   error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::Text::Text(class sf::String const &,class sf::Font const &,unsigned int)" (__imp_??0Text@sf@@QAE@ABVString@1@ABVFont@1@I@Z) referenced in function _main   main.obj
Error   11   error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::String::String(char const *,class std::locale const &)" (__imp_??0String@sf@@QAE@PBDABVlocale@std@@@Z) referenced in function _main   main.obj
Error   12   error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall sf::RenderWindow::~RenderWindow(void)" (__imp_??1RenderWindow@sf@@UAE@XZ) referenced in function _main   main.obj
Error   13   error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::Font::~Font(void)" (__imp_??1Font@sf@@QAE@XZ) referenced in function _main   main.obj
Error   14   error LNK2019: unresolved external symbol "__declspec(dllimport) public: bool __thiscall sf::Font::LoadFromFile(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (__imp_?LoadFromFile@Font@sf@@QAE_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function _main   main.obj
Error   15   error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall sf::Font::Font(void)" (__imp_??0Font@sf@@QAE@XZ) referenced in function _main   main.obj
Error   16   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 long,struct sf::ContextSettings const &)" (__imp_??0RenderWindow@sf@@QAE@VVideoMode@1@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@KABUContextSettings@1@@Z) referenced in function _main   main.obj
Error   17   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   main.obj
Error   18   fatal error LNK1120: 17 unresolved externals   E:\Dev\Projects\VS2005 SFML2.0 Test\Debug\VS2005 SFML2.0 Test.exe

I can see that those errors look like I haven't included the correct libraries, but I've checked it a dozen times and it's all right.

The code I compiled with both IDEs:
Code: [Select]
#include "SFML/Audio.hpp"
#include "SFML/Graphics.hpp"

int main()
{
// Create the main window
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");

     sf::Font font;
     if(!font.LoadFromFile("arial.ttf"))
     {
         return EXIT_FAILURE;
     }


     sf::Text text("hello sfml", font, 50);

// Start the game loop
while (window.IsOpened())
{
// Process events
sf::Event event;
while (window.PollEvent(event))
{
// Close window : exit
if (event.Type == sf::Event::Closed)
window.Close();
}

// Clear screen
window.Clear();
         window.Draw(text);

// Update the window
window.Display();
}

return EXIT_SUCCESS;
}


VS2005 debug C++ settings:
Quote
/Od /I "E:\Dev\SFML-2.0\include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /Gm /EHsc /RTC1 /MTd /Fo"Debug\\" /Fd"Debug\vc80.pdb" /W3 /nologo /c /ZI /TP /errorReport:prompt


VS2005 debug (static) Linker settings:
Quote
/OUT:"E:\Dev\Projects\VS2005 SFML2.0 Test\Debug\VS2005 SFML2.0 Test.exe" /INCREMENTAL /NOLOGO /LIBPATH:"E:\Dev\SFML-2.0\8build\lib\debug" /MANIFEST /MANIFESTFILE:"Debug\VS2005 SFML2.0 Test.exe.intermediate.manifest" /DEBUG /PDB:"e:\dev\projects\vs2005 sfml2.0 test\debug\VS2005 SFML2.0 Test.pdb" /SUBSYSTEM:CONSOLE /MACHINE:X86 /ERRORREPORT:PROMPT sfml-audio-s-d.lib sfml-system-s-d.lib sfml-window-s-d.lib sfml-graphics-s-d.lib  kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib


VS2005 release libs:

VS2005 debug libs:

VS2010 (all libs):


So I tried to link dynamically...

VS2010 debug C++ settings:
Quote
/I"E:\Dev\SFML-2.0\include" /ZI /nologo /W3 /WX- /Od /Oy- /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /Gm /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Fp"Debug\VS2010 SFM 2.0 Test.pch" /Fa"Debug\" /Fo"Debug\" /Fd"Debug\vc100.pdb" /Gd /analyze- /errorReport:queue


VS2010 debug (static) Linker settings:
Quote
/OUT:"E:\Dev\Projects\VS2010 SFM 2.0 Test\Debug\VS2010 SFM 2.0 Test.exe" /INCREMENTAL /NOLOGO /LIBPATH:"E:\Dev\SFML-2.0\lib" "sfml-graphics-d.lib" "sfml-audio-d.lib" "sfml-window-d.lib" "sfml-system-d.lib" "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" /MANIFEST /ManifestFile:"Debug\VS2010 SFM 2.0 Test.exe.intermediate.manifest" /ALLOWISOLATION /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:"E:\Dev\Projects\VS2010 SFM 2.0 Test\Debug\VS2010 SFM 2.0 Test.pdb" /SUBSYSTEM:CONSOLE /PGD:"E:\Dev\Projects\VS2010 SFM 2.0 Test\Debug\VS2010 SFM 2.0 Test.pgd" /TLBID:1 /DYNAMICBASE /NXCOMPAT /MACHINE:X86 /ERRORREPORT:QUEUE


It compiles fine, but gives me this error:


Call stack (pointing to the construction of the sf::Text object):


Any help would be greatly appreciated.

Cheers.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Linker errors with SFML 2.0
« Reply #1 on: May 26, 2011, 03:13:10 pm »
Wow... that's a complete report :D

But I can tell you what's wrong from the very first line of your post ;)
You need to define SFML_STATIC for static linking.
Laurent Gomila - SFML developer

mitchgc

  • Newbie
  • *
  • Posts: 27
    • View Profile
Linker errors with SFML 2.0
« Reply #2 on: May 26, 2011, 03:21:36 pm »
Quote from: "Laurent"
Wow... that's a complete report :D

But I can tell you what's wrong from the very first line of your post ;)
You need to define SFML_STATIC for static linking.

Yeah well I didn't want to sound like a whinging brat, as I've been posting these kinds of problems a lot lately.

You'll have to excuse my bluntness because I'm a bit tired, but it does not mention SFML_STATIC anywhere. I can see that SFML_DYNAMIC is mentioned, but not SFML_STATIC.

Do you know why I might be getting that error when I link dynamically? It happens in debug and release mode.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Linker errors with SFML 2.0
« Reply #3 on: May 26, 2011, 03:34:26 pm »
Quote
Yeah well I didn't want to sound like a whinging brat

And I appreciate, that was a very good bug report actually ;)

Quote
You'll have to excuse my bluntness because I'm a bit tired, but it does not mention SFML_STATIC anywhere. I can see that SFML_DYNAMIC is mentioned, but not SFML_STATIC.

You're right, there's no mention of SFML_STATIC because there's no tutorial at all (yet) for SFML 2.0.
But there are many topics on the forum about this problem -- I don't know if they can easily be found though.

Quote
Do you know why I might be getting that error when I link dynamically? It happens in debug and release mode.

Sorry, I missed it (it was kind of lost in your report ;)).
Can you show me the full call stack?
Laurent Gomila - SFML developer

mitchgc

  • Newbie
  • *
  • Posts: 27
    • View Profile
Linker errors with SFML 2.0
« Reply #4 on: May 26, 2011, 03:40:36 pm »
Quote from: "Laurent"
Quote
Yeah well I didn't want to sound like a whinging brat

And I appreciate, that was a very good bug report actually ;)

Quote
You'll have to excuse my bluntness because I'm a bit tired, but it does not mention SFML_STATIC anywhere. I can see that SFML_DYNAMIC is mentioned, but not SFML_STATIC.

You're right, there's no mention of SFML_STATIC because there's no tutorial at all (yet) for SFML 2.0.
But there are many topics on the forum about this problem -- I don't know if they can easily be found though.

Quote
Do you know why I might be getting that error when I link dynamically? It happens in debug and release mode.

Sorry, I missed it (it was kind of lost in your report ;)).
Can you show me the full call stack?

Hahaha. I'm glad you liked it.


Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Linker errors with SFML 2.0
« Reply #5 on: May 26, 2011, 03:49:16 pm »
Looks like a configuration problem. Make sure that your VS2010 and VC2005 binaries are not mixed somehow.

I recommend to remove absolutely everything and restart from zero.

Does it happen with static linking too?
Laurent Gomila - SFML developer

mitchgc

  • Newbie
  • *
  • Posts: 27
    • View Profile
Linker errors with SFML 2.0
« Reply #6 on: May 26, 2011, 03:53:42 pm »
Quote from: "Laurent"
Looks like a configuration problem. Make sure that your VS2010 and VC2005 binaries are not mixed somehow.

I recommend to remove absolutely everything and restart from zero.

Does it happen with static linking too?

Everything. :shock: You don't mean reinstall both versions of Visual Studio do you?

Nope, static linking works a treat.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Linker errors with SFML 2.0
« Reply #7 on: May 26, 2011, 03:59:37 pm »
Quote
Everything.  You don't mean reinstall both versions of Visual Studio do you?

No :lol:
Only binary/tempoerary files that you generated when compiling SFML. In other words, remove your CMake build directories and anything that you potentially installed.
Laurent Gomila - SFML developer

mitchgc

  • Newbie
  • *
  • Posts: 27
    • View Profile
Linker errors with SFML 2.0
« Reply #8 on: May 26, 2011, 04:02:38 pm »
Quote from: "Laurent"
Quote
Everything.  You don't mean reinstall both versions of Visual Studio do you?

No :lol:
Only binary/tempoerary files that you generated when compiling SFML. In other words, remove your CMake build directories and anything that you potentially installed.

Oh haha. Ok, thanks. I'll try that tomorrow. Sleep time now..

mitchgc

  • Newbie
  • *
  • Posts: 27
    • View Profile
Linker errors with SFML 2.0
« Reply #9 on: May 27, 2011, 01:10:15 pm »
Ok I did a complete rebuild of SFML 2.0 for both IDEs.

VS2005:
Static debug and release work fine.
Dynamic debug gives me the old error with the same call stack:

Dynamic release works fine.

VS2010:
Static debug and release work fine.
Dynamic debug, again, gives me the old error with the same call stack.
Dynamic release works fine.

VS2005 dynamic debug C++ settings:
Quote
/Od /I "E:\Dev\SFML-2.0\include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "SFML_DYNAMIC" /D "_MBCS" /Gm /EHsc /RTC1 /MDd /Fo"Debug\\" /Fd"Debug\vc80.pdb" /W3 /nologo /c /ZI /TP /errorReport:prompt


VS2005 dynamic debug linker settings:
Quote
/OUT:"E:\Dev\Projects\VS2005 SFML2.0 Test\Debug\VS2005 SFML2.0 Test.exe" /INCREMENTAL /NOLOGO /LIBPATH:"E:\Dev\SFML-2.0\build\lib\debug" /MANIFEST /MANIFESTFILE:"Debug\VS2005 SFML2.0 Test.exe.intermediate.manifest" /DEBUG /PDB:"e:\Dev\Projects\VS2005 SFML2.0 Test\debug\VS2005 SFML2.0 Test.pdb" /SUBSYSTEM:CONSOLE /MACHINE:X86 /ERRORREPORT:PROMPT sfml-graphics-d.lib sfml-window-d.lib sfml-system-d.lib  kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib


VS2010 dynamic debug C++ settings:
Quote
/I"E:\Dev\SFML-2.0\include" /ZI /nologo /W3 /WX- /Od /Oy- /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "SFML_DYNAMIC" /D "_MBCS" /Gm /EHsc /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Fp"Debug\VS2010 SFM 2.0 Test.pch" /Fa"Debug\" /Fo"Debug\" /Fd"Debug\vc100.pdb" /Gd /analyze- /errorReport:queue


VS2010 dynamic debug linker settings:
Quote
/OUT:"E:\Dev\Projects\VS2010 SFM 2.0 Test\Debug\VS2010 SFM 2.0 Test.exe" /INCREMENTAL /NOLOGO /LIBPATH:"E:\Dev\SFML-2.0\build_2010\lib\Debug" "sfml-graphics-d.lib" "sfml-audio-d.lib" "sfml-window-d.lib" "sfml-system-d.lib" "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" /MANIFEST /ManifestFile:"Debug\VS2010 SFM 2.0 Test.exe.intermediate.manifest" /ALLOWISOLATION /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /DEBUG /PDB:"E:\Dev\Projects\VS2010 SFM 2.0 Test\Debug\VS2010 SFM 2.0 Test.pdb" /SUBSYSTEM:CONSOLE /PGD:"E:\Dev\Projects\VS2010 SFM 2.0 Test\Debug\VS2010 SFM 2.0 Test.pgd" /TLBID:1 /DYNAMICBASE /NXCOMPAT /MACHINE:X86 /ERRORREPORT:QUEUE

 

anything