SFML community forums
Help => General => Topic started by: Stewbond 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:
#include <SFML/System.hpp>
int main()
{
sf::Clock Clock;
Clock.GetElapsedTime();
return 0;
}
But as soon as I do:
#include <SFML/Window.hpp>
int main()
{
sf::Window App;
return 0;
}
I get 27 linking errors of the form:
xxxx.lib(XXXX.dll) : error LNK2005: XXXXXXX already defined in XXXX.lib(XXXXX.dll)
and
: 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?
-
Did you enable STATIC_STD_LIBS in CMake when you compiled SFML?
-
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.
-
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.
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.
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?
-
Try building the libraries in Cmake with STATIC_STD_LIBS disabled, than define SFML_STATIC in the preprocessor.
-
Yeah, don't use STATIC_STD_LIBS unless you really know what you do.
And define SFML_STATIC if you link SFML statically.
-
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.
-
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.
-
Please do a complete report with your new settings:
- CMake options
- linker settings
- error messages
-
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.
-
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 :)
-
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.