Is it possible to include statically linked libraries in other libraries in C/C++?

lex82

In my project I have some shared code in a statically linked library that is used by several subprojects, each of which building its own executable. I use ar to create the library from the .o files. Part of the shared code depends on statically linked third party libraries.

Currently, I have to include all the third party libraries in each makefile (for each executable) and pass them to g++. Is it possible to include these libraries in the one library shared by the subproject, so I don't have to reference them explicitly when building the different executables? Or is there something wrong with my approach in general?

n. 'pronouns' m.

It is possible to pack all the static libraries you are using in one big library. You don't want that.

The common method of dealing with the situation is defining variables in your top level makefile, or in an .inc file included by several makefiles:

MY_LIBS = -lOne -lTwo
MY_LDFLAGS = -L /path/to/libs

and then adding these variables to standard variables

LDLIBS += $(MY_LIBS)
LDFLAGS += $(MY_LDFLAGS)

Variables above are used by GNU Make implicit link rules; if you are using your own rules, be sure to use these variables, like this:

...
g++ $^ $(LDLIBS) $(LDFLAGS) -o $@

Look at several makefiles from established open source projects for inspiration.

References:

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Statically linked libraries and JNI?

From Dev

GCC: list a statically linked libraries

From Dev

Combine Dynamically Linked Libraries into one Statically Linked Library

From Dev

What happens to static variables when libraries are statically linked

From Dev

How to link libgomp statically when linking other libraries dynamically?

From Dev

Is it possible to include C++ libraries in C programs?

From Dev

Is it possible to include C++ libraries in C programs?

From Dev

How to change Visual Studio C++ initialization sequence for const string arrays in statically linked libraries

From Dev

Statically linked executable with LTO (link time optimization) : how to make it with previously built libraries

From Dev

Order of linked libraries in XCode

From Dev

Order of linked libraries in XCode

From Dev

Is there an rpath for dynamic linked libraries?

From Dev

how to compile c++ and not include cstdio and other c standard libraries

From Dev

how to compile c++ and not include cstdio and other c standard libraries

From Dev

How to include JavaScript libraries?

From Dev

Include libraries in EAR with Maven

From Dev

Android, referencing other libraries

From Dev

(CMake) PCL + Other libraries

From Dev

Webpack require other libraries

From Dev

Possible conflicting jquery libraries

From Dev

ClassNotFoundException from libraries that use other libraries

From Dev

c++ cannot use libraries in other libraries

From Dev

Linked frameworks and libraries in Swift project

From Dev

Symbol visibility of indirectly linked libraries

From Dev

Symbol visibility of indirectly linked libraries

From Dev

Find libraries a binary was linked against

From Dev

how to #include third party libraries

From Dev

How to include external libraries in CMakeLists?

From Dev

Include mingw libraries in compiled file

Related Related

  1. 1

    Statically linked libraries and JNI?

  2. 2

    GCC: list a statically linked libraries

  3. 3

    Combine Dynamically Linked Libraries into one Statically Linked Library

  4. 4

    What happens to static variables when libraries are statically linked

  5. 5

    How to link libgomp statically when linking other libraries dynamically?

  6. 6

    Is it possible to include C++ libraries in C programs?

  7. 7

    Is it possible to include C++ libraries in C programs?

  8. 8

    How to change Visual Studio C++ initialization sequence for const string arrays in statically linked libraries

  9. 9

    Statically linked executable with LTO (link time optimization) : how to make it with previously built libraries

  10. 10

    Order of linked libraries in XCode

  11. 11

    Order of linked libraries in XCode

  12. 12

    Is there an rpath for dynamic linked libraries?

  13. 13

    how to compile c++ and not include cstdio and other c standard libraries

  14. 14

    how to compile c++ and not include cstdio and other c standard libraries

  15. 15

    How to include JavaScript libraries?

  16. 16

    Include libraries in EAR with Maven

  17. 17

    Android, referencing other libraries

  18. 18

    (CMake) PCL + Other libraries

  19. 19

    Webpack require other libraries

  20. 20

    Possible conflicting jquery libraries

  21. 21

    ClassNotFoundException from libraries that use other libraries

  22. 22

    c++ cannot use libraries in other libraries

  23. 23

    Linked frameworks and libraries in Swift project

  24. 24

    Symbol visibility of indirectly linked libraries

  25. 25

    Symbol visibility of indirectly linked libraries

  26. 26

    Find libraries a binary was linked against

  27. 27

    how to #include third party libraries

  28. 28

    How to include external libraries in CMakeLists?

  29. 29

    Include mingw libraries in compiled file

HotTag

Archive