Walter
Walter

Reputation: 45444

How to express dependence on a shared library when making multithreaded

I use a shared library.so in order to avoid to remake executables (which are linked against it) when only the implementation (library.cpp), but not the interface (library.hpp), has changed, i.e.

obj/library.o:    library.cpp library.hpp
lib/library.so:    obj/library.o

program        :    program.cpp library.hpp
                $(CXX) program.cpp -Llib -lrary

Thus, program does not depend on library.cpp or library.so. However, when making it from scratch (rather than remaking it because of changes to some files), library.so must be made before program. This can be ensured by setting:

default:    library.so program

But when using make -j this is broken.

So what is the correct way to 1) ensure library.so is made before program but 2) avoid re-making program if only library.cpp has changed?

Upvotes: 0

Views: 56

Answers (1)

Etan Reisner
Etan Reisner

Reputation: 81002

The solution for what you want is an order-only prerequisite.

From the Types of Prerequisites section of the GNU make Manual:

Occasionally, however, you have a situation where you want to impose a specific ordering on the rules to be invoked without forcing the target to be updated if one of those rules is executed. In that case, you want to define order-only prerequisites. Order-only prerequisites can be specified by placing a pipe symbol (|) in the prerequisites list: any prerequisites to the left of the pipe symbol are normal; any prerequisites to the right are order-only:

targets : normal-prerequisites | order-only-prerequisites

Upvotes: 1

Related Questions