GCC Tips and Tricks

The GNU Compiler Collection is a great and free tool suite for creating native applications. But since it is not streamlined by a corporation, there are some quirks you need to understand, by example.

Linking Qt static libraries

Did you know that the linking order of static libraries in GCC matters a lot? Since the Qt5Widgets component depends on Qt5Core you need to put Qt5Core after Qt5Widgets in the Code::Blocks library inclusion list. Not doing so would result in many undefined reference errors.

Wrong: g++ -o ../output/program ../src/qt_main.cpp -lQt5Core -lQt5Gui -lQt5Widgets

Correct: g++ -o ../output/program ../src/qt_main.cpp -lQt5Widgets -lQt5Gui -lQt5Core

Thus if you could not link your Qt program statically try changing the linking order of your Qt (static) libraries.