Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Problem compiling Qt example from OS X terminal

    Tools
    3
    11
    6368
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • C
      CrazyFileMaker last edited by

      Hello,

      I'm currently learning Qt by working through examples in the ebook "C+ GUI Programming with Qt 4, Second Edition".

      The first example is a "Hello World" application. Following the steps in the example I've been able to create the following files:
      hello.cpp, by typing out the provided code.
      hello.pro, by using OS X Terminal command "qmake -project".
      hello.xcodeproj and info.plist by using command "qmake hello.pro"

      However, I am unable to create "hello.app"

      The command "make" yields:
      "make: *** No targets specified and no makefile found. Stop."

      The command "make hello" yields:
      g++ hello.cpp -o hello
      hello.cpp:1:24: error: QApplication: No such file or directory
      hello.cpp:2:18: error: QLabel: No such file or directory
      hello.cpp: In function ‘int main(int, char**)’:
      hello.cpp:6: error: ‘QApplication’ was not declared in this scope
      hello.cpp:6: error: expected ;' before ‘app’ hello.cpp:7: error: ‘QLabel’ was not declared in this scope hello.cpp:7: error: ‘label’ was not declared in this scope hello.cpp:7: error: expected type-specifier before ‘QLabel’ hello.cpp:7: error: expected ;' before ‘QLabel’
      hello.cpp:9: error: ‘app’ was not declared in this scope
      make: *** [hello] Error 1

      While I can't create "hello.app" from the terminal with these two commands, I can create it by simply opening Xcode and pressing the button "Build and Go".

      Can someone tell me why in the world these two commands don't work? And how I can make the "hello.app" from the terminal?

      Thanks!

      1 Reply Last reply Reply Quote 0
      • G
        goetz last edited by

        Your include paths are not set correctly. Can you paste the hello.pro and the hello.cpp here (use the @-Tags or the button to pretty format the code).

        http://www.catb.org/~esr/faqs/smart-questions.html

        1 Reply Last reply Reply Quote 0
        • C
          CrazyFileMaker last edited by

          The Following is the hello.pro
          @######################################################################

          Automatically generated by qmake (2.01a) Sat Nov 6 15:35:50 2010

          ######################################################################

          TEMPLATE = app
          TARGET =
          DEPENDPATH += .
          INCLUDEPATH += .

          Input

          SOURCES += hello.cpp@

          The following is the hello.cpp
          @#include <QApplication>
          #include <QLabel>

          int main(int argc, char *argv[])
          {
          QApplication app(argc, argv);
          QLabel *label = new QLabel("Hello Qt!");
          label->show();
          return app.exec();
          }
          @

          1 Reply Last reply Reply Quote 0
          • G
            goetz last edited by

            Your qmake seems to be setup to create XCode project files (that creates the file hello.xcodeproj). You should try

            @
            rm -rf hello.xcodeporj
            rm Info.plist

            qmake -spec macx-g++
            @

            That removes the XCode project files and creates a normal makefile for you.

            http://www.catb.org/~esr/faqs/smart-questions.html

            1 Reply Last reply Reply Quote 0
            • C
              CrazyFileMaker last edited by

              Worked perfectly! Thanks so much!

              1 Reply Last reply Reply Quote 0
              • G
                goetz last edited by

                You're welcome.

                Just for curiosity: How did you install Qt? The default mode for qmake is generating a makefile, not an xcode project, as far as I know.

                http://www.catb.org/~esr/faqs/smart-questions.html

                1 Reply Last reply Reply Quote 0
                • D
                  DenisKormalev last edited by

                  Volker, I've stucked with same problem when ported one of my projects to MacOSX. Qt was installed from package from qt ftp. I think that setting QMAKESPEC will help, but didn't try (always explicitly setted -spec param to qmake).

                  1 Reply Last reply Reply Quote 0
                  • G
                    goetz last edited by

                    Ah, I see. I've always compiled the libs manually, there the default is normal makefiles.

                    You can change the default: Go to the installation directory of Qt, enter the mkspecs directory and change the symbolic link default to macx-g++, that should work.

                    http://www.catb.org/~esr/faqs/smart-questions.html

                    1 Reply Last reply Reply Quote 0
                    • D
                      DenisKormalev last edited by

                      Volker, yeah, another good way :)

                      1 Reply Last reply Reply Quote 0
                      • G
                        goetz last edited by

                        Once in a while one forgets the -spec switch and gets the wrong proejct files :)

                        http://www.catb.org/~esr/faqs/smart-questions.html

                        1 Reply Last reply Reply Quote 0
                        • C
                          CrazyFileMaker last edited by

                          I installed Qt 4.7.0, Qt Creator 2.0.1, and Xcode Developer 3.1.3.

                          All of them were installed from disk images.

                          I didn't install any of them manually.

                          1 Reply Last reply Reply Quote 0
                          • First post
                            Last post