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

Author Topic: Why do i need to include DLLs with .exe when linking with .lib?  (Read 7273 times)

0 Members and 1 Guest are viewing this topic.

nicedude80

  • Newbie
  • *
  • Posts: 22
    • View Profile
Why do i need to include DLLs with .exe when linking with .lib?
« on: January 02, 2014, 01:12:27 am »
I am setting up vs2012 with SFML 2.1 and i have entered everything correctly but when i compile/build/run it says that i am missing a dll? I thought that when you link statically it just inlcudes the .libs inside the .exe, without you having to redistribute any dlls or anything. So what does that mean? I tried copying and pasting the dlls in the bin folder to the same directory as the .exe, but I am curious as to why I needed to include the dlls?

I hope I didnt do anything wrong. I am starting on a game, and I want to set everything up correctly for when I need to release it.

FRex

  • Hero Member
  • *****
  • Posts: 1845
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Why do i need to include DLLs with .exe when linking with .lib?
« Reply #1 on: January 02, 2014, 01:22:46 am »
For VS static libs have -s in their name, if they don't then the lib is just import lib that describes symbols inside dll and tells your exe(or dll or lib, depending on what you're making) to look for that dll with these symbols.
Back to C++ gamedev with SFML in May 2023

nicedude80

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Why do i need to include DLLs with .exe when linking with .lib?
« Reply #2 on: January 02, 2014, 01:24:51 am »
so instead of sfml-graphics-d.lib I would do sfml-graphics-d-s.lib? Or how do I find the proper spelling prefix?

Edit: I just found the spelling inside the lib folder. so I guess i just need to put a s- in front of the d.lib. Like this: sfml-graphics-s-d.lib, right?
« Last Edit: January 02, 2014, 01:26:42 am by nicedude80 »

FRex

  • Hero Member
  • *****
  • Posts: 1845
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Why do i need to include DLLs with .exe when linking with .lib?
« Reply #3 on: January 02, 2014, 01:25:56 am »
It's a suffix and it's described in the VS tutorial, just below the red box(second one) in the middle of text: http://www.sfml-dev.org/tutorials/2.1/start-vc.php
Back to C++ gamedev with SFML in May 2023

nicedude80

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Why do i need to include DLLs with .exe when linking with .lib?
« Reply #4 on: January 02, 2014, 01:27:55 am »
Ohhhh I see! Thanks! So I also have to do that SFML_STATIC thing too.

nicedude80

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Why do i need to include DLLs with .exe when linking with .lib?
« Reply #5 on: January 02, 2014, 01:30:51 am »
So, the way that i have it setup now is linking dynamically, even though I had to show the compilker where the /lib folder was? I don't really understand that. Besides that, is the way that I have it setup now ok? It just means that the program is linked dynamically and I need to include the .dlls? Or is the way that I am doing this not the right way to link dynamically? sorry for all the questions.

FRex

  • Hero Member
  • *****
  • Posts: 1845
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Why do i need to include DLLs with .exe when linking with .lib?
« Reply #6 on: January 02, 2014, 01:43:40 am »
Quote
SFML_STATIC thing too.
Yes, but you might also need to add variable or few to additional dependencies field(I think.. I stopped using VS long before this change to SFML), see: http://en.sfml-dev.org/forums/index.php?topic=9362.msg94331#msg94331

Quote
It just means that the program is linked dynamically and I need to include the .dlls?
Yes. You also always need two dlls for audio besides SFML because of licensing terms they are under.

Quote
where the /lib folder was
Linker needs to know where to find the lib files to link them into exe, then exe will look around itself for the dll files using the information that was in lib files(that's why they are needed when building the exe) when it's launched.

Quote
Or is the way that I am doing this not the right way to link dynamically?
As long as you don't mix debug and release files it is the right way to link dynamically for VS.

Also take everything with a bit of scepticism, I oversimplified some things and I know really little about inner workings of VS, lib and dll contents and structure etc. but enough to be fairly sure how you linked is right way to link dynamically.
« Last Edit: January 02, 2014, 01:47:01 am by FRex »
Back to C++ gamedev with SFML in May 2023

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10827
    • View Profile
    • development blog
    • Email
Re: Why do i need to include DLLs with .exe when linking with .lib?
« Reply #7 on: January 02, 2014, 01:49:17 am »
Usually if one doesn't understand a certain topic, one would go and find some resources on said topic, instead of waiting for others to write all their knowledge again and again. ;)

Object files are compiled but not yet linked together code parts.
Static libraries are essentially just an archive of object files.
If you link your application against a static libraries, the library object files will get linked at the same time as your own application object files.

Shared libraries are already fully linked binaries. On Windows you however need an import library that tells the compiler what to expect in the DLL (= shared library).

So with SFML you get:
sfml-XYZ-s.lib = static release library
sfml-XYZ-s-d.lib = static debug library

sfml-XYZ.lib = import release library
sfml-XYZ.dll = dynamic release library
sfml-XYZ-d.lib = import debug library
sfml-XYZ-d.dll = dynamic debug library

I hope that cleared it up a bit. If you still have no idea about this whole compiling and linking stuff, then I suggest you reading some more information, maybe start off with this?

Note: For GCC based compilers (e.g. MinGW) (and NOT Visual Studio), the file endings for static and import libraries are *.a
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

nicedude80

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Why do i need to include DLLs with .exe when linking with .lib?
« Reply #8 on: January 02, 2014, 02:32:53 am »
I hope you dont mind me asking one more question. So in Linker > Input > Additional Dependencies, I want to link dynamically, and I have put all the sfml-audio-d.lib files, do I need to put the .dll extension in this section if I am linking dynamically or will the way I have it be linking dynamically? I think I understand, visual studio is very complicated, so  to link statically I use sfml-audio-s-d.lib and to link dynamically I use sfml-audio-d.lib in the Linker > Input > Additional Dependencies section? I wish libraries weren't so confusing. Thanks for your help!

FRex

  • Hero Member
  • *****
  • Posts: 1845
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Why do i need to include DLLs with .exe when linking with .lib?
« Reply #9 on: January 02, 2014, 03:34:33 am »
Quote
will the way I have it be linking dynamically?
It depends only on SFML_STATIC preprocessor definition and lib files you link(as stated in VS tutorial).

You put lib names with -s suffix, define SFML_STATIC and you then don't need dlls(except for audio module libsnd and OpenAL that are always dlls and get pulled in by both static and dynamic audio).

You put lib names without -s suffix and then you need to put dlls near the exe for launching it.

You never put dll names(like sfml-audio-d.dll) into that field. Also if there are names without -s when SFML_STATIC is defined or if SFML_STATIC is not defined and you use lib names with -s then you'll most likely get really weird sounding errors from linker.
Back to C++ gamedev with SFML in May 2023