What is the reason for having both a CCFLAGS and a SHCCFLAGS variable in the SCons environment?

I am trying to modify a large program build that I did not write myself. When I add the command:

env.Append(CCFLAGS=["-I%s" % amber_dir, "-DAMBER"])

the compiler runs without the flags I added. But when I do

env.Append(SHCCFLAGS=["-I%s" % amber_dir, "-DAMBER"])

the compiler adds my flags as wanted. Somewhere in SCons' innards, CCFLAGS are is not passed to SHCCFLAGS. But why have a CCFLAGS and a SHCCFLAGS to begin with?

有帮助吗?

解决方案

This is taken from the SCons User's Guide: SCons Construction Variable

CCFLAGS

General options that are passed to the C and C++ compilers.

CPPFLAGS

User-specified C preprocessor options. These will be included in any command that uses the C preprocessor, including not just compilation of C and C++ source files via the $CCCOM, $SHCCCOM, $CXXCOM and $SHCXXCOM command lines, but also the $FORTRANPPCOM, $SHFORTRANPPCOM, $F77PPCOM and $SHF77PPCOM command lines used to compile a Fortran source file, and the $ASPPCOM command line used to assemble an assembly language source file, after first running each file through the C preprocessor. Note that this variable does not contain -I (or similar) include search path options that scons generates automatically from $CPPPATH. See $_CPPINCFLAGS, below, for the variable that expands to those options.

SHCCFLAGS

Options that are passed to the C and C++ compilers to generate shared-library objects.

SHCCCOM

The command line used to compile a C source file to a shared-library object file. Any options specified in the $SHCFLAGS, $SHCCFLAGS and $CPPFLAGS construction variables are included on this command line.

The most interesting of the 4 mentioned above are the SHCCCOM and CPPFLAGS variables. Try your test again setting CPPFLAGS instead of CCFLAGS.

A general comment about the flags you are setting: with SCons, its generally better to set include paths with the CPPPATH variable, and to set defines with the CPPDEFINES. When using these variable, you dont need to include the -I, nor the -D flags, SCons will add it for you in a platform-independent manner. Here's an example:

env.Append(CPPPATH=amber_dir)
env.Append(CPPDEFINES='AMBER')

You'll need to test this to see if the SharedObject() and/or SharedLibrary() builders use those, I would imagine they would.

Answers to questions in comment below:

SHCCCOM is just used to see what the command line looks like, sometimes you may need to use it without using the SCons builders directly. SHCCFLAGS is a super-set of CPPFLAGS and others and should be used when you have flags that you only want to pass to SharedLibrary() or SharedObject(). CPPFLAGS applies to both static and shared compilations.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top