【问题标题】:gcc -D option not doing what I thought it wouldgcc -D 选项没有做我认为的事情
【发布时间】:2012-03-03 01:45:09
【问题描述】:

我正在尝试在项目中使用 AsmJit。这是我使用的makefile:

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

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

我在尝试此操作时遇到编译器错误,因此我取消了 dep/AsmJit/Config.h 中的 #define ASMJIT_API 行的注释,并从 makefile 中删除了 -D 开关,并且所有内容都编译干净了。我正在使用 gcc 4.5.3。有什么想法吗?

谢谢。

编辑:编译器错误

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

【问题讨论】:

  • 您遇到了哪些编译器错误?
  • 基本上是错误,表明某些东西没有正确定义。当设置#define ASMJIT_API 时,其他定义按预期工作。如果他们有帮助,我会编辑我的帖子以包含它们。
  • 是的,如果您发布更多代码会有所帮助。
  • 那么,dep/Asmjit/Build.h 第 274 行发生了什么?
  • ASMJIT_API void asertionFailure(const char* file, int line, const char* exp);

标签: gcc makefile asmjit


【解决方案1】:

#define ASMJIT_API-DASMJIT_API 之间存在差异。

#define 语句将 ASMJIT_API 定义为空,而 the -D flag defines the preprocessor constant as 1

使用-D 标志,build.h 的第 274 行扩展为

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

导致编译器错误。

【讨论】:

    【解决方案2】:

    不要在 -D 和 ASMJIT_API 之间插入空格。同上 -I

    CFLAGS = -DASMJIT_API -Idep/
    

    你去。

    【讨论】:

    • @kisplit - 当您键入“make test”时,您是否看到 -DASMJIT_API 作为生成的命令行的一部分?
    猜你喜欢
    • 1970-01-01
    • 2023-03-26
    • 1970-01-01
    • 1970-01-01
    • 2011-09-09
    • 2016-03-19
    • 1970-01-01
    • 1970-01-01
    • 2016-07-31
    相关资源
    最近更新 更多