Reputation:
I create static library and linking main.cpp
.
I compile programm using static library, but programm have some dependencies of shared libraries
libstdc++.so.6 => /usr/lib32/libstdc++.so.6 (0xf75c1000)
libm.so.6 => /lib/i386-linux-gnu/libm.so.6 (0xf756a000)
libgcc_s.so.1 => /lib/i386-linux-gnu/libgcc_s.so.1 (0xf754c000)
libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xf7394000)
libz.so.1 => /lib/i386-linux-gnu/libz.so.1 (0xf7379000)
libssl.so.1.1 => /usr/lib/i386-linux-gnu/libssl.so.1.1 (0xf730b000)
libcrypto.so.1.1 => /usr/lib/i386-linux-gnu/libcrypto.so.1.1 (0xf70a4000)
libev.so.4 => /usr/lib/i386-linux-gnu/libev.so.4 (0xf7094000)
libuv.so.1 => /usr/lib/i386-linux-gnu/libuv.so.1 (0xf706c000)
libpthread.so.0 => /lib/i386-linux-gnu/libpthread.so.0 (0xf704f000)
Edit
I try compile my programm, which used only static libraries. A libHermite.a
is my compiled static library.
g++ -o HermitesPolynomialCleanLx-x64 main.cpp -static -L/home/mnowak/projects/HermitesPolynomialLxClean/lib -lHermite -lwebsockets -lstdc++ -lpthread -lssl -lcrypto -ldl -luv -lev -lgcc -lc -Wall -Wextra -pedantic -pthread
My output:
/home/mnowak/projects/HermitesPolynomialLxClean/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_globallookup':
(.text+0x11): warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/home/mnowak/projects/HermitesPolynomialLxClean/lib/libwebsockets.a(lws-plat-unix.c.o): In function `lws_plat_drop_app_privileges':
(.text+0x79e): warning: Using 'initgroups' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/home/mnowak/projects/HermitesPolynomialLxClean/lib/libwebsockets.a(lws-plat-unix.c.o): In function `lws_plat_drop_app_privileges':
(.text+0x787): warning: Using 'getpwuid' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/home/mnowak/projects/HermitesPolynomialLxClean/lib/libuv.a(libuv_la-core.o): In function `uv__getpwuid_r':
(.text+0x16e0): warning: Using 'getpwuid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/home/mnowak/projects/HermitesPolynomialLxClean/lib/libwebsockets.a(libwebsockets.c.o): In function `lws_get_addresses':
(.text+0x1a9): warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/home/mnowak/projects/HermitesPolynomialLxClean/lib/libcrypto.a(b_sock.o): In function `BIO_gethostbyname':
(.text+0x71): warning: Using 'gethostbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
Upvotes: 1
Views: 10076
Reputation: 1
How to compile a program so that the dynamic libraries are linked in the static library built by me.
This is not possible. Shared libraries have (in practice) position-independent code, but static libraries (usually) don't. See also this answer to a very related question.
Read Drepper's paper How To Write Shared Libraries.
I recommend making, as most people do, your shared library, possibly linked to other shared libraries. There are many good reasons to prefer shared libraries.
Or (usually not recommended) make a static library and require your users to link other dependent libraries statically (which is not recommended). e.g. link also your & their executable with -Bstatic
I would like, that my program using only static library without outer dependencies.
This is usually a wrong wish (which smells badly like some XY problem). You should prefer to systematically use shared libraries (for many reasons, e.g. read Program Library HowTo) , like most programs of your Linux distribution do. For instance, of the 6249 executables in my /usr/bin/
only one go-md2man
is statically linked.
In 2018, there are very few reasons to statically link an executable (Usually, only few low-level system utilities to be usable after a bad system crash need to be statically linked, and they mostly sit under /sbin/
).
BTW, your software looks like using some cryptography. This is a very good reason to dynamically link it: you want your user to profit from any future bug correction in libcrypto.so
or libssl.so
as soon as possible (e.g. when his Linux distribution is updating these).
(so I think that a cryptographic program which is statically linked is a security risk by itself)
To deal with dependencies, use a package manager and release your thing as e.g. some .deb
package. But you probably could just transmit the source code of your software, it is often simpler (to let your user rebuild it).
Upvotes: 1