0

I am using scons to build my project. Now I got a problem.

I use
env.StaticLibrary('a', [a1.o, a2.o])
to get a static library "liba.a".

Now I pass "liba.a" to another part of my project, in the part, I will generate another static library named "libb.a", and this will merge "liba.a" with some other object files.

The code like this:
env.StaticLibrary('b', ['liba.a', 'b1.o', 'b2.o'] )

In this question Linking static libraries, that share another static library we know that we can not simply merge a static library into another static library, Because this may result in some symbol problems.

Now I want to solve this problem in this way:

First get the object file of 'liba.a'. Then merge this object files with new object files to generate the final 'libb.a'.

But I found I can not find a method or function to get the object files in a static library with scons.

Can anyone help me ?

Community
  • 1
  • 1
lee
  • 121
  • 1
  • 11

1 Answers1

1

Sounds like you just want to use the same object files for 2 different libraries.

You could do something like this:

env = Environment()

env.StaticLibrary('a', ['a1.o', 'a2.o'])
env.StaticLibrary('b', ['b1.o', 'b2.o', 'a1.o', 'a2.o'])

Additionally, instead of dealing with the Object files, you could directly specify the source files. In this case, SCons will only compile the source files once, as needed.

env.StaticLibrary('a', ['a1.c', 'a2.c'])
env.StaticLibrary('b', ['b1.c', 'b2.c', 'a1.c', 'a2.c'])

Also, remember that each SCons builder returns a list of targets (each being a SCons Node). The list may have one or several entries. So, for example, the following target variable will contain the library target, and all of the objects built:

target = env.StaticLibrary('a', ['a1.c', 'a2.c'])
for t in target: print str(t)
Brady
  • 10,207
  • 2
  • 20
  • 59
  • Thank you for your answer, it is helpful. I want to ask you one more question: Can you decompression a static library into some object files in SCons? I mean do like in command "ar -x liba.a". – lee May 03 '14 at 12:06
  • @lee, you could do it by using the Command() builder or by calling os.system(). Use the 'AR' construction variable to get the 'ar' binary.. I dont understand why you would want to do this though, considering the objects used to create the library are available, either in the same dir as the source files, or in the variant_dir if you're using one. – Brady May 03 '14 at 18:32
  • Thank you again. I don`t want to do that in this way either, but in my company, I just take over a product, and in this product someone else just pass the static library to me, and I need to make a new static library within the former one. What is worse, I can not access the object file of the former one. – lee May 06 '14 at 07:05
  • ,I found a way to get the source file of a static library. I have read the SCons.Node.Node source code, I found it has a attribution -- sources. It is a list which contains the object file address. – lee May 06 '14 at 08:31