繁体   English   中英

使用SCons定义C ++预处理器宏

[英]Defining C++ Preprocessor macros with SCons

我正在尝试在Scons中定义一个预处理器宏来构建一个更大的C / C ++项目。

我正在使用的其中一个库需要ALIGN定义。 更具体地说,如果我添加

#define ALIGN(x) __attribute((aligned(x)))

对于所述库的头文件,它编译得很好。 但是,我应该能够在构建时指定它,因为这是库打算如何使用。 我知道在CMake中,我可以用类似的东西来定义宏

SET(ALIGN_DECL "__attribute__((aligned(x)))") 

in Scons like this 像这样在Scons中定义

myEnv.Append(CPPDEFINES = ['IAMADEFINEDCONSTANT']) 

in this way doesn't work. 工作正常,但以这种方式定义不起作用。 是什么赋予了?

编辑:修正错字

我能够在Linux上使用g ++进行如下操作:

SConscript

env = Environment()
env.Append(CPPDEFINES=['MAX(x,y)=(x>y ? x:y)'])
env.Program(target = 'main', source = 'main.cc')

main.cc

#include <iostream>

using namespace std;

int main(int argc, char **argv)
{
  int a = 3;
  int b = 5;

  // MAX() will be defined at compile time
  cout << "Max is " << MAX(a, b) << endl;
}

汇编

$ scons
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
g++ -o main.o -c "-DMAX(x,y)=(x>y ? x:y)" main.cc
g++ -o main main.o
scons: done building targets.

执行

./main
Max is 5

暂无
暂无

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

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