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

Author Topic: Static libraries  (Read 5126 times)

0 Members and 3 Guests are viewing this topic.

Kuker

  • Newbie
  • *
  • Posts: 8
    • View Profile
Static libraries
« on: January 31, 2015, 05:41:58 pm »
Hello there! I have a problem with linking static libraries in Visual Studio 13. I've read, that now i have to link (type them in ProjectProperties->Linker->Input->Additional Dependencies) all libraries. The problem is, i still get linker or IntelliSense errors. My question and request for you, is that you should add in tutorial what EXACTLY should be typed in there to get static libraries ;). For many new people this is very hard, as it is for me, cause i don't really know if i should type then in All Configurations, or only in Debug or somewhere else.
Thank you in advance for any help, and sorry if I wrote something wrong.
Cheers!

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Static libraries
« Reply #1 on: January 31, 2015, 05:49:08 pm »
First of all; you can mostly ignore intellisense errors. Intellisense uses a completely different parser than the actual compiler. Intellisense can help sometimes provide "tips" but it doesn't have anything to do with what the real compiler actually does with your code. It's just a "helper".

As far as linking libraries goes;  any C++ developer worth his salt should know how his toolchain works. This includes knowing the rules the linker follows when linking static and/or dynamic libraries and how to configure that in his buildsystem of choice.  The basic rule is; depending libraries need to be linked before the libraries providing needed facilities.

Sure, the tutorials could maybe spoon-feed info a bit more, but in the long term you still need to learn this stuff for yourself.

In any case; this is just my personal opinion.
« Last Edit: January 31, 2015, 06:09:06 pm by Jesper Juhl »

Kuker

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Static libraries
« Reply #2 on: January 31, 2015, 06:11:35 pm »
Thank you for your reply. So, you're telling me to check in what order are the libraries linked? I thought it doesn't matter in VS13 :).

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Static libraries
« Reply #3 on: January 31, 2015, 06:14:59 pm »
Library linking order matters. Yes.
As does explicitly mentioning all needed libraries to the linker.
You need to mention all needed libs and you need to mention them in proper order.
Some compilers/linkers may relax the rules and pull in stuff for you implicitly, but don't count on it.

And don't forget that debug and release versions of a library are not the same. You sometimes (often) need to link different libs for debug and release builds...
« Last Edit: January 31, 2015, 06:18:59 pm by Jesper Juhl »

Kuker

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Static libraries
« Reply #4 on: January 31, 2015, 06:19:33 pm »
So if I want to use these three modules (i think this is their definition): sfml-system-s, sfml-windows-s, sfml-graphics-s, I have to link these things aswell: winmm.lib, opengl32.lib, gdi32.lib, glew.lib, freetype.lib, jpeg.lib?

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Static libraries
« Reply #5 on: January 31, 2015, 06:24:17 pm »
For static linking that looks about right (on my phone atm, can't check) - why don't you just try? ;-)  and/or read up on the details ;)

Edit: I admit that I'm probably not the best guy to help with this since I tend to assume that people have the basics already worked out. And I'm maybe not very good at being considerate and helpful. More of an old arrogant ass. - sorry.
« Last Edit: January 31, 2015, 06:53:45 pm by Jesper Juhl »

Kuker

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Static libraries
« Reply #6 on: January 31, 2015, 07:09:21 pm »
Well, it does not work :/. That's why i would like someone to tell me what and where to type.

Rosme

  • Full Member
  • ***
  • Posts: 169
  • Proud member of the shoe club
    • View Profile
    • Code-Concept
Re: Static libraries
« Reply #7 on: January 31, 2015, 08:45:31 pm »
Because the list here, right after the red box that explains how to link static is not clear enough? I don't see how it could more clear.
GitHub
Code Concept
Twitter
Rosme on IRC/Discord

Kuker

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Static libraries
« Reply #8 on: January 31, 2015, 09:16:28 pm »
Believe me, I've read it and I link all other libraries aswell and it still doesnt work. I don't know in what order should i type them to VS.

Gambit

  • Sr. Member
  • ****
  • Posts: 283
    • View Profile
Re: Static libraries
« Reply #9 on: January 31, 2015, 10:49:39 pm »
Why dont you try linking dynamically for now? If that works, then you know that you are doing something wrong when you are linking statically.

Kuker

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Static libraries
« Reply #10 on: February 01, 2015, 12:36:53 am »
I think the problem is solved, it wasn't the compiler fault, just an error in code. But now when i try to debug it, i get an Unhandled Exception about ntdll.dll. Got any idea what it causes? It pauses on the line "sf::RenderWindow window;". I'll add, that it compiles without any errors (except those of intellisense).

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Static libraries
« Reply #11 on: February 01, 2015, 12:41:32 am »
sfml-system-s, sfml-windows-s, sfml-graphics-s
Are you trying to compile in debug mode because these are the release versions.

Have you added the static definition to the preprocessor list (as per the VS tutorial)?

Does the same code compile fine with dynamic libraries?
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Kuker

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Static libraries
« Reply #12 on: February 01, 2015, 12:43:39 am »
Yes yes I've already fixed that. The code works and debugs with dynamic libraries, with static ones it compiles, but when i try to debug it stops as i mentioned above. I use correct libraries, -s-d for debug and -s for release, aswell as other libraries (winmm, opengl32 etc.) in "All Configurations".

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Static libraries
« Reply #13 on: February 01, 2015, 12:48:53 am »
It runs fine statically in release mode but not in debug mode?
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Kuker

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: Static libraries
« Reply #14 on: February 01, 2015, 12:50:16 am »
"The program has stopped working" - it says when i start it without debugging.

Problem solved: works ok when i declare sf::RenderWindow window in game.h, instead of putting it globally in game.cpp. Thanks guys for your help.
« Last Edit: February 01, 2015, 12:52:20 am by Kuker »