简体   繁体   English

如何使Qt生成的makefile没有qmake依赖

[英]How to make makefile generated by Qt without qmake dependency

I use Qt creator in linux to make my non-Qt c++ project. 我在Linux中使用Qt Creator创建非Qt c ++项目。 I find that Qt creator would make a makefile for me. 我发现Qt创建者会为我创建一个makefile。 I want to move all the project into a computer without any qt or qmake, but I cannot really edit the makefile myself. 我想将所有项目移到没有任何qt或qmake的计算机中,但是我自己不能真正编辑makefile。 As I google that someone says add a CONFIG -= qt flag can make a pure g++ makefile without any qt component but actually not. 正如我在Google上搜索到的那样,有人说添加CONFIG-= qt标志可以创建没有任何qt组件的纯g ++ makefile,但实际上不能。

the pro file in my project is like this: 我项目中的pro文件是这样的:

QMAKE_LFLAGS += -no-pie
TEMPLATE = app
CONFIG += console c++11
CONFIG -= app_bundle
CONFIG -= qt
INCLUDEPATH += /home/MyName/opencvBuild/install/include/opencv4/
LIBS += -L/home/MyName/opencvBuild/install/lib/ \
        -lopencv_core \

SOURCES += \
        main.cpp \
    helloopencv.cpp

HEADERS += \
    helloopencv.hpp

and the makefile generate thousands of Qt dependencies like: 并且makefile生成数千个Qt依赖项,例如:

.....
###### Files

SOURCES       = ../HelloOpenCV/main.cpp \
        ../HelloOpenCV/helloopencv.cpp 
OBJECTS       = main.o \
        helloopencv.o
DIST          = ../Qt/5.12.0/gcc_64/mkspecs/features/spec_pre.prf \
        ../Qt/5.12.0/gcc_64/mkspecs/common/unix.conf \
        ../Qt/5.12.0/gcc_64/mkspecs/common/linux.conf \
        ../Qt/5.12.0/gcc_64/mkspecs/common/sanitize.conf \
        ../Qt/5.12.0/gcc_64/mkspecs/common/gcc-base.conf \
.....

now when I call make command in terminal it would automatically link to qmake. 现在,当我在终端中调用make命令时,它将自动链接到qmake。 I don't want any "Qt" in my makefile. 我的makefile文件中不需要任何“ Qt”。 What should I do? 我该怎么办?

These are not "Qt"-dependencies, but rather "qmake"-dependencies: it's a list of files which qmake had processed in order to generate your Makefile. 这些不是“ Qt”依赖关系,而是“ qmake”依赖关系:这是qmake为了生成Makefile而已处理的文件列表。 Stuff like gcc-base.conf is needed for some common gcc options, sanitize.conf for a bunch of -fsanitize= options, and so on. 一些常见的gcc选项需要gcc-base.conf类的东西,一堆-fsanitize=选项需要sanitize.conf之类的-fsanitize= ,依此类推。

Thus, it's the list of the files your Makefile itself depends on (used for auto-regeneration and such). 因此,这是Makefile本身依赖的文件列表(用于自动重新生成等)。 Of course, if you don't intend to ever regenerate Makefile with the help of qmake, you can just delete all these lines at once. 当然,如果您不想在qmake的帮助下重新生成Makefile,则可以一次删除所有这些行。

You complain that despite of having CONFIG-=qt in your .pro, there is still a bunch of qt_config.prf and other such files mentioned in that list. 您抱怨说,尽管您的.pro中有CONFIG-=qt ,但该列表中仍然有一堆qt_config.prf和其他此类文件。 This is true, however qmake startup scripts designed precisely in this way: first, all Qt-related stuff is unconditionally preconfigured ; 的确如此,但是qmake启动脚本正是以这种方式设计的:首先,所有与Qt相关的内容都是无条件预配置的 then the user project is processed; 然后处理用户项目; and then, only if CONFIG += qt , the relevant Qt stuff finally becomes enabled. 然后,只有在CONFIG += qt ,相关的Qt东西才最终启用。

Just for fun, you can mess with qmake startup code: go to <prefix>/share/qt5/mkspecs/linux-g++-64 (or whatever your QMAKE_SPEC is); 只是为了好玩,您可以将qmake启动代码弄乱:转到<prefix>/share/qt5/mkspecs/linux-g++-64 (或任何QMAKE_SPEC是); open the file qmake.conf ; 打开文件qmake.conf comment out the last string: #load(qt_config) . 注释掉最后一个字符串: #load(qt_config) Now your CONFIG -= qt project should be processed okay, but the resulting Makefile will be significantly smaller. 现在应该可以正确处理您的CONFIG -= qt项目,但是生成的Makefile将大大缩小。 But the price is that qmake cannot do Qt-enabled projects anymore (well, in fact, you can add load(qt_config) on top of your .pro file and it may even work - no warranties of any kind, of course ;-). 但是代价是qmake不能再执行启用Qt的项目(嗯,事实上,您可以在.pro文件的顶部添加load(qt_config) ,它甚至可以工作-当然,没有任何形式的保证;-) 。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM