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

Author Topic: Linking errors  (Read 3579 times)

0 Members and 1 Guest are viewing this topic.

Stewbond

  • Newbie
  • *
  • Posts: 9
    • View Profile
Linking errors
« on: February 20, 2012, 08:29:50 pm »
I'm running SFML 2.0 with VS2010.  I've done a few SFML projects before so the libraries themselves should be good.  I am trying to statically link some libraries but can't figure out what is wrong.

This will compile:
Code: [Select]
#include <SFML/System.hpp>
int main()
{
sf::Clock Clock;
Clock.GetElapsedTime();
return 0;
}


But as soon as I do:
Code: [Select]
#include <SFML/Window.hpp>
int main()
{
sf::Window App;
return 0;
}


I get 27 linking errors of the form:
Code: [Select]
xxxx.lib(XXXX.dll) : error LNK2005: XXXXXXX already defined in XXXX.lib(XXXXX.dll)
and
Code: [Select]
: fatal error LNK1169: one or more multiply defined symbols found

I have the libraries linked as additional dependancies. I've tried /NODEFAULTLIB as the warnings recommend, but that causes more errors. I've also defined SFML_STATIC and STATIC_STD_LIBS in my Preprocessor.  I've also tried it without STATIC_STD_LIBS with no change.

Am I missing something?
Thank you!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Linking errors
« Reply #1 on: February 20, 2012, 08:36:58 pm »
Did you enable STATIC_STD_LIBS in CMake when you compiled SFML?
Laurent Gomila - SFML developer

Stewbond

  • Newbie
  • *
  • Posts: 9
    • View Profile
Linking errors
« Reply #2 on: February 20, 2012, 08:48:11 pm »
I am fairly confident that it was.  I've used these libs before in December so I can't remember, but I do recall that my CMake looked exactly like the one in the tutorial.  I will try and recompile just in case.
Thank you!

Stewbond

  • Newbie
  • *
  • Posts: 9
    • View Profile
Linking errors
« Reply #3 on: February 20, 2012, 09:47:48 pm »
Okay, so I can't quite figure out how to make the static libraries.  That's okay, I just want it to work with the libraries that I have.

I accidently forgot to save the file that I had copied my original code into when I had trimmed the original down for the sake of this post, meaning I just lost my 400 lines of code.  Dang.  I've written a skeleton back and I am still getting my linking errors:

This time I am using the non-static release libraries in my additional dependencies and I've taken out the SFML_STATIC preprocessor define.
Quote
C:\Dev\SFML\build\lib\Release\sfml-graphics.lib
C:\Dev\SFML\build\lib\Release\sfml-window.lib
C:\Dev\SFML\build\lib\Release\sfml-system.lib  


When I declare sf::Clock Clock; It compiles fine, but I found that when I use Clock.GetElapsedTime(); I now have unresolved external symbols.  The same is true for any object I use from any class from Graphics, window or system.
Code: [Select]
1>Snippets.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: bool __thiscall sf::Window::IsOpened(void)const " (__imp_?IsOpened@Window@sf@@QBE_NXZ)
1>Snippets.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: void __thiscall sf::Clock::Reset(void)" (__imp_?Reset@Clock@sf@@QAEXXZ)
1>Snippets.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: unsigned int __thiscall sf::Clock::GetElapsedTime(void)const " (__imp_?GetElapsedTime@Clock@sf@@QBEIXZ)
1>C:\Users\Stew\Documents\Visual Studio 2010\Projects\Snippets\Release\Snippets.exe : fatal error LNK1120: 3 unresolved externals


Are there any ideas where I may have gone wrong?
Thank you!

robvleugel

  • Newbie
  • *
  • Posts: 29
    • View Profile
Linking errors
« Reply #4 on: February 20, 2012, 10:05:58 pm »
Try building the libraries in Cmake with STATIC_STD_LIBS disabled, than define SFML_STATIC in the preprocessor.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Linking errors
« Reply #5 on: February 20, 2012, 10:08:15 pm »
Yeah, don't use STATIC_STD_LIBS unless you really know what you do.

