Search code examples
gcclinkersdlcodeblockslinker-flags

Code::Blocks Linking Options


I was setting up SDL in Code::Blocks 17.12, using MinGW on Windows, and I saw a weird set of options for the linker. I'm new to this, so it could be obvious. Load up a project, go into the Project tab at the top, click on Properties, then click on Project's build options. If you click on Linker settings, you'll find two things. One contains a list of libraries to link, while the other contains a list of options given to the linker in the command itself. Here's a screenshot of what the window looks like: Code::Blocks Linker Options

What I found is that removing the link libraries doesn't mess up the build at all, while removing the linker options messes up everything. Is this something that only happens with SDL? What's the difference between these two sections? What do these flags tell the linker to do?


Solution

  • Okay, this was a pretty simple mistake. After doing some research, I found this post on the forums explaining the problem. The libraries have to be loaded in the exact same order! To answer my first question, SDL does have some weirdness, but this problem can happen with any set of library files. Second, these two sections are basically exactly the same when it comes to linking static library files, but the linker options give you more control and let you specify other flags that the linker might use. Finally, these flags tell the linker to look into the directories provided and embed them into your program, allowing you to use the functionality present in the library in your final executable.

    Here's an image showing what I did. Using the same specs as previously provided, the build ran perfectly, and I was successfully able to run the final program. The library names are provided in the exact same order as they were in the linker options