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

Author Topic: [SOLVED]Unresolved external symbol when statically linking  (Read 13044 times)

0 Members and 1 Guest are viewing this topic.

practikalmagik

  • Newbie
  • *
  • Posts: 7
    • View Profile
[SOLVED]Unresolved external symbol when statically linking
« on: July 27, 2016, 03:38:13 pm »
SOLUTION:
Firstly, thanks to the patient community who helped me (eventually) figure this out. The answer was in the tutorials and FAQs but it didn't click for me in the way it was written. So just in case anyone finds this thread in a similar situation, the Additional Dependencies needs to include ALL the window libs, not just the SFML libs,opengl32,winmmn.lib and gdi32.lib. As such, mine now works with them as:
Debug
sfml-window-s-d.lib;sfml-graphics-s-d.lib;sfml-audio-s-d.lib;sfml-network-s-d.lib;sfml-system-s-d.lib;sfml-main-d.lib;opengl32.lib;winmm.lib;gdi32.lib;freetype.lib;jpeg.lib;openal32.lib;flac.lib;vorbisenc.lib;vorbisfile.lib;vorbis.lib;ogg.lib;ws2_32.lib;
Release
sfml-window-s.lib;sfml-graphics-s.lib;sfml-audio-s.lib;sfml-network-s.lib;sfml-system-s.lib;sfml-main.lib;opengl32.lib;winmm.lib;gdi32.lib;freetype.lib;jpeg.lib;openal32.lib;flac.lib;vorbisenc.lib;vorbisfile.lib;vorbis.lib;ogg.lib;ws2_32.lib;


ORIGINAL POST:
I am having problems with static linking in SFML and Visual Studio. I'm having this linking problem in my game so I thought I would test out why by going back to basics by following the tutorial below:
http://www.sfml-dev.org/tutorials/2.2/start-vc.php

Using dynamic linking (and copying the .dlls from the sfml/bin folder to the project folder) it works as expected and I get that lime green circle as per the tutorial.

However if I then add the -s suffix as below:
Debug:
sfml-graphics-s-d.lib;sfml-window-s-d.lib;sfml-system-s-d.lib
Release:
sfml-graphics-s.lib;sfml-window-s.lib;sfml-system-s.lib

and add the SFML_STATIC macro to c/c++ preprocessor defintion I get a lot of "unresolved external symbol" errors referring to the sfml-graphics-s.lib, with the same error if its build in debug or release mode.

Can anyone advise as I can't see what I have missed from the tutorial and it works fine dynamically.

EDITED TO ADD ERRORS:

Error   LNK2001   unresolved external symbol __imp__glReadPixels@28   ConsoleApplication2   C:\Users\NAME\Documents\Visual Studio 2015\Projects\ConsoleApplication2\ConsoleApplication2\sfml-graphics-s.lib(RenderWindow.cpp.obj)   1   1   

Error   LNK2001   unresolved external symbol __imp__glBlendFunc@8   ConsoleApplication2   C:\Users\NAME\Documents\Visual Studio 2015\Projects\ConsoleApplication2\ConsoleApplication2\sfml-graphics-s.lib(RenderTarget.cpp.obj)   1   1   


etc. There are about 65 of these errors, all the same error type of LNK2001 for various functions in the sfml-graphics.lib
« Last Edit: July 27, 2016, 05:53:43 pm by practikalmagik »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Quote
I get a lot of "unresolved external symbol" errors
Can we see them?
Laurent Gomila - SFML developer

practikalmagik

  • Newbie
  • *
  • Posts: 7
    • View Profile
Yup sorry I should have added them originally. Edited OP to add.

GameBear

  • Jr. Member
  • **
  • Posts: 73
    • View Profile
    • Email
have you added the -s & -s-d lib files to:

C:\Users\NAME\Documents\Visual Studio 2015\Projects\ConsoleApplication2\ConsoleApplication2
I know some turoeials only tell you to add the standard lib files.
string message = "some random dude";
cout << "I'm just " << message;

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Just read the big red box that begins with "Starting from SFML 2.2, when static linking, you will have to [...]" in the tutorial you said you read ;)
Laurent Gomila - SFML developer

practikalmagik

  • Newbie
  • *
  • Posts: 7
    • View Profile
Thanks for pointing that bit out (must have missed it last time).
Additional Dependencies are now:
sfml-graphics-s-d.lib;sfml-window-s-d.lib;sfml-system-s-d.lib;opengl32.lib;winmm.lib;gdi32.lib

sfml-graphics-s.lib;sfml-window-s.lib;sfml-system-s.lib;opengl32.lib;winmm.lib;gdi32.lib

However, I'm still getting the imilar errors (only 10 of them this time though!)

Error   LNK2001   unresolved external symbol _jpeg_std_error   ConsoleApplication2   C:\Users\NAME\Documents\Visual Studio 2015\Projects\ConsoleApplication2\ConsoleApplication2\sfml-graphics-s.lib(ImageLoader.cpp.obj)   1   1   

Error   LNK2001   unresolved external symbol _jpeg_CreateCompress   ConsoleApplication2   C:\Users\NAME\Documents\Visual Studio 2015\Projects\ConsoleApplication2\ConsoleApplication2\sfml-graphics-s.lib(ImageLoader.cpp.obj)   1   1   



have you added the -s & -s-d lib files to:

C:\Users\NAME\Documents\Visual Studio 2015\Projects\ConsoleApplication2\ConsoleApplication2
I know some turoeials only tell you to add the standard lib files.
- isn't that essentially what I am doing by providing the SFML/lib address for additional library directories and then adding the addtional dependencies as above?

Or do I also need to copy the lib files over to the project folder too? So far the only thing I have added to the project folder was the .dll files from sfml/bin.
« Last Edit: July 27, 2016, 04:40:50 pm by practikalmagik »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: [SOLVED]Unresolved external symbol when statically linking
« Reply #6 on: July 27, 2016, 08:27:40 pm »
Quote
However, I'm still getting the imilar errors (only 10 of them this time though!)
Don't stop at the red box. There's a table right below with the full list of dependencies for each SFML module. And, the names of the unresolved symbols are quite clear regarding what's missing by the way ;)
Laurent Gomila - SFML developer