简体   繁体   English

gcc -D选项没有做我想的那样

[英]gcc -D option not doing what I thought it would

I'm trying to use AsmJit in a project. 我正在尝试在项目中使用AsmJit。 This is the makefile I was using: 这是我使用的makefile:

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. 我在尝试这个时遇到编译器错误,所以我从dep / AsmJit / Config.h取消注释#define ASMJIT_API行,并从makefile中删除了-D开关,干净地编译了所有内容。 I'm using gcc 4.5.3. 我正在使用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

There is a difference between #define ASMJIT_API and -DASMJIT_API . #define ASMJIT_API-DASMJIT_API之间存在差异。

The #define statement defines ASMJIT_API as nothing, while the -D flag defines the preprocessor constant as 1 . #define语句将ASMJIT_API定义为ASMJIT_API ,而-D标志将预处理器常量定义为1

Using the -D flag, line 274 of build.h expands to 使用-D标志,build.h的第274行扩展为

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

causing the compiler error. 导致编译器错误。

Don't insert a space between -D and ASMJIT_API. 不要在-D和ASMJIT_API之间插入空格。 Ditto for -I 同上-I

CFLAGS = -DASMJIT_API -Idep/

There you go. 你去吧

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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