I want to link all the binary code from these included header files so I can distribute my shared library in one .so file.
You cannot do what you want (and that is against the whole idea of shared libraries, which, as their name imply, are shared between several processes and "loaded" into their virtual address space by the dynamic linker).
You should read Drepper's How To Write Shared Libraries paper and the Program Library HowTo. See also ld-linux(8) & elf(5) & objdump(1) & readelf(1) & ld(1) & ldd(1). Read about Invoking GCC.
To ease distribution of your software, you may want to build some package (e.g. a .deb
one) targetting some package manager. And you might publish your source code as free software (e.g. on github).
You could (and perhaps should) link other lower-level shared libraries with your own one. But your user would still need to have these libraries installed. For example, you might compile with
gcc -Wall -O -g -I$JAVA_8_HOME/include/ -I$JAVA_8_HOME/include/linux/
-I./include/ -I. -fPIC -o libMyLibrary.so
-shared com__MyLibrary.c -lother
and check with ldd libMyLibrary.so
that it depends on some libother.so.*
(which your user should have installed to use your libMyLibrary.so
).
You could compile all the code you are using (as position-independent code) -including the source code of "other libraries"- into a single shared library, but that is not recommended (if you did that, a program could practicaly not use some shared low-level function in several shared libraries above it).
You also need to understand that a library is not a set of header files, that is to understand the roles of the linker and of the preprocessor. Header files just describe (partly) the API of some C or C++ library. Read also Levine's Linkers and Loaders book. In practice, header files declare some stuff (classes, functions, variables, types...) and might define inline functions (but not global ones). You need to understand what translation units are.
You could, with the help of the /proc/
file system (see proc(5)), understand the virtual address space of some given process. For instance, try cat /proc/$$/maps
in a terminal.
You may read some Linux programming book, perhaps the old ALP (freely downloadable) or something newer. You may read some textbook on operating systems, such as Operating Systems: Three Easy Pieces (also freely downloadable).
Look also for inspiration into the source code and build procedure of existing free software libraries (e.g. from your Linux distribution, or on github or elsewhere). You should consider using some build automation tool (e.g. GNU make, or ninja) to build your own library.