And define SFML_STATIC if you link SFML statically.
Laurent Gomila - SFML developer

Stewbond

  • Newbie
  • *
  • Posts: 9
    • View Profile
Linking errors
« Reply #6 on: February 20, 2012, 10:14:05 pm »
Thanks robvleugel

I just disabled STATIC_STD_LIBS in CMake, recompiled SFML and tried to compile my project with and without the SFML_STATIC preprocessor.  In both cases, I got the unresolved external symbol error.

I don't really care if I use static or dynamic libraries.  At this point I just want something.
Thank you!

Stewbond

  • Newbie
  • *
  • Posts: 9
    • View Profile
Linking errors
« Reply #7 on: February 20, 2012, 10:37:26 pm »
Say, are there any OpenGL requirements for this?  I just want to use RenderWindow in 2D to display some shapes (circles) that bounce around.  I don't think I have any OpenGL libs installed although this doesn't explain why I am getting unresolved clock issues.
Thank you!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Linking errors
« Reply #8 on: February 21, 2012, 08:18:55 am »
Please do a complete report with your new settings:
- CMake options
- linker settings
- error messages
Laurent Gomila - SFML developer

Stewbond

  • Newbie
  • *
  • Posts: 9
    • View Profile
Linking errors
« Reply #9 on: February 21, 2012, 05:40:07 pm »
I'm sure you've better things to do than help another guy with linking problems.  I've decided that it will be easier for me to just include the source files from SFML that I am using and build it locally with my project.  You can consider this issue resolved.

This isn't the first time I've decided to link SFML this way. I don't know why this library is always so hard for me to link.  Even Boost took more time to download and compile than install.
Thank you!

robvleugel

  • Newbie
  • *
  • Posts: 29
    • View Profile
Linking errors
« Reply #10 on: February 21, 2012, 09:42:11 pm »
All steps for building SFML 2.0 using Cmake and using it staticly on Windows-Visual Studio 10 Express (atleast, this is how I did it)

- Download latest zip archive SFML2 and extract
- Open Visual studio command prompt as administrator (by right clicking and select 'Run as administrator'
- Open Cmake-gui in this command prompt by entering 'cmake-gui', set source code folder to the extracted zip archive, destination folder to whatever you like.
- Press the configure button
- Specify generator: "NMake Makefiles" (using default native compilers)
- BUILD_DOC to FALSE
- BUILD_EXAMPLES to FALSE
- BUILD_SHARED_LIBS to FALSE
- GLEW_INCLUDE_PATH to "[zip-archive]/extlibs/headers"
- GLEW_LIBRARY to "[zip-archive]/extlibs/libs-msvc/x86/glew.lib"
- STATIC_STD_LIBS to FALSE
- CMAKE_BUILD_TYPE to Release
- CMAKE_INSTALL_PREFIX to "C:/Program Files (x86)/SFML" (or whatever you want it installed in)

- Press configure again
- Press generate
- Switch to the VS command prompt, locate the destination folder and type 'nmake install'
- Change 'Release' to 'Debug' in Cmake, press configure again and press generate.
- Type 'nmake install' again in the command prompt.
- Exit cmake and command prompt, check to see if the sfml-xxx-s-d.lib and sfml-xxx-s.lib files are created.
- Open a new SFML project, define SFML_STATIC in the preprocessor and link to the correct libraries.

If it still doesn't work, something is wrong :)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Linking errors
« Reply #11 on: February 21, 2012, 10:18:38 pm »
Quote
I'm sure you've better things to do than help another guy with linking problems

No.

There's nothing complex about building and using SFML statically, you're just using a wrong option and if you simply show me what you did I'll tell you how you can correct it.
Laurent Gomila - SFML developer

 

anything