qmake工具生成项目文件与Makefile文件

news/2024/7/7 15:39:21

qmake

是一个协助简化跨平台进行专案开发的构建过程的工具程式,也是Qt附带工具之一。可以根据项目环境构建.pro项目文件,再根据项目文件生成Makefile文件。相对于手写一个项目Makefile来说,使用qmake生成Makefile比较简便。

查看qmake

Ubuntu下已经安装好Qt

qmake -v

可能会出现错误

qmake: could not exec ‘/usr/lib/x86_64-linux-gnu/qt4/bin/qmake’: No such file or directory

是因为在/usr/lib/x86_64-linux-gnu/qt4/bin/qmake这个目录下没有qmake程式文件。
找到路径:/usr/lib/x86_64-linux-gnu/qt-default/qtchooser

vim default.conf

将第一行:/usr/lib/x86_64-linux-gnu/qt4/bin/qmake改成自己Qt安装的路径/opt/Qt5.5.0/5.5/gcc_64/bin
再执行

qmake -v

可以看到qt版本。

查看qmake帮助文档

qmake - h
Usage: /opt/Qt5.5.0/5.5/gcc_64/bin/qmake [mode] [options] [files]

QMake has two modes, one mode for generating project files based on
some heuristics, and the other for generating makefiles. Normally you
shouldn't need to specify a mode, as makefile generation is the default
mode for qmake, but you may use this to test qmake on an existing project

Mode:
  -project       Put qmake into project file generation mode
                 In this mode qmake interprets files as files to
                 be built,
                 defaults to *; *; *; *.ts; *.xlf; *.qrc
                 Note: The created .pro file probably will 
                 need to be edited. For example add the QT variable to 
                 specify what modules are required.
  -makefile      Put qmake into makefile generation mode (default)
                 In this mode qmake interprets files as project files to
                 be processed, if skipped qmake will try to find a project
                 file in your current working directory

Warnings Options:
  -Wnone         Turn off all warnings; specific ones may be re-enabled by
                 later -W options
  -Wall          Turn on all warnings
  -Wparser       Turn on parser warnings
  -Wlogic        Turn on logic warnings (on by default)
  -Wdeprecated   Turn on deprecation warnings (on by default)

Options:
   * You can place any variable assignment in options and it will be     *
   * processed as if it was in [files]. These assignments will be parsed *
   * before [files].                                                     *
  -o file        Write output to file
  -d             Increase debug level
  -t templ       Overrides TEMPLATE as templ
  -tp prefix     Overrides TEMPLATE so that prefix is prefixed into the value
  -help          This help
  -v             Version information
  -after         All variable assignments after this will be
                 parsed after [files]
  -norecursive   Don't do a recursive search
  -recursive     Do a recursive search
  -set <prop> <value> Set persistent property
  -unset <prop>  Unset persistent property
  -query <prop>  Query persistent property. Show all if <prop> is empty.
  -cache file    Use file as cache           [makefile mode only]
  -spec spec     Use spec as QMAKESPEC       [makefile mode only]
  -nocache       Don't use a cache file      [makefile mode only]
  -nodepend      Don't generate dependencies [makefile mode only]
  -nomoc         Don't generate moc targets  [makefile mode only]
  -nopwd         Don't look for files in pwd [project mode only]

qmake语法

qmake [mode] [options] [files]

模式有两种:
-project:根据工程生成.pro项目文件。
-makefile:根据.pro项目文件生成makefile文件。

qmake生成makefile文件简单测试

创建一个test工程目录,目录下有三个目录分别是:a,b,m;a目录下有a.c,a.h;b目录下有b.c,b.h;m目录下有main.c。
在这里插入图片描述

a.c

#include <stdio.h>
#include "a.h"
int a(void)
{
        printf("call a!\n");
        return 0;
}

a.h

#ifndef _A_H
#define _A_H
int a(void);
#endif

b.c

#include <stdio.h>
#include "b.h"

int b(void)
{
        printf("call b!\n");
        return 0;
}

b.h

#ifndef _B_H
#define _B_H
int b(void);
#endif

