gccmakefileasmjit

gcc -D option not doing what I thought it would


I'm trying to use AsmJit in a project. This is the makefile I was using:

CC = g++
CFLAGS = -D ASMJIT_API -I dep/

test: src/main.cpp
        $(CC) $(CFLAGS) src/main.cpp -o test.exe

I was getting compiler errors when trying this, so instead I uncommented the line #define ASMJIT_API from dep/AsmJit/Config.h, and removed the -D switch from the makefile and everything compiled cleanly. I'm using gcc 4.5.3. Any ideas?

Thanks.

EDIT: Compiler Errors

g++ -DASMJIT_API -Idep/ src/main.cpp -o test.exe
In file included from dep/AsmJit/Assembler.h:31:0,
                 from src/main.cpp:1:
dep/AsmJit/Build.h:274:1: error: expected unqualified-id before numeric constant
In file included from dep/AsmJit/AssemblerX86X64.h:36:0,
                 from dep/AsmJit/Assembler.h:51,
                 from src/main.cpp:1:
dep/AsmJit/Defs.h:408:1: error: expected unqualified-id before numeric constant
In file included from dep/AsmJit/DefsX86X64.h:36:0,
                 from dep/AsmJit/Defs.h:423,
                 from dep/AsmJit/AssemblerX86X64.h:36,
                 from dep/AsmJit/Assembler.h:51,
                 from src/main.cpp:1:
dep/AsmJit/Util.h:412:8: error: expected identifier before numeric constant
dep/AsmJit/Util.h:412:8: error: expected unqualified-id before numeric constant
src/main.cpp:6:1: error: expected ‘}’ at end of input
makefile:5: recipe for target `test' failed
make: *** [test] Error 1

Solution

  • There is a difference between #define ASMJIT_API and -DASMJIT_API.

    The #define statement defines ASMJIT_API as nothing, while the -D flag defines the preprocessor constant as 1.

    Using the -D flag, line 274 of build.h expands to

    1 void assertionFailure(const char* file, int line, const char* exp);
    

    causing the compiler error.