我正在尝试在Scons中定义一个预处理器宏来构建一个更大的C/C++项目.
我正在使用的其中一个库需要ALIGN定义.更具体地说,如果我添加
#define ALIGN(x) __attribute((aligned(x)))
Run Code Online (Sandbox Code Playgroud)
对于所述库的头文件,它编译得很好.但是,我应该能够在构建时指定它,因为这是库打算使用的方式.我知道在CMake中,我可以用类似的东西来定义宏
SET(ALIGN_DECL "__attribute__((aligned(x)))")
Run Code Online (Sandbox Code Playgroud)
像这样在Scons中定义常量
myEnv.Append(CPPDEFINES = ['IAMADEFINEDCONSTANT'])
Run Code Online (Sandbox Code Playgroud)
工作正常,但以这种方式定义宏不起作用.是什么赋予了?
编辑:修正错字
我能够在Linux上使用g ++进行如下操作:
SConscript
env = Environment()
env.Append(CPPDEFINES=['MAX(x,y)=(x>y ? x:y)'])
env.Program(target = 'main', source = 'main.cc')
Run Code Online (Sandbox Code Playgroud)
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;
}
Run Code Online (Sandbox Code Playgroud)
汇编
$ 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.
Run Code Online (Sandbox Code Playgroud)
执行
./main
Max is 5
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4684 次 |
| 最近记录: |