开发者

Create statically-linked binary that uses getaddrinfo?

开发者 https://www.devze.com 2022-12-28 15:10 出处:网络
I have included the header netdb.h, where getaddrinfo is included, but gcc issues this warning: warning: Using \'getaddrinfo\' in statically linked applications requires at runtime the shared librari

I have included the header netdb.h, where getaddrinfo is included, but gcc issues this warning:

warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking

gcc -m32 -static -s -O2 -std=c99 -D_POSIX_C_SOURCE=200112L myprogram.c

How can I statically compile whatever file is missing ?

Possible solutions:

  1. It could be that the glibc installation is missing the corresponding object file necessary for static compilation. If that is the case, create the corresponding object file and link it at c开发者_高级运维ompilation.

  2. Try EGLIBC instead of glibc.

  3. I succesfully compiled my program with dietlibc which compiled without any errors plus the resulting binary was much smaller than what glibc makes.


glibc uses libnss to support a number of different providers for address resolution services. Unfortunately, you cannot statically link libnss, as exactly what providers it loads depends on the local system's configuration.


You can use musl library to replace glibc. To use musl, you can either install it and build your software using musl-gcc, or you can use a Linux distribution that uses musl, e.g. Alpine Linux.

In my case, to save time, I chose Alpine Linux to build my program (https://github.com/zhanxw/rvtests), as I don't want to build multiple compilers (gcc, g++ and gfortran).


I think certain features are dependent on the dynamic loader to work things out at run time. static linking is no longer practical unfortunately http://people.redhat.com/drepper/no_static_linking.html

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号