SFML community forums
Help => General => Topic started by: Charsmud on January 06, 2014, 05:28:19 am
-
Hello! I am having a linker error which I just cannot seem to solve. For some reason, VS2010 cannot seem to link the library needed for basic_string:
1>------ Build started: Project: CharsEngine, Configuration: Release Win32 ------
1>Application.obj : error LNK2001: unresolved external symbol "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl toString<unsigned int>(unsigned int const &)" (??$toString@I@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@ABI@Z)
1>C:\Users\Will\Documents\Visual Studio 2010\Projects\CharsEngine\Release\CharsEngine.exe : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I cannot seem to get this to work in either debug or release. Any ideas?
-
You're mixing debug and release modes. Link against debug (with -d suffix) libraries in debug mode and against release (no suffix) libraries in release mode.
-
May I ask in this thread, what the difference between the debug and non-debug libs is?
Is it the "-g" flag (for debugging symbols) and the lack of optimization flags or is there more to it?
-
Hard to say since every compiler will add its own stuff. But in general debug libraries get debug symbols, so that the debugger knows what belongs to what, additionally the code doesn't get optimized (too much).
For example if you run the debugger with release binaries and try to break at certain locations, it will just jump over them and break somewhere else, because either the code piece got optimized away or the debugger simply doesn't know where to stop.
The linker issue one sees with VS is mostly always due to the fact that, when you're in debug mode VS will use the debug runtime libraries, while the SFML DLLs are linked with the release runtime library and thus there are somewhere incompatible functions. Interestingly enough most of the time it will cause an error with strings, thus after seeing it a few times, the issue gets obvious quickly.
-
Thank you very much, thats a great answer :)
-
debug builds have simbles that debugger can set breakpoints on there and execute or stop them
when you optimize them, the debugging information get's removed and the debugger doesn't know where is the problem
for example without a debugger, in debug mode the assert can work
but if you build your project in release mode, the assert get's removed and your program doesn't stop when the expression isn't true
another thing is the differences between compilers and debuggers
for example a debugger can debug just the code that compiled with MSVC while a debugger can debug the code that GCC compiled it
I hope that I explained it good
if you have any questions, please ask here
I recommend you to debug your project before build it as a release binary
-
@eXpl0it3r, This is what I have under Project Properties->Linker->Input->Additional Dependencies
For Release:
sfml-graphics.lib
sfml-window.lib
sfml-system.lib
sfml-network.lib
sfml-audio.lib
and Debug:
sfml-graphics-d.lib
sfml-window-d.lib
sfml-system-d.lib
sfml-network-d.lib
sfml-audio-d.lib
I did exclude the Inherited Values from the above list because they aren't related to the problem (unless I'm wrong).
I tried rebuilding and running again in both debug and release mode to no avail: same LNK error.
-
What's the runtime libs you're linking?
At best you post the full build command (http://en.sfml-dev.org/forums/index.php?topic=12552.0) here.
-
Here is what is output after I followed the steps on the link:
1>------ Build started: Project: CharsEngine, Configuration: Release Win32 ------
1> Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.40219.01 for 80x86
1> Copyright (C) Microsoft Corporation. All rights reserved.
1>
1> cl /c /IC:\Users\Will\Documents\OpenGL\include /Zi /nologo- /W3 /WX- /O2 /Oi /Oy- /GL /D _MBCS /Gm- /EHsc /MD /GS /Gy /fp:precise /Zc:wchar_t /Zc:forScope /Fo"Release\\" /Fd"Release\vc100.pdb" /Gd /TP /analyze- /errorReport:prompt Aircraft.cpp Application.cpp Command.cpp CommandQueue.cpp Entity.cpp GameState.cpp Main.cpp MenuState.cpp PauseState.cpp Player.cpp SceneNode.cpp SpriteNode.cpp State.cpp StateStack.cpp TitleState.cpp Utility.cpp World.cpp
1>cl : Command line warning D9035: option 'nologo-' has been deprecated and will be removed in a future release
1>
1> Aircraft.cpp
1> Application.cpp
1> Command.cpp
1> CommandQueue.cpp
1> Entity.cpp
1> GameState.cpp
1> Main.cpp
1> MenuState.cpp
1> PauseState.cpp
1> Player.cpp
1> SceneNode.cpp
1> SpriteNode.cpp
1> State.cpp
1> StateStack.cpp
1> TitleState.cpp
1> Utility.cpp
1> World.cpp
1> Microsoft (R) Incremental Linker Version 10.00.40219.01
1> Copyright (C) Microsoft Corporation. All rights reserved.
1>
1> "/OUT:C:\Users\Will\Documents\Visual Studio 2010\Projects\CharsEngine\Release\CharsEngine.exe" /LIBPATH:C:\Users\Will\Documents\OpenGL\lib\SFML "sfml-graphics.lib" "sfml-window.lib" "sfml-system.lib" "sfml-network.lib" "sfml-audio.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:Release\CharsEngine.exe.intermediate.manifest" "/MANIFESTUAC:level='asInvoker' uiAccess='false'" /DEBUG "/PDB:C:\Users\Will\Documents\Visual Studio 2010\Projects\CharsEngine\Release\CharsEngine.pdb" /OPT:REF /OPT:ICF /LTCG /TLBID:1 /DYNAMICBASE /NXCOMPAT "/IMPLIB:C:\Users\Will\Documents\Visual Studio 2010\Projects\CharsEngine\Release\CharsEngine.lib" /MACHINE:X86 Release\Aircraft.obj
1> Release\Application.obj
1> Release\Command.obj
1> Release\CommandQueue.obj
1> Release\Entity.obj
1> Release\GameState.obj
1> Release\Main.obj
1> Release\MenuState.obj
1> Release\PauseState.obj
1> Release\Player.obj
1> Release\SceneNode.obj
1> Release\SpriteNode.obj
1> Release\State.obj
1> Release\StateStack.obj
1> Release\TitleState.obj
1> Release\Utility.obj
1> Release\World.obj
1>Application.obj : error LNK2001: unresolved external symbol "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl toString<unsigned int>(unsigned int const &)" (??$toString@I@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@ABI@Z)
1>C:\Users\Will\Documents\Visual Studio 2010\Projects\CharsEngine\Release\CharsEngine.exe : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
-
Any ideas? I just simply cannot figure out why this is happening, as I haven't #included <string> anywhere.
-
you haven't included <string> anyware
but sfml included
the first thing that I can say, link msvcrt.lib in your release build, and for your debug, link msvcrtd.lib
the second thing that I can say, link msvcr${your run-time-version}.lib for release and for your debug build, link msvcr${your-run-time-version}d.lib
as ${your-run-time-version} represent's your runtime version
I think this can fix the problem
-
Is this file something I need to download, or is it already in the system? I didn't see it in the SFML package.
-
it must be exist on your visual studio directory, inside vc inside lib
and a question:
why you want to use MSVC?
gcc doesn't have these problems
-
Linking that .lib file did not fix the problem. :(
-
I don't know what is the problem
I'm sorry, because I'm not using MSVC
-
Repeating what the error message already tells you: The function toString<unsigned int>(unsigned int const &) is not defined, or its definition is not visible to the linker.
Since this is a function template, you have to ensure that the definition is provided in the header -- the book uses .inl for it, don't use .cpp files. Templates must always be defined in header files if they are used across translation units.
-
Thanks, that fixed it. :)