I'm using scons for building. I had encountered the following warning (when compiling some classes that are used in multiple build targets):
scons: warning: Two different environments were specified for target /home/stackuser/src/dsl/build/debug/common/LocalLog.o,
but they appear to have the same action: $CXX -o $TARGET -c $CXXFLAGS $CCFLAGS $_CCCOMCOM $SOURCES
So the accepted way around this warning is to use env.Object in the source list for common cpp files:
client_srcs = [
env.Object("../common/LocalLog.cpp"),
env.Object("../common/LogMsg.cpp"),
"LogWriter.cpp",
"QueueConsumer.cpp",
env.Object("../common/QueueStore.cpp"),
env.Object("../common/TimeFunctions.cpp")
]
However, when using this env.Object function around the common cpp files, some targets don't build (linker error linking to boost):
/usr/include/boost/system/error_code.hpp:208: undefined reference to `boost::system::get_system_category()'
/usr/include/boost/system/error_code.hpp:209: undefined reference to `boost::system::get_generic_category()'
/usr/include/boost/system/error_code.hpp:214: undefined reference to `boost::system::get_generic_category()'
/usr/include/boost/system/error_code.hpp:215: undefined reference to `boost::system::get_generic_category()'
This linker error is described here; to summarize the accepted answer:
When statically linking the linker expects that libraries will come after the files containing references to them. You need to move your .o files before your -l flags.
However, if I just remove the env.Object calls in the SConscript, I get these scons warnings, but compilation and linking is successful.
I'd just like to ignore these scons warnings; (how) can I turn them off?
If you take a short look at the MAN page ( http://scons.org/doc/production/HTML/scons-man.html ), you'll find the "warn=no-all" option...amongst a lot of other useful stuff.
Note however, that switching off this warning is a bad idea in general, because it's hinting at flaws in your build description. You're telling SCons to build a file like "debug/common/LocalLog.o" from two (or more) different environments. This may work as long as the command lines used (and the environments, including all shell variable settings) are exactly the same, so that's why SCons continues. But usually you want to have one single way to build a specific target file.
There are three proper solutions to your dilemma (probably more, but these are the ones that came to my head immediately):
1.) Put the sources/objects that you want to use in multiple places into a separate lib and then link against that.
2.) For each time you compile the same *.CPP file, give a different unique name to the object file (LocalLog_a.o, LocalLog_b.log, ...).
3.) Compile the source one time (env.Object('LocalLog.cpp'), and then add the resulting object file to your list of sources for each program/library in question:
client_srcs = [
"../common/LocalLog.$OBJSUFFIX",
"../common/LogMsg.$OBJSUFFIX",
"LogWriter.cpp",
"QueueConsumer.cpp",
"../common/QueueStore.$OBJSUFFIX",
"../common/TimeFunctions.$OBJSUFFIX")
]