C++ 从命令行编译 Qt 项目

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19206462/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 22:36:25  来源:igfitidea点击:

Compile a Qt project from command Line

c++qtqt-creator

提问by roosevelt

I am developing a application using Qt, the C++ library/framework. Using the QT-Creator I can compile my project just fine and the build directory generates the desired executable files just fine. However, I am trying to automate my asks and using Apache ANT. But I am running into the following issues.

我正在使用 C++ 库/框架 Qt 开发应用程序。使用 QT-Creator 我可以很好地编译我的项目,并且构建目录可以很好地生成所需的可执行文件。但是,我正在尝试自动化我的问题并使用 Apache ANT。但我遇到了以下问题。

Here is the output from the command line:

这是命令行的输出:

build.mac.64:
     [echo] Building for Mac
     [echo] Updating destination path
     [exec] Project WARNING: No .qmake.cache is present. This significantly slows down qmake with this makespec.
     [exec] Project WARNING: Call 'cache()' in the top-level project file to rectify this problem.
     [exec] make: Nothing to be done for `first'.
     [exec] cp: ./build/mac.64/settings.ini: No such file or directory
     [exec] Result: 1
     [echo] Reverting destination path

I am not sure why it is not compiling the executable file.

我不确定为什么它不编译可执行文件。

Here is how my target looks like:

这是我的目标的样子:

<target name="build.mac.64">
    <echo>Building for Mac</echo>
    <exec executable="qmake">
        <arg value="myproject.pro"/>
        <arg
        value="-r"/>
        <arg value="-spec"/>
        <arg value="macx-clang"/>
        <arg value="CONFIG+=x86_64"/>
    </exec>

    <exec executable="make" />

    <exec executable="cp">
        <arg value="./settings.ini"/>
        <arg value="${default.build.dir.mac.64}/settings.ini"/>
    </exec>

</target>

Any idea where I am going wrong?

知道我哪里出错了吗?

回答by roosevelt

Thanks for the tips guys. I realized what I was doing wrong. QT-Creator actually takes the first two steps silently.

谢谢提醒伙计。我意识到我做错了什么。QT-Creator 实际上是默默地进行前两步。

  1. Create the build output directory
  2. CD to the build output directory (KEY STEP)
  3. Call qmake referencing the .pro file
  4. Call make
  1. 创建构建输出目录
  2. CD 到构建输出目录(关键步骤)
  3. 调用引用 .pro 文件的 qmake
  4. 呼叫使

So, the key thing that I overlooked was that you had to be in the build directory first and then call qmake, make etc... And also if the build already has the files compiled it throws that error. I just have to make sure I clean the build directory to compile everything fresh.

所以,我忽略的关键是你必须首先进入构建目录,然后调用 qmake、make 等......而且如果构建已经编译了文件,它会抛出该错误。我只需要确保我清理了构建目录以编译所有内容。

回答by Denis Shiryaev

In terminal window

在终端窗口

  1. cd ~/your_project_folder/
  2. qmake -project
  3. qmake
  4. make
  1. cd ~/your_project_folder/
  2. qmake -project
  3. qmake
  4. 制作

回答by kay

If compiling an existing project, qmake -project is actually wrong, see "qmake --help".

如果编译现有项目,qmake -project 实际上是错误的,请参阅“qmake --help”。

qmake -makefile
make

If its a large project, "make -j4" or similar.

如果它是一个大项目,“make -j4”或类似的。