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

Author Topic: Visual Studio 12 (2013 preview) static linking  (Read 4991 times)

0 Members and 1 Guest are viewing this topic.

Incubbus

  • Newbie
  • *
  • Posts: 12
    • ICQ Messenger - 315161720
    • View Profile
    • http://incubbus.eu
Visual Studio 12 (2013 preview) static linking
« on: August 28, 2013, 12:46:34 am »
Heya,

I did create the visual studio 12-solutions using CMake (had to use solutions, because my antivir would give me 2 alerts about a trojan when building an nmake-thing)...

When using the shared-libs option in CMake everything works fine (tested with the tutorial code)...

But when i try to use the static libs (sfml-xxx-s-d.lib e.g.) visual studio could not load the following projects, because the the vcxproj-files had invalid entries:

sfml-audio
sfml-graphics
sfml-window
sfml-network

the invalid entries were the "<Lib> <AdditionalOptions>..." -entries...
So i did delete those and added an cpp file to every project which includes the additional dependencies mentioned in the <Lib>-section.

But when i tried building a test-project with static linkage, visual studio reported linking errors to missing external symbols...

After trying some things i got it to work:
I had to add the library files mentioned in the lib-sections manually as additional dependencies.
E.g.:
When using sfml-window-s.lib & sfml-graphics-s.lib i had to do the following:
#pragma comment(lib, "glew.lib")
#pragma comment(lib, "freetype.lib")
#pragma comment(lib, "jpeg.lib")
#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "winmm.lib")
#pragma comment(lib, "gdi32.lib")
(Of course, this would also work then adding them manually in the project properties)...

Anyone knows why i have to do add those libs manually and why they are not included in the sfml-lib-files, and how to fix this?...

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Visual Studio 12 (2013 preview) static linking
« Reply #1 on: August 28, 2013, 07:51:11 am »
A static library is just an archive of compiled files, no linking step is performed. Therefore, all the dependencies have to be linked when you build your own executable that depends on SFML. So what you did is just how things are supposed to be done.

(Un)fortunately, Visual C++ provides a simple way to "merge" static libraries in other static libraries, so this is what SFML does so that users don't have to bother with SFML dependencies themselves.

Two possible explanations to your problem:
- your version of Visual C++ is not correctly handled in my CMake scripts (I don't have the time to check now, sorry)
- or they suddenly removed the ability to merge static libraries in the new version of Visual C++ (this is very unlikely)
Laurent Gomila - SFML developer