Understand Qt's g++ calls in QtCreator



  • In order to understand how Qt's file should be link with my application, I created the default Hello Word program in QtCreator and started to analyse g++'s calls. I understand everything except the following bold options :

    g++ -c -m64 -pipe -g -Wall -W -D_REENTRANT -fPIE -DQT_QML_DEBUG -DQT_DECLARATIVE_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I../../Qt5.0.1/5.0.1/gcc_64/mkspecs/linux-g++-64 -I../test4 -I../../Qt5.0.1/5.0.1/gcc_64/include -I../../Qt5.0.1/5.0.1/gcc_64/include/QtWidgets -I../../Qt5.0.1/5.0.1/gcc_64/include/QtGui -I../../Qt5.0.1/5.0.1/gcc_64/include/QtCore -I. -I. -I. -o moc_mainwindow.o moc_mainwindow.cpp

    Looking at gcc's man page, I can see it is for macros, but I still don't quite understand. Can someone explain this?

    Additionnaly, there is this :

    g++ -m64 -Wl,-rpath,/home/jp/Qt5.0.1/5.0.1/gcc_64 -Wl,-rpath,/home/jp/Qt5.0.1/5.0.1/gcc_64/lib -o test4 main.o mainwindow.o moc_mainwindow.o -L/usr/X11R6/lib64 -L/home/jp/Qt5.0.1/5.0.1/gcc_64/lib -lQt5Widgets -lQt5Gui -lQt5Core -lGL -lpthread

    Again, I understand it is related to the linker, but I don't understand those two options. I looked in gcc's man page and didn't the -r option. Where can I read about linker's options?


  • Moderators

    -DWHATEVER_SYMBOL is essentially the same as creating a header file that is included in each and every file and contains #define WHATEVER_SYMBOL 1

    -m64 tells the compiler to generate code for the x86-64 architecture

    -Wl passes following, comma separated, options to the linker

    -rpath (linker option) adds a dir to the runtime library search path

    You can find a list of all the params for the gcc compiler "here":http://gcc.gnu.org/onlinedocs/gcc/Invoking-GCC.html#Invoking-GCC
    As for the linker options, check the man pages of "ld" or take a look "here":http://ftp.gnu.org/old-gnu/Manuals/ld-2.9.1/html_node/ld_3.html


  • Moderators

    One nitpick: Creator does not call g++, it calls make which then in turn does everything necessary to generate the binaries (incl. calling make).



  • ""-DWHATEVER_SYMBOL is essentially the same as creating a header file that is included in each and every file and contains #define WHATEVER_SYMBOL 1""

    And what is the point of defining these symbols? Are they used after?

    Is it for example, if I had written in my code "#ifdef WHATEVER_SYMBOL .... #endif" ?


  • Moderators

    Well, they're obviously not just for fun there :)

    Yes, it's for "turning on/off" parts of code with ifdefs.
    For example you could to something like:
    @
    #ifdef _DEBUG
    #define printSome(x) printSomeDebuggingMessage(x);
    #else
    #define printSome(x)
    #endif
    @
    or
    @
    #ifdef SOME_FLAG
    static SomeType turnSomeFeatureOn( true );
    #else
    static SomeType turnSomeFeatureOn( false );
    #endif
    @

    Qt's names are pretty descriptive, like QT_QML_DEBUG turns on debugging of the QML module etc.. But if you're really curious you can just take Qt source and look those up.



  • Thank you! It is clear now!

    "" Well, they’re obviously not just for fun there :) ""

    It could have been. There is also "-I. -I. -I." in the g++ call which is obviously there just for fun. :)


  • Moderators

    More fun might be finding out where those -I.s actually come from :)
    The first one is for the configuration directory, eg. on windows with msvc compiler the first -I. becomes -I"release" or -I"debug". I guess without shadow building this would become -I. but I haven't checked.

    Don't know where the other two come from, but I'm not really that interested :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.