main.c

#include <stdio.h>
#include "../a/a.h"
#include "../b/b.h"
int main(int argc, char ** argv)
{
        if(argc > 1){
                printf("%s\n",argv[1]);
        }
        printf("hello, linux world!\n");
        a();
        b();
        return 0;
}

在test目录下生成.pro

qmake -project

在这里插入图片描述
生成Makefile

qmake -makefile test.pro -o Makefile

在这里插入图片描述
make生成执行文件
在这里插入图片描述


http://www.niftyadmin.cn/n/2210912.html

相关文章

谈谈对Canal(增量数据订阅与消费)的理解

概述 canal是阿里巴巴旗下的一款开源项目&#xff0c;纯Java开发。基于数据库增量日志解析&#xff0c;提供增量数据订阅&消费&#xff0c;目前主要支持了mysql&#xff08;也支持mariaDB&#xff09;。 起源&#xff1a;早期&#xff0c;阿里巴巴B2B公司因为存在杭州和美国…

【noi 2.6_666】放苹果 【noi 2.6_8467】鸣人的影分身(DP)

这题其实在2.6前面的专题也有出现过&#xff0c;我还以为我有写&#xff0c;结果发现&#xff0c;并没有。于是就现在写了。这2题其实重复了......我就按放苹果的来说。 题意&#xff1a;把N个苹果放在M个盘子里&#xff0c;允许有的盘子空着不放&#xff0c;问共有多少种不同的…

php 随机在文章中添加锚文本_原创文章SEO技巧——嘉定行吟科技

一、网站内容关键词的选定是根据自动分词许多SEO优化人员&#xff0c;对于网站页面内容的选择大多都是在关键词标签中出现的&#xff0c;但实际上这是一种错误的方法&#xff0c;其中一些只是优化人员的主观看法&#xff0c;没有从搜索引擎的规则上考虑&#xff0c;如果优化人员…

mysql中的(null)_mysql中的NULL

[mysql - rootlocalhosttestmysql.sock 23:44:48] >select * from a;------------ --------------a表中包含a&#xff0c;c&#xff0c;无NULL| a | c |------------| 2 | 1 || 3 | 1 || 1 | 2 |------------3 rows in set (0.00 sec)[mysql - rootlocalhosttestmysql.sock …

SMTP基本电子邮件发送协议原理

1.电子邮件发送客户端发送给服务器端&#xff0c;postfix软件提供MTA,MDA.MTA 提供SMTP服务&#xff0c;接受邮件(读取DNS的MX记录)--》保存MDA 传送邮件MUA 用户代理 1-1服务器使用SMTP协议将电子邮件提交至TCP端口25,或由本地客户端通过 /usr/bin/sendmail程序进行提交。如…

Qt执行出现:can‘t resolve symbol ‘_ZN15lanStatusWidgetC1EP7QWidget‘

can’t resolve symbol这种问题是&#xff1a;编译过了&#xff0c;但是dvr424识别不了.so里面的_ZN15lanStatusWidgetC1EP7QWidget这个东西&#xff0c;说明你dvr424和.so不是同一个版本。 解决&#xff1a;重新编译整个工程。

android 访问服务器sql_1.sql注入基础

1.1 前言从本节开始&#xff0c;讲开始第二章web漏洞原理篇的讲解。首先带给大家的是sql注入漏洞。sql注入漏洞是web层面最高危的漏洞之一。2008年至2018年期间&#xff0c;sql注入漏洞连续三年位于owasp漏洞排行榜中的第一名。1.2 免责声明该课程中涉及的技术只适合于CTF比赛…

Ubuntu16.04网络配置(ping不通baidu.com与Ping网关Destination Host Unreachable错误)

打开虚拟机编辑&#xff0c;选择虚拟网络编辑器。 选择更改设置 如果之前没有VMnet网络&#xff0c;点击添加网络&#xff0c;选择桥接模式&#xff0c;确定。 左击”虚拟机“选择“网络适配器”。 选择桥接模式。 点击联网。 手动配置网络 ifconfig ens33 192.168.xxx.…