Results 1 to 2 of 2

Thread: Seeking Info on Linkers

  1. #1
    Join Date
    Jun 2011
    Posts
    203
    Thanks
    7
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Seeking Info on Linkers

    I've been trying to figure out how linkers work but I can't find any good information on the topic. Does anyone have any good in depth info on the subject?

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,248
    Thanks
    304
    Thanked 868 Times in 855 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Seeking Info on Linkers

    Linkers basically work by taking each of the object code files that the compiler has produced, identifying all of the variables, classes, methods, etc. that haven't been defined in that file, and looking in all of the other object code files and libraries you have listed as linker inputs for definitions that match. If everything the linker needs gets found, then it produces an executable file. If it doesn't then you get a list of "unresolved reference" items.

    Different linkers work in different ways. In Microsoft's Visual C++, for example, you can list object code and library files in pretty much any order and the linker will figure it out. In other C++ toolchains (gcc for one, I think), you have to list files in order of dependence. For example, if library A depends on a function in library B, then you have to list A first and then B because the linker only brings in object code to satisfy the reference it knows about so far. If you list B then A since the linker hasn't seen A yet, it doesn't know about its dependence on B and won't bring those parts in.

    Think about making an apple pie. You need a pie crust and apple filling. The pie crust needs butter, flour, salt, ice water, and maybe a little sugar. The apple filling needs apples, more sugar, a little more flour, cinnamon, nutmeg, and maybe a few other spices. You, the baker, must link all of that together to make an apple pie. You know that flour and sugar are found in the pantry library, butter is in the refrigerator library, spices in the spice library, ice in the freezer library, and water in the sink library. Ice water depends on both ice and water. So you have to link all of those dependencies together in the right order to get your pie. If you are only allowed to visit each library once (as in gcc) then if you go to the pantry and pull out only sugar and flour for the crust and then put them back, you're stuck because when you want to make the filling you find you are missing sugar and flour, but the pantry library has already been processed and is gone. So you have to make sure you list both the crust and the filling before you list the pantry library. If you are a lucky Microsoft baker, all of the doors are still open and you can just reach in and grab the sugar again.

    If you google for "compilers and linkers" there are lots of good articles. If you google for "apple pie recipe" you'll find lots of them too.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. The following user says thank you to d_stranz for this useful post:

    Atomic_Sheep (15th December 2020)

Similar Threads

  1. Probably missing linkers
    By sliverTwist in forum Newbie
    Replies: 2
    Last Post: 28th February 2013, 00:08
  2. Seeking freelance Qt developer
    By ibalt0 in forum Jobs
    Replies: 1
    Last Post: 9th October 2012, 09:25
  3. Phonon MMS seeking
    By fessio in forum Qt Programming
    Replies: 0
    Last Post: 29th May 2009, 22:45
  4. QFile Seeking / Overwriting
    By tntcoda in forum Qt Programming
    Replies: 3
    Last Post: 13th November 2008, 20:02

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.