Question

If I have this SConstruct file:

env = Environment()
mylib = env.SharedLibrary(target='mylib', source='mylib.c')
print mylib[0].name

That will print libmylib.so on Linux and mylib.dll on Windows.

Is there any attribute on the value returned from SharedLibrary that will return the original target name that I passed in?

Was it helpful?

Solution

There is no general relation in SCons between the name you pass in as a target and the actual target node. Usually it's something simple as in @Brady's answer, but if you have an emitter in the builder the emitter could rename the target however it wants, or add more targets. And sometimes you call a builder with no target, just a source, as in env.Program('foo.c'). In fact, a target doesn't need to be a file! It could be a dir, or a Value even. So in general, I'd question why you want to do that -- there may be a better way to solve your problem.

OTHER TIPS

I dont think its possible to get the original target name, but what you can do is get the platform dependent library prefix and suffix and strip those off to get the original library name. These prefixes and suffixes are in the form of SCons Construction Variables. You'll be interested in the following:

  • LIBPREFIX - static library prefix

  • LIBSUFFIX - static library suffix

  • SHLIBPREFIX - shared library prefix

  • SHLIBSUFFIX - shared library suffix

In your case with a shared library, you could get the original name like this:

print mylib[0].name.strip(SHLIBPREFIX).rstrip(SHLIBSUFFIX)

This will work on any platform, since these construction variables change depending on the platform.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top