Search code examples
mingwc-preprocessorpreprocessormingw32

How do I define preprocessor macros through MinGW make


I've been trying to build a make file I generate via qmake, and I've tried the following but they don't seem to work.

mingw32-make -j8 -DDEVELOP
mingw32-make -j8 -D DEVELOP

But both seem to fail with the former giving me:

mingw32-make: invalid option -- E
mingw32-make: invalid option -- V
mingw32-make: invalid option -- E

followed by the -help messege. And the second one begins compiling but then gets to mingw32-make: *** DEVELOP: No such file or directory. Stop. and stops, failing to build the exe.

I'm using GNU MAKE 4.2.1 which was installed along side QT.

I wouldn't want to define these from my project files or in C++ as they're unique to certain builds. How do I go about doing this?


Solution

  • GNU Make doesn't have a -D parameter. If you want to pass this to your compiler, you need to check the Makefile to see if there is a variable where you can add it to that is used when compiling. Usually this will be CFLAGS and/or CXXFLAGS.

    Sometimes you can do

    mingw32-make -j8 CXXFLAGS="-DDEVELOP"
    

    or if that doesn't work you could try like this

    mingw32-make -j8 CXX="g++ -DDEVELOP"
    

    In the worst case you will need to manually add -DDEVELOP to the Makefile where compilation is done (look for compilation flag -c or other flags like -O).