Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
564 views
in Technique[技术] by (71.8m points)

c - Create statically-linked binary that uses getaddrinfo?

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 compilation.

  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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...