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 ?

1 Answer 1

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)
Sign up to request clarification or add additional context in comments.

4 Comments

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, 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.
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.
,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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.