0

I have a Makefile.am with two noinst_LIBRARIES, and one of them needs to link with the other.

Adding it to the CFLAGS throws a compiler warning, but as far as I know, automake likes to freak out about using LDADD with libraries, since they are not complete programs.

How can I do this, assuming libb.a needs to pull in liba.a?

8
  • 1
    You don't link static libraries, they are added to your binary. Commented Jun 3, 2015 at 13:46
  • 1
    It's not clear to me what exactly you're trying to do, but note that you cannot link one static library to another. They're just a collection of object files, and there is no mechanism in static libraries to indicate that they depend on another library. Commented Jun 3, 2015 at 13:46
  • @nos true, however if there is dependency, i.e. if liba.a uses symbols from libb.a then when including the libraries in your binary you must be careful about the order in which you pass them. Which means that circular dependencies are not allowed. Commented Jun 3, 2015 at 13:47
  • Possible Duplicate Commented Jun 3, 2015 at 13:48
  • 1
    @iharob Circular dependencies can be handled, but you must mention the libraries several times when linking the program that uses them, e.g. pass the flags -lA -lB -lA Commented Jun 3, 2015 at 13:51

1 Answer 1

1

You can't do it. Actually, what you are trying to do doesn't really make sense. Static libraries are just archives containing object files and a table of contents. Put simply, you can think of a static library as a .zip containing .o files.

The linking phase only takes place when compiling a shared object or executable. When your program is linked against liba.a, you also need to specify -static -lb or similar and that's it.

Sign up to request clarification or add additional context in comments.

2 Comments

I suppose I was considering "linking" the static libraries to be "include the object files from the other one in the final one".
That's very far from linking :) if you meant merging two archives into another, there is no universal way of doing so (because static libraries are not meant to be handled like that), but you might find platform-specific ways. For instance, GCC/Clang static libraries are ar archives that you could extract, merge and repack. Instead, MSVC has a tool for that. Be careful with conflicting names or symbols though.

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.