How to create a qt 5 project on mac

I am trying to create a simple Qt 5 program on a Mac. But I failed.

The code is very simple:

#include <QtWidgets/QApplication> int main(int argc, char *argv[]) { QApplication app (argc, argv); return app.exec(); } 

I used:

 clang++ -I ~/Qt5.0.0/5.0.0/clang_64/include -L/Users/crazylion/Qt5.0.0/5.0.0/clang_64/lib test.cpp 

Then I got this error:

 Undefined symbols for architecture x86_64: "QApplication::exec()", referenced from: _main in test-jPGORy.o "QApplication::QApplication(int&, char**, int)", referenced from: _main in test-jPGORy.o "QApplication::~QApplication()", referenced from: _main in test-jPGORy.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) 

Is there something I don't see?

+1
source share
3 answers

First, do not compile or link Qt projects manually; use qmake and project files.

Run qmake -project in the source directory to create the base project file.

Edit the project file and add the following line: QT += widgets

Now run qmake to generate the makefile.

Now run make to create your program.

Secondly, you can simply #include <QApplication>

+1
source

If you want to use clang ++ in favor of qmake, you need to specify the libraries to link against, along with the library directory (which you provided).

 clang++ -I ~/Qt5.0.0/5.0.0/clang_64/include -L/Users/crazylion/Qt5.0.0/5.0.0/clang_64/lib -lQtCore -lQtGui test.cpp 
+1
source

I had the same problems and it seems to me that there is some kind of error in the release. This gave me some errors, because from the new installation (using the qt creator) I did not have some obscure qt library (not ordinary qt5 modules, but some kind of library in development), so I tend to think that this may be qt problem

I have a few questions to better understand:

- do you use an IDE?

- if you use the one that is?

- Do you include all modules in * .pro for an earthquake?

- If you used version 4.8, did you encounter these problems?

PS if you don’t have any special need, I suggest you stick with version 4.8 for some time (as I do without problems), since 5.0 has just been released

0
source

Source: https://habr.com/ru/post/1493328/


All Articles