簡體   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