使用 SCon 定义C++预处理器宏
Defining C++ Preprocessor macros with SCons
我正在尝试在 Scons 中定义一个预处理器宏,用于构建更大的 C/C++ 项目。
我正在使用的库之一需要定义 ALIGN。更具体地说,如果我添加
#define ALIGN(x) __attribute((aligned(x)))
到所述库的头文件,它可以很好地编译。但是,我应该能够在构建时指定这一点,因为这是库打算使用的方式。我知道在 CMake 中,我将能够使用类似的东西定义宏
SET(ALIGN_DECL "__attribute__((aligned(x)))")
像这样定义 Scons 中的常量
myEnv.Append(CPPDEFINES = ['IAMADEFINEDCONSTANT'])
工作正常,但以这种方式定义宏不起作用。什么给?
编辑:修正错别字
我能够在 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
相关文章:
- 错误:无效的预处理指令 #i 的意思是 #if?
- C++预处理会生成变量成员、资源库和映射
- 使用预处理指令检查是否包含标头?
- 预处理的 C/C++ 文件是否特定于计算机?
- 使用 GCC 对 C 文件进行部分预处理(不删除 "define" 指令)
- 在 CPLEX 中求解线性规划,无需剪切和预处理
- CPP -D 选项,用于预处理 Fortran 代码
- 错误:粘贴"tmp_UINT"和"+"未提供有效的预处理令牌
- 任务计划程序库的预处理不起作用 - 多定义错误
- Eclipse 问题 - 编译期间不考虑 .c 和 .cpp 文件中定义的预处理
- 使用python预处理后,C++(opencv)中的垫子类型数据与image_to_array相同
- Howo 使用 cl 预处理为 masm 组装生成一个单独的文件
- 我有一个预处理的 C/C++ 源文件 (cacti.i).如何从这个 .i 文件生成可执行二进制文件,以便我可以像 ./
- 如何使用Visual Studio C/C++编译器(cl.exe)来预处理我的objective-C代码
- 是具有预处理前分支实现的结构违反ODR
- 与不完整的Cholesky预处理的共轭梯度返回特征库的意外错误
- Visual Studio C - 无法输出预处理文件
- 在海湾合作委员会中加快宏观预处理的任何方法
- 所有结构成员的预处理器批处理
- 当头文件被预处理时是否有一个预处理器选项显示?