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

Author Topic: LNK2001: unresolved external symbol  (Read 7760 times)

0 Members and 2 Guests are viewing this topic.

Charsmud

  • Newbie
  • *
  • Posts: 30
    • View Profile
LNK2001: unresolved external symbol
« 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:

Code: [Select]
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? 

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: LNK2001: unresolved external symbol
« Reply #1 on: January 06, 2014, 08:31:50 am »
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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Daddi

  • Jr. Member
  • **
  • Posts: 66
    • View Profile
    • http://foxdev.de/
    • Email
Re: LNK2001: unresolved external symbol
« Reply #2 on: January 06, 2014, 11:09:00 am »
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?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: LNK2001: unresolved external symbol
« Reply #3 on: January 06, 2014, 12:09:19 pm »
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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Daddi

  • Jr. Member
  • **
  • Posts: 66
    • View Profile
    • http://foxdev.de/
    • Email
Re: LNK2001: unresolved external symbol
« Reply #4 on: January 06, 2014, 01:39:29 pm »
Thank you very much, thats a great answer :)

amir ramezani

  • Jr. Member
  • **
  • Posts: 81
  • i'm a programmer who can't see well
    • View Profile
    • download useful software!
    • Email
Re: LNK2001: unresolved external symbol
« Reply #5 on: January 06, 2014, 02:06:43 pm »
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
if you can't see well, you can't test your applications and operating system well
my game engine:
allegro game creator
my operating system:
AmirOS

Charsmud

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: LNK2001: unresolved external symbol
« Reply #6 on: January 06, 2014, 05:35:33 pm »
@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. 

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: LNK2001: unresolved external symbol
« Reply #7 on: January 06, 2014, 06:01:46 pm »
What's the runtime libs you're linking?

At best you post the full build command here.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Charsmud

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: LNK2001: unresolved external symbol
« Reply #8 on: January 06, 2014, 06:11:45 pm »
Here is what is output after I followed the steps on the link:

Code: [Select]
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 ==========

Charsmud

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: LNK2001: unresolved external symbol
« Reply #9 on: January 07, 2014, 07:23:46 pm »
Any ideas? I  just simply cannot figure out why this is happening, as I haven't #included <string> anywhere.

amir ramezani

  • Jr. Member
  • **
  • Posts: 81
  • i'm a programmer who can't see well
    • View Profile
    • download useful software!
    • Email
Re: LNK2001: unresolved external symbol
« Reply #10 on: January 07, 2014, 07:33:34 pm »
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
if you can't see well, you can't test your applications and operating system well
my game engine:
allegro game creator
my operating system:
AmirOS

Charsmud

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: LNK2001: unresolved external symbol
« Reply #11 on: January 07, 2014, 07:34:55 pm »
Is this file something I need to download, or is it already in the system?  I didn't see it in the SFML package. 

amir ramezani

  • Jr. Member
  • **
  • Posts: 81
  • i'm a programmer who can't see well
    • View Profile
    • download useful software!
    • Email
Re: LNK2001: unresolved external symbol
« Reply #12 on: January 07, 2014, 07:40:30 pm »
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
if you can't see well, you can't test your applications and operating system well
my game engine:
allegro game creator
my operating system:
AmirOS

Charsmud

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: LNK2001: unresolved external symbol
« Reply #13 on: January 07, 2014, 07:47:09 pm »
Linking that .lib file did not fix the problem.  :( 

amir ramezani

  • Jr. Member
  • **
  • Posts: 81
  • i'm a programmer who can't see well
    • View Profile
    • download useful software!
    • Email
Re: LNK2001: unresolved external symbol
« Reply #14 on: January 07, 2014, 08:11:40 pm »
I don't know what is the problem
I'm sorry, because I'm not using MSVC
if you can't see well, you can't test your applications and operating system well
my game engine:
allegro game creator
my operating system:
AmirOS