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

Author Topic: General Linker Questions  (Read 1262 times)

0 Members and 1 Guest are viewing this topic.

ShyRobbie

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
General Linker Questions
« on: April 23, 2020, 06:09:34 pm »
Hello!  I am really excited to be getting into C++ and so far SFML has made this so much more enjoyable.  I have a few general questions WRT linking that I could not find in the FAQs or on google that should be pretty simple.

I am running on Code::Blocks 20.03 on Windows 10 with MinGW 7.3.0 x64 (SEH)
SFML v2.5.1 as per the download page for CGG 7.3.0 MinGW (SEH) x64

I have had a little confusion about the linker settings because sometimes a project will compile and run just dandy, but if I create another project with identical project/build settings and even use the same code from the previous project in CB, it will throw compile errors.

1.  Is it common for Code Blocks not to run/execute the project/build settings if they were recently changed?  I feel like I have gone into that setting screen and configured it every possible way but it will throw the same error, regardless of what is linked or changed when I try to rebuild the project.
I figured out you have to rebuild the whole project for the linking settings to actually work.

2.  Is it okay to link to the dynamic libraries for the debug build, and the static libraries for the release build?  I was reading in another thread that you shouldn't link to both the dynamic and static libraries at the same time, but if they are configured to be completely separate for the debug and release build settings that shouldn't be an issue, correct?

For example, should the following settings work or do I need to link the the sfml-xxx-s-d libraries for the debug portion of the settings?
 
Project 1 -> SFML App -> Search Directories -> Compiler -> SFML\Include
                                                                      -> Linker     -> SFML\Lib
Debug -> Linker Settings
               sfml-graphics-d
               sfml-window-d
               sfml-system-d
               sfml-main-d

Release -> Linker Settings
               sfml-graphics-s
               freetype
               sfml-window-s
               opengl32
               gdi32
               sfml-system-s
               winmm
               sfml-main
             -> Compiler Settings -> #Defines -> SFML_STATIC
                                               -> compiler Flags -> -static

3.  When static linking, I am a little confused about the order of the dependencies.  sfml-graphics depends on sfml-windows which depends on sfml-system so you list them top to bottom in that order.  But when static linking, both sfml-window and sfml-system both depend on winmm.  Does this mean you should order winmm at the very bottom like:

sfml-window-s
sfml-system-s
winmm

Is it more clean to just order all sfml files at the top and all the other dependencies at the bottom?

4.  The SFML and Code::Blocks tutorial and the FAQ "How do I link SFML statically?" lists the dependencies as... 
sfml-window, sfml-graphics, sfml-audio, sfml-network, sfml-system... with their sub-dependencies. 

These are not showing the main modules in their proper order, correct? They should be audio, graphics, window, network, system? 


Thank you very much for any help!  I know these probably seem pretty n00b :) but I hope they make sense. Just trying to fully understand how all these things plug together.
« Last Edit: April 24, 2020, 07:57:21 pm by ShyRobbie »

Hapax

  • Hero Member
  • *****
  • Posts: 3351
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: General Linker Questions
« Reply #1 on: April 25, 2020, 01:05:13 am »
Hello!!! :)

2) Yes. Whether it is static or dynamic is completely dependant on the linker settings so if you have completely different settings for debug and release builds, they will link differently.

3) Your list in 2 looks good.
You could list all external dependencies after all the SFML since none of them depend on SFML.

4) The order in the table captioned "Dependencies" are in the correct order: graphics, window, audio, network, system.
Although, they can be re-arranged as long as their dependants are in the correct order.
Basically, graphics first, then window/audio/network in any order, then system.
However, as long as graphics/window/system are in the correct order, audio/network can go anywhere as long as it's before system (so they can go first if you want).
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

ShyRobbie

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Re: General Linker Questions
« Reply #2 on: April 25, 2020, 07:16:31 pm »
Thank you so much!  ;D

One more question I had is if sfml-main needs to be linked for any reason, either statically or dynamically?  I read in some tutorials online that you need to, but they might have been for an older version of SFML.

Additionally, in Code::Blocks it's super handy to map sfml\bin under the global compiler settings -> toolchain executables -> Additional paths, so when your testing a dynamic SFML project it doesn't need the .dll files in the \bin\debug folder of your project.  Is there a place under the project build settings where you can map sfml\bin when your working on a dynamically linked project so it doesn't need to be mapped under the global compiler settings?

It works if you map it under search directories -> linker along with sfml\lib but I feel like that isn't the proper place for this...

Thanks again for the clarification!!!  :)