Makefile Creates Two Libraries - One Depends On Other

Phil

I have a parent C++ Makefile that builds 2 libraries, from two source subdirectories.

Library B depends on Library A.

The cpp files is compiled via the standard implicit rule.

The linker step is completed by having a function that takes the sources, replaces the .cpp with a .o and then creates a dependency:

# $(call source-to-object, source-file-list)
source-to-object = $(subst .c,.o,$(filter %.c,$1)) \
                   $(subst .cpp,.o,$(filter %.cpp,$1))


# $(call make-library, library-name, source-file-list, customldopt)
define make-library
  libraries += $1
  sources += $2

  $1: $(call source-to-object,$2)
        $(CXX) $(CXXFLAGS) -shared $$^ -o $(RELEASE)/$$@ -L$(RELEASE) $(LDFLAGS) $(LDLIBS) $(addprefix -l,$3)
endef

This works fine until I want to introduce a dependency between the 2 libraries. I'm doing this by hardcoding:

libB.so: libA.so

The problem here is that the $$^ will now not cleanly contain a list of object files, but will also include the libA.so - which has no place being in the linker line in the same place as the object files?

So my question is how do I introduce the idea of a dependency between two libraries, without polluting the linker line with the value of the dependent library?

This statement is not correct, you do want the library to be referenced on the linker line in the same form as it is represented as a target - see my answer

I can of course just have -lA in the linker line for libB.so, just like you would for a 3rd party dependency - but this does not guarantee it will be built before it is referenced?

One thing I have noticed is that if I change $(RELEASE)/$$@ to just $$@ then it works:

g++ -fPIC -shared path/to/some_source.o libA.so -o libB.so 

This is a problem as I need the output of both libraries in the $RELEASE directory, and I'm not convinced the libA.so in the above linker line is ever correct?

It's becoming a bit of a mess - any advice?

Thanks

Phil

The problem was my understanding of the linker command, and the moving of the output target as stated by @o11c in the comments under the original question.

Having libA.so on the linker line is fine.

I've added a subsequent cp command to copy the the $@ to $(RELEASE) so that targets are kept where make expects.

$1: $(call source-to-object,$2)
    $(CXX) $(CXXFLAGS) -shared $$^ -o $$@ $(LDFLAGS) $(LDLIBS)
    $(CP) $$@ $(RELEASE)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Android NDK: Two prebuilt shared libraries, but one of them depends on the other

From Dev

Makefile generator creates two files

From Dev

How I use one YAML to deploy two servers where one depends on the other one in Kubernetes

From Dev

Compile two projects on NDK w/ gradle, one of which depends on the other's binary

From Dev

How to ensure that two programs always run ? (where the one depends upon the other.)

From Dev

How can I simultaneously complete two sets of tasks in python when one depends on the other?

From Dev

link two j spinners where number range of one depends on value selected in the other

From Dev

SELECT query that depends on two other tables

From Dev

two async tasks - one depends on another in python

From Dev

Two libraries which can expand each other

From Dev

Code creates two MySQL rows instead of one

From Dev

Django creates two model instances instead of one

From Dev

jQuery .append() creates two elements not one

From Java

How to merge two "ar" static libraries into one?

From Dev

Recursive Oracle query to calculate two values that depends on each other

From Dev

Updating a column that depends on two other colums all in the same table

From Dev

Retrieving data from two XML that depends on each other

From Dev

vectorizing a nested loop where one loop variable depends on the other

From Dev

Typescript Generic Constraint where the property of one type depends on the other

From Dev

Rendering 2 elements when one depends of the content of the other

From Dev

Microservices, How to decouple services if data on one service depends on other?

From Dev

react one state variable depends on multiple other states variables

From Dev

Using a FutureBuilder with one future depends on the results on the other future

From Dev

Split a Flowable in 2, process 2 streams, but one depends on the other?

From Dev

How to tackle when one parameter depends on the other in RSTAN

From Dev

How to fix Module depends on one or more Android Libraries but is a Jar when building Cordova App

From Dev

Rxjs: Merge two streams with one stream that depends of another

From Dev

Static libraries linked against other static libraries with CMake - one works, one doesn't. Why?

From Dev

One function call creates double borrow error while other does not

Related Related

  1. 1

    Android NDK: Two prebuilt shared libraries, but one of them depends on the other

  2. 2

    Makefile generator creates two files

  3. 3

    How I use one YAML to deploy two servers where one depends on the other one in Kubernetes

  4. 4

    Compile two projects on NDK w/ gradle, one of which depends on the other's binary

  5. 5

    How to ensure that two programs always run ? (where the one depends upon the other.)

  6. 6

    How can I simultaneously complete two sets of tasks in python when one depends on the other?

  7. 7

    link two j spinners where number range of one depends on value selected in the other

  8. 8

    SELECT query that depends on two other tables

  9. 9

    two async tasks - one depends on another in python

  10. 10

    Two libraries which can expand each other

  11. 11

    Code creates two MySQL rows instead of one

  12. 12

    Django creates two model instances instead of one

  13. 13

    jQuery .append() creates two elements not one

  14. 14

    How to merge two "ar" static libraries into one?

  15. 15

    Recursive Oracle query to calculate two values that depends on each other

  16. 16

    Updating a column that depends on two other colums all in the same table

  17. 17

    Retrieving data from two XML that depends on each other

  18. 18

    vectorizing a nested loop where one loop variable depends on the other

  19. 19

    Typescript Generic Constraint where the property of one type depends on the other

  20. 20

    Rendering 2 elements when one depends of the content of the other

  21. 21

    Microservices, How to decouple services if data on one service depends on other?

  22. 22

    react one state variable depends on multiple other states variables

  23. 23

    Using a FutureBuilder with one future depends on the results on the other future

  24. 24

    Split a Flowable in 2, process 2 streams, but one depends on the other?

  25. 25

    How to tackle when one parameter depends on the other in RSTAN

  26. 26

    How to fix Module depends on one or more Android Libraries but is a Jar when building Cordova App

  27. 27

    Rxjs: Merge two streams with one stream that depends of another

  28. 28

    Static libraries linked against other static libraries with CMake - one works, one doesn't. Why?

  29. 29

    One function call creates double borrow error while other does not

HotTag

Archive