Scons仅在OSX上将随机数“ 1”附加到宏定义

时间:2019-01-01 00:37:32

标签: c++ macos g++ scons

我有一个命令行参数,该参数定义用于Vector3类的类型。它在SConstruct文件中定义如下:

EnumVariable('vector3_type', 'The type to use for Vector3\'s xyz coordinates', 'float', allowed_values=['float', 'double', 'long_double'], ignorecase=2)

此变量在此处添加到环境中:

if env['vector3_type'] != 'long_double':
    env.Append(CPPDEFINES = ["BIGROCK_VEC3_TYPE %s" % env['vector3_type']])
else:
    env.Append(CPPDEFINES = ["BIGROCK_VEC3_TYPE long double"])

这在Windows 10上正常工作,但是当我尝试在OSX上编译时,出现以下错误:

In file included from src/octree.cpp:1:
In file included from src/octree.h:5:
src/vector3.h:15:9: error: expected member name or ';' after declaration specifiers
    BIGROCK_VEC3_TYPE x, y, z;
    ^~~~~~~~~~~~~~~~~
<command line>:1:33: note: expanded from here
#define BIGROCK_VEC3_TYPE float 1
                          ~~~~~ ^

scons或g ++在我的宏末尾添加了一个额外的“ 1”,从而导致其余的代码中断。

当我在scons中打印env ['vector3_type']时,它没有附加1。我不知道这个1会被添加到哪里。

1 个答案:

答案 0 :(得分:1)

这让我感到有些愚蠢。 Scons假定CPPDEFINES中的一个孤立字符串是一个标志名称,并将为#ifdef和#ifndef指令在其后附加1。传递此#define的正确方法是:

if env['vector3_type'] != 'long_double':
    env.Append(CPPDEFINES = [("BIGROCK_VEC3_TYPE", env['vector3_type'])])
else:
    env.Append(CPPDEFINES = [("BIGROCK_VEC3_TYPE", "long double")])