制作多线程时如何表达对共享库的依赖
How to express dependence on a shared library when making multithreaded
我使用共享 library.so
以避免在仅实现 (library.cpp
) 而不是接口 (library.hpp
时重新制作可执行文件(链接到它) ), 已经改变, 即
obj/library.o: library.cpp library.hpp
lib/library.so: obj/library.o
program : program.cpp library.hpp
$(CXX) program.cpp -Llib -lrary
因此,program
不依赖于 library.cpp
或 library.so
。但是,从头开始制作(而不是因为某些文件的更改而重新制作)时,library.so
必须在 program
之前制作。这可以通过设置来确保:
default: library.so program
但是当使用 make -j
时,这是错误的。
那么正确的方法是 1) 确保 library.so
在 program
之前制作,但 2) 如果只有 library.cpp
发生变化,则避免重新制作 program
?
您想要的解决方案是一个仅订单的先决条件。
来自 GNU make 手册的 Types of Prerequisites 部分:
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
我使用共享 library.so
以避免在仅实现 (library.cpp
) 而不是接口 (library.hpp
时重新制作可执行文件(链接到它) ), 已经改变, 即
obj/library.o: library.cpp library.hpp
lib/library.so: obj/library.o
program : program.cpp library.hpp
$(CXX) program.cpp -Llib -lrary
因此,program
不依赖于 library.cpp
或 library.so
。但是,从头开始制作(而不是因为某些文件的更改而重新制作)时,library.so
必须在 program
之前制作。这可以通过设置来确保:
default: library.so program
但是当使用 make -j
时,这是错误的。
那么正确的方法是 1) 确保 library.so
在 program
之前制作,但 2) 如果只有 library.cpp
发生变化,则避免重新制作 program
?
您想要的解决方案是一个仅订单的先决条件。
来自 GNU make 手册的 Types of Prerequisites 部分:
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