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

Author Topic: Static linking with Visual Studio 2012  (Read 5834 times)

0 Members and 1 Guest are viewing this topic.

Henri_

  • Newbie
  • *
  • Posts: 8
    • View Profile
Static linking with Visual Studio 2012
« on: April 23, 2015, 11:34:00 pm »
Hello there. First of all, this is my first post here.
Well, as the tittle says, I can't dynamic link the SFML 2.2 libraries into my project. I'm using Visual Studio 2012 and the respective SFML 2.2 x86 files. My project has a few custom settings and I did pay attention to:

- set the SFML_STATIC for the preprocessor
- set the path to the libraries folder (so its not necessary to put the full path to every lib file)
- set the -d libs for debug and no -d libs for release
- tried linking with the "freetype, glew, jpeg, openal32 and sndfile" lib files which come with the SFML 2.2 I downloaded from this site (note that "opengl32, ws2_32 and some others lib" are not in this list) and without them

However, it still did not work. Here's a small part of the build log:

1>------ Build started: Project: Game, Configuration: Release Win32 ------
1>LINK : warning LNK4075: ignoring '/INCREMENTAL' due to '/LTCG' specification
1>sfml-graphics-s.lib(Texture.cpp.obj) : error LNK2001: unresolved external symbol __imp__glBindTexture@8
1>sfml-graphics-s.lib(TextureSaver.cpp.obj) : error LNK2001: unresolved external symbol __imp__glBindTexture@8
1>sfml-graphics-s.lib(Texture.cpp.obj) : error LNK2001: unresolved external symbol __imp__glCopyTexSubImage2D@32
...

So, what am I doing wrong? Also, does it have something to do with the "/LTCG" warning above? If so, how do I fix it?
Thanks in advance

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Static linking with Visual Studio 2012
« Reply #1 on: April 23, 2015, 11:37:38 pm »
- tried linking with the "freetype, glew, jpeg, openal32 and sndfile" lib files which come with the SFML 2.2 I downloaded from this site (note that "opengl32, ws2_32 and some others lib" are not in this list) and without them

You must link to all of them at the same time, so with all of them in your linker list post the full build command.

http://www.sfml-dev.org/faq.php#tr-grl-verbose-ide
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

Henri_

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Static linking with Visual Studio 2012
« Reply #2 on: April 24, 2015, 01:45:13 am »
Hey, zsbzsb. Like I said, I did also try linking with the other libs, other than the 5 SFML libs (for each module). As an information, here are the linked libs:

$(SolutionDir)Dependency\Libraries\SFML\sfml-audio-s.lib
$(SolutionDir)Dependency\Libraries\SFML\sfml-graphics-s.lib
$(SolutionDir)Dependency\Libraries\SFML\sfml-network-s.lib
$(SolutionDir)Dependency\Libraries\SFML\sfml-system-s.lib
$(SolutionDir)Dependency\Libraries\SFML\sfml-window-s.lib
$(SolutionDir)Dependency\Libraries\SFML\glew.lib
$(SolutionDir)Dependency\Libraries\SFML\jpeg.lib
$(SolutionDir)Dependency\Libraries\SFML\freetype.lib
$(SolutionDir)Dependency\Libraries\SFML\openal32.lib
$(SolutionDir)Dependency\Libraries\SFML\sndfile.lib

Note 1: these are the ONLY libs that comes with the x86 SFML 2.2 (in the download section of this website)


The inherited libs:

kernel32.lib
user32.lib
gdi32.lib
winspool.lib
comdlg32.lib
advapi32.lib
shell32.lib
ole32.lib
oleaut32.lib
uuid.lib
odbc32.lib
odbccp32.lib

Note 2: The 2.2 tutorial says to link the opengl32.lib and some others I cant remember right now, however these dont come with the SFML 2.2 zip. Am I missing something?


If you meant the "build log", heres is the FULL build log with all the 10 libs above:

(click to show/hide)


Otherwise, if by "command" you mean the linker "command line", here it is:

(click to show/hide)
« Last Edit: April 24, 2015, 01:48:57 am by Henri_ »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Static linking with Visual Studio 2012
« Reply #3 on: April 24, 2015, 01:53:53 am »
Check zsbzsb's link and add the missing libraries, they are system libraries and come with the toolchain.
Also read again the official tutorial for Visual Studio, because you should not be linking against libraries with their absolute path, but instead you should add them just with their name (e.g. "sfml-graphics-s.lib") and provide the path to these libraries in the "Additional libraries" settings or similar (check the tutorial).

Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Henri_

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Static linking with Visual Studio 2012
« Reply #4 on: April 24, 2015, 03:08:28 am »
These are one of the things I have already done, exploiter. It's in my first post. The only problem is exactly WHICH are the missing libs and why (my fault? did they come with the SFML 2.2 zip? etc). I changed the "start up banner supressing", as the above link says and here's the log:

(click to show/hide)


In the same link above, we can see that the dependencies are as follows (http://www.sfml-dev.org/faq.php#build-link-static):

sfml-system
winmm
sfml-network
ws2_32
sfml-system
sfml-audio
openal32
sndfile
sfml-system
sfml-window
opengl32
winmm
gdi32
sfml-system
sfml-graphics
freetype
glew
jpeg
opengl32
sfml-window
sfml-system

So, this is my additional dependencies, according to the above link (can be seen the command build output above):

sfml-audio-s.lib (path to this file has been set in "additional library directories")
sfml-graphics-s.lib (path to this file has been set in "additional library directories")
sfml-network-s.lib (path to this file has been set in "additional library directories")
sfml-system-s.lib (path to this file has been set in "additional library directories")
sfml-window-s.lib (path to this file has been set in "additional library directories")
glew.lib (path to this file has been set in "additional library directories")
jpeg.lib (path to this file has been set in "additional library directories")
freetype.lib (path to this file has been set in "additional library directories")
openal32.lib (path to this file has been set in "additional library directories")
sndfile.lib (path to this file has been set in "additional library directories")
winmm.lib (this lib is stored somewhere in my computer?)
ws2_32.lib (this lib is stored somewhere in my computer?)
gdi32.lib (this lib is stored somewhere in my computer?)
opengl32.lib (this lib is stored somewhere in my computer?)


I can't find anywhere what else to be done, this is why I am here.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Static linking with Visual Studio 2012
« Reply #5 on: April 24, 2015, 12:37:28 pm »
These are one of the things I have already done, exploiter.
Well you didn't link against OpenGL in the posts above. ;)

here's the log:
You seem to have removed or changed the inherited libraries.

Fixed "unresolved symbols" is in most cases as easy as to copy the function name (e.g. DestroyWindow), past it into Google, see what library that function is from and add said library to the linker settings.

If you google any of the functions from the posted log, you'll end up on the MSDN page and it will show that they are part of User32.lib and Advapi32.lib. Since they are usually inherited or listed as "additional libraries", I assume you must have accidentally removed them.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Henri_

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Static linking with Visual Studio 2012
« Reply #6 on: April 24, 2015, 10:41:37 pm »
I have finally managed to solve it with your hint. I did not think about it. Really.

If you google any of the functions from the posted log, you'll end up on the MSDN page and it will show that they are part of User32.lib and Advapi32.lib. Since they are usually inherited or listed as "additional libraries", I assume you must have accidentally removed them.

You were indeed right. For some reasons, the 'inherit from parent' (in the additional dependencies, if you, reader, were having the same problem) was not selected for some reason, but still, looking for the function names in the MSDN did it. I just think this post deserves a stick or the documentation/tutorial should be updated for your information to be added. It is just too confusing whether the libraries linking order matters or not and which libraries have to be linked (in my case, the 'inherit' caused the whole problem).

If you, reader, had the same problem, see the solution below.

Additional Dependencies are (just keep the order for safety):
sfml-graphics-s.lib
freetype.lib
glew.lib
jpeg.lib
sfml-window-s.lib
opengl32.lib
sfml-system-s.lib
winmm.lib
sfml-audio-s.lib
openal32.lib
sndfile.lib
sfml-network-s.lib
ws2_32.lib

Also, make sure the 'Inherit from parent or project defaults' is selected.

Thanks both of you.

« Last Edit: April 24, 2015, 10:46:22 pm by Henri_ »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Static linking with Visual Studio 2012
« Reply #7 on: April 25, 2015, 12:47:19 am »
It is just too confusing whether the libraries linking order matters or not and which libraries have to be linked
Or people should just learn first how their toolchain works. SFML is not your "how to actually do more than print hello world on a console" guide and help forum, even though it unfortunately seems like it from time to time.

How you link libraries statically an shared and whether orders are important or not, is toolchain dependent and all SFML does is provide support for these toolchains. ;)

And for those wondering, linking order doesn't matter in Visual Studio, while it very well does with GCC (that includes the MinGW distributions).
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything