Search code examples
c++qtqmake

Qt - Set the output path of .o file


Here's the structure of the folder:

TEST
|-- DIR1
|   |-- TEST1.cpp
|   `-- TEST1.h
|-- DIR2
|   |-- TEST2.cpp
|   `-- TEST2.h
`-- main.cpp

After qmake -project, qmake TEST.pro, make, I got:

TEST
|-- DIR1
|   |-- TEST1.cpp
|   `-- TEST1.h
|-- DIR2
|   |-- TEST2.cpp
|   `-- TEST2.h
|-- Makefile
|-- TEST
|-- TEST.pro 
|-- TEST1.o
|-- TEST2.o
|-- main.cpp
`-- main.o

I want to specify the output path of the .o file generated from .cpp file and put .o file in the same folder of its .cpp file, like:

TEST
|-- DIR1
|   |-- TEST1.cpp
|   |-- TEST1.o
|   `-- TEST1.h
|-- DIR2
|   |-- TEST2.cpp
|   |-- TEST2.o
|   `-- TEST2.h
|-- Makefile
|-- TEST
|-- TEST.pro
|-- main.cpp
`-- main.o

Solution

  • qmake puts all object files in one directory and you cant change it. But you can add this line to your .pro file

    OBJECTS_DIR = .obj
    

    Then it will create a directory named obj and put all object files there.