简体   繁体   中英

How to make makefile generated by Qt without qmake dependency

I use Qt creator in linux to make my non-Qt c++ project. I find that Qt creator would make a makefile for me. I want to move all the project into a computer without any qt or qmake, but I cannot really edit the makefile myself. As I google that someone says add a CONFIG -= qt flag can make a pure g++ makefile without any qt component but actually not.

the pro file in my project is like this:

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:

.....
###### 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. I don't want any "Qt" in my makefile. 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. Stuff like gcc-base.conf is needed for some common gcc options, sanitize.conf for a bunch of -fsanitize= options, and so on.

Thus, it's the list of the files your Makefile itself depends on (used for auto-regeneration and such). 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.

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. This is true, however qmake startup scripts designed precisely in this way: first, all Qt-related stuff is unconditionally preconfigured ; then the user project is processed; and then, only if CONFIG += qt , the relevant Qt stuff finally becomes enabled.

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); open the file qmake.conf ; comment out the last string: #load(qt_config) . Now your CONFIG -= qt project should be processed okay, but the resulting Makefile will be significantly smaller. 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 ;-).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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