Search code examples
qtlinkerqmakeobject-files

QMake OBJECTS issue after clean


I have a precompiled object file, say myObjectFile.o. Inside my .pro file I have a block of code like this:

mac {
    ...
    OBJECTS += myObjectFile.o
}

This works great for linking in the object file with the rest of the project, but there is a fatal issue. If I do a clean this object file gets deleted. And since it's precompiled, when I try to build again I get a linking error until I copy the file back into my projects directory (I actually have a system call in my .pro file to copy the file so I just run qmake again).

This problem is annoying and causes some issues with our continuous integration server. Basically, I'm looking for a way I can link precompiled object files into my code.


Solution

  • You do this by adding the object files in LIBS rather than OBJECTS:

    mac {
        ...
        LIBS += myObjectFile.o
    }
    

    The contents of LIBS are passed to the linker as-is, which makes it possible to include object files in it.