Cannot run qmake in Mac Terminal

时光怂恿深爱的人放手 提交于 2019-12-22 03:25:20

问题


I'm learning Qt for my C++ course at college. I am trying to set up the environment for my first assignment but I can't seem to get it right. I swear I have run qmake in the terminal before, but now since I installed Qt 5.2 with Qt Creator I can't create the projects in the terminal.

None of the commands are recognised and on top of that if I try to compile a standard C++ file with

#include <QtGui>

the compiler won't find it. The g++ compiler that I'm using will not find any of the Qt Libraries that I try to import. I looked online and the solution I found was just to run

brew install qt

in Terminal and hope that it sorts itself out, although the terminal throws an error and won't install it once it's downloaded. I really need to get this working for my assignment.

Any help would be greatly appreciated. Thanks in advance!

* EDIT *

Okay so I added the qmake bin into my PATH variable. This was the path:

/Users/#####/Qt5.2.1/5.2.1/clang_64/bin

The problem is that now nothing in my C++ source files are being recognized. None of the imports like QString or QTextStream or QtGui, etc. What can cause this?


回答1:


Did you set the environment variable PATH with the path to Qt?

in Terminal do: echo $PATH and look for something like /usr/local/Qt-5.x.x/bin:PATH

If there is not any path to your installed qt, set it like this:

In .profile (if your shell is bash), add the following lines:

PATH=/usr/local/Qt-5.0.2/bin:$PATH
export PATH

To help you in the process you probably would like to read here: QT mac install

ANSWER TO NEW QUESTION

If writing code nothing seems to be recognized you should add the link to your include directory. The include directory is where there are all the header file, so your IDE can give you suggestion about class method etc...




回答2:


It is generally not needed at all to touch the PATH on any system (Mac, Unix, Windows) merely to use Qt. You may have multiple Qt versions installed in parallel (say 4.8 from macports, 5.2, git stable, etc.).

A way of building a Qt project on Unix is (substitute relevant paths for your setup):

mkdir ~/build-dir
cd ~/build-dir
~/Qt5.2.1/5.2.1/clang_64/bin/qmake ~/src/myproject/myproject.pro
make -j2
# were N in -jN is the number of CPU cores on your system



回答3:


The reason why you cannot execute the program is because it's not in the $PATH of the shell you are using. First find where it is located and then add the directory to that binary directory to your $PATH environment variable. Then you'll be able to execute it in your terminal.

For instance, if you are using ZSH and your program resides in "/opt/local/bin" then execute the following to make it available through $PATH:

export PATH=$PATH:/opt/local/bin

After this point you would be able to run the program. And you should add this to your shell RC file.




回答4:


If you've installed the Qt SDK then the path of qmake is not automatically included as an environment variable, so you have to do it manually. This is also true in windows. I found this weird. It should be included automatically unless there is a sensible reason behind it.




回答5:


For me, I realised that the .bashrc file was not getting autoloaded on a new terminal session after adding the qmake PATH to the file (using echo 'export PATH="$(brew --prefix qt@5.5)/bin:$PATH"' >> ~/.bashrc).

So I simply run source ~/.bashrc and bam! It worked!



来源:https://stackoverflow.com/questions/22116608/cannot-run-qmake-in-mac-terminal

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!