Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: How to compile qt4 source from the terminal.

  1. #1
    Join Date
    Dec 2007
    Location
    CDO, Philippines
    Beans
    368
    Distro
    Kubuntu Jaunty Jackalope (testing)

    How to compile qt4 source from the terminal.

    i just started stduying qt4/c++. now i made a very basic app using qdevelop and i noticed it has generated three files: 2 .cpp files and one .h file in the source folder. my question is, how do i compile them using command "g++ xxx.cpp -o xxx -Wall -0"? i have tried compiling a single .ccp file for one program but not those with multiple .cpp files. how will i do it?

    thanks

  2. #2
    Join Date
    Apr 2007
    Beans
    14,781

    Re: How to compile qt4 source from the terminal.

    Quote Originally Posted by adredz View Post
    i just started stduying qt4/c++. now i made a very basic app using qdevelop and i noticed it has generated three files: 2 .cpp files and one .h file in the source folder. my question is, how do i compile them using command "g++ xxx.cpp -o xxx -Wall -0"? i have tried compiling a single .ccp file for one program but not those with multiple .cpp files. how will i do it?

    thanks
    You just do
    Code:
    g++ source.cpp source2.cpp
    But you'll have to link them to the qt libs.

  3. #3
    Join Date
    Apr 2005
    Location
    Finland
    Beans
    272

    Re: How to compile qt4 source from the terminal.

    Quote Originally Posted by LaRoza View Post
    You just do
    Code:
    g++ source.cpp source2.cpp
    But you'll have to link them to the qt libs.
    Just linking to the Qt libs isn't usually enough because the code first has to be converted to standard C++ by the Meta-Object Compiler. The painless way to compile Qt apps is to create a project file, run qmake (which creates the necessary C++ code and a platform-specific makefile), and then run make.

  4. #4
    Join Date
    Feb 2008
    Beans
    785
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: How to compile qt4 source from the terminal.

    what includes (Qt related ones) did you use in your project?

  5. #5
    Join Date
    Aug 2007
    Beans
    33

    Re: How to compile qt4 source from the terminal.

    Typically, you'd go into the directory where the files are and...

    Code:
    qmake-qt4 -project   #creates the project for you automatically
    qmake                #generates the Makefile
    make                 #compiles the code

  6. #6
    Join Date
    Jan 2008
    Location
    Toronto, Canada
    Beans
    70
    Distro
    Ubuntu 8.10 Intrepid Ibex

    Re: How to compile qt4 source from the terminal.

    I'm having a problem doing so..

    Here si an example from trolltech
    Code:
    #include <QApplication>
    #include <QPushButton>
    
    int main (int argc, char *argv[])
    {
            QApplication app(argc, argv);
    
            QPushButton hello ("Hello world!");
            hello.resize (100, 30);
    
            hello.show();
            return app.exec();
    }
    then i did:

    qmake-qt4 -project
    qmake
    make

    Which ended up with whole bunch of errors...,
    Code:
    alxlabs@alxlabs-laptop:~/hello_qt$ make
    gcc -c -pipe -g -Wall -W -D_REENTRANT -DQT_SHARED -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I. -I. -o hello.o hello.c
    In file included from /usr/include/qt4/QtCore/qobjectdefs.h:47,
                     from /usr/include/qt4/QtCore/qobject.h:49,
                     from /usr/include/qt4/QtCore/qcoreapplication.h:47,
                     from /usr/include/qt4/QtGui/qapplication.h:47,
                     from /usr/include/qt4/QtGui/QApplication:1,
                     from hello.c:1:
    /usr/include/qt4/QtCore/qnamespace.h:51: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘QT_MODULE’
    /usr/include/qt4/QtCore/qnamespace.h:1429: error: expected ‘)’ before ‘:’ token
    /usr/include/qt4/QtCore/qnamespace.h:1445: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘Q_CORE_EXPORT’
    In file included from /usr/include/qt4/QtCore/qobject.h:49,
                     from /usr/include/qt4/QtCore/qcoreapplication.h:47,
                     from /usr/include/qt4/QtGui/qapplication.h:47,
                     from /usr/include/qt4/QtGui/QApplication:1,
                     from hello.c:1:
    /usr/include/qt4/QtCore/qobjectdefs.h:49: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘QT_BEGIN_HEADER’
    /usr/include/qt4/QtCore/qobjectdefs.h:55: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘QByteArray’
    /usr/include/qt4/QtCore/qobjectdefs.h:138: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘<’ token
    /usr/include/qt4/QtCore/qobjectdefs.h:141: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘<’ token
    /usr/include/qt4/QtCore/qobjectdefs.h:214: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘QObject’
    /usr/include/qt4/QtCore/qobjectdefs.h:215: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘QMetaMethod’
    
    ..................

  7. #7
    Join Date
    Apr 2005
    Location
    Finland
    Beans
    272

    Re: How to compile qt4 source from the terminal.

    Quote Originally Posted by alxlabs View Post
    ...then i did:

    qmake-qt4 -project
    qmake
    make

    Which ended up with whole bunch of errors...,
    I'm guessing that's because you named your source file hello.c, even though it's C++ code. Try renaming it hello.cpp and see what happens.

  8. #8
    Join Date
    Jan 2008
    Location
    Toronto, Canada
    Beans
    70
    Distro
    Ubuntu 8.10 Intrepid Ibex

    Re: How to compile qt4 source from the terminal.

    Thanks Scourge, it worked...

  9. #9
    Join Date
    Dec 2007
    Location
    CDO, Philippines
    Beans
    368
    Distro
    Kubuntu Jaunty Jackalope (testing)

    Re: How to compile qt4 source from the terminal.

    wow that works! thanks to all!
    anyone know the equivalent commands for windows? the story is, i am making a little project in my *buntu box but i should be able to run it on windows as well cos in our school, all computers are "infected with M$". could you help me please..
    Last edited by adredz; July 15th, 2008 at 02:11 AM.

  10. #10
    Join Date
    Apr 2005
    Location
    Finland
    Beans
    272

    Re: How to compile qt4 source from the terminal.

    Quote Originally Posted by adredz View Post
    wow that works! thanks to all!
    anyone know the equivalent commands for windows? the story is, i am making a little project in my *buntu box but i should be able to run it on windows as well cos in our school, all computers are "infected with M$". could you help me please..
    The qmake commands are the same, and the project file is platform-independent, so you can use it also in Windows. The "make" part depends on the compiler/environment you're using. If you have the MinGW install of Qt, it's "mingw32-make", if you're using Visual Studio it's "nmake".

Page 1 of 2 12 LastLast

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
  •