[Scons-users] using g++ vs. gcc for linking when used with Repository()

Chris BeHanna chris at behanna.org
Thu Aug 9 13:30:29 EDT 2012


On Aug 9, 2012, at 08:20 , taf.undying at gmx.de wrote:


> I get some weird link errors and don't know if this is a bug or if I am doing something wrong. So maybe you can help.

>

> Assuming the following, simple folder setup:

>

> +-.

> +-local

> | +-sconstruct

> +-remote;

> +-main.cpp

> +-sconstruct

>

> main.cpp only contains a simple hello world example:

>

>> [...snip...]

>

> And the sconstruct files (both) only contain a simple target definition for a program:

>

>> env = Environment()

>> env.Program('test', ['main.cpp'])

>

> Now, if I run "scons" in the "remote" directory, first g++ is used to compile "main.cpp" to "main.o" and then g++ is used again to link it to the executable "test".

>

> After that, I run the command "scons -Y ../remote" in the "local" directory.

> Then scons tries to link the executable again (although I think it really should not, as nothing has changed). But this time, it uses gcc instead of g++. This results in "undefined reference" errors, as the STL library is not linked.

>

> Trying different varations of that setup, I can say that it basically boils down to whether the object file "main.o" is in the local directory or whether it is only remote.

> If it is local, then g++ is used for linking, but if the object file is remote, then scons tries to link using gcc, which fails.


The problem is that after you've built in the remote directory, an SCons instance in the "local" directory that is using it as a repository only sees the bare .o file. It does not know that the .o file was built using g++; thus, it does not know that you need to link using g++, so it does the default link action, which is to use gcc.

I agree, this is surprising, and it looks like you've turned up a bug, as scons *should* know from what you've written in your SConstruct file that main.o came from main.cpp, and should then know that, even if it fetches main.o from the repository to re-link locally, it needs to use g++.

--
Chris BeHanna
chris at behanna.org


More information about the Scons-users mailing list