Making static binaries problem
xuegege5290 opened this issue · comments
Hi~
I've encountered some issues while compiling conmon and I'm seeking a resolution. I wish to compile conmon as a statically linked binary so that it can be used in other environments. However, after completing the static compilation, there's a warning that suggests conmon will still depend on the glibc version of the host machine when run in other environments. Is there a way to resolve this issue? Of course, you might think that using the Nix package manager would be straightforward, but I'm unable to use Nix and would prefer to compile directly, as direct compilation is also faster.
root@syx:~/go/conmon# make static
+ cat VERSION
+ bash -c '[[ `command -v git` && `git rev-parse --git-dir 2>/dev/null` ]] && echo 0'
+ pkg-config --exists libsystemd
+ hack/seccomp-notify.sh
+ pkg-config --cflags glib-2.0
+ pkg-config --libs glib-2.0
cc -static -std=c99 -Os -Wall -Wextra -Werror -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -DVERSION=\"2.1.10\" -DGIT_COMMIT=\"\" -o bin/conmon src/conmon.o src/cmsg.
o src/ctr_logging.o src/utils.o src/cli.o src/globals.o src/cgroup.o src/conn_sock.o src/oom.o src/ctrl.o src/ctr_stdio.o src/parent_pipe_fd.o src/ctr_exit.o src/runtime_args.o src/close_fds.o
src/seccomp_notify.o -Wl,-Bstatic -lglib-2.0 -lpthread -lc
+ cc -static -std=c99 -Os -Wall -Wextra -Werror -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include '-DVERSION="2.1.10"' '-DGIT_COMMIT=""' -o bin/conmon src/conmon.o src/cmsg.
o src/ctr_logging.o src/utils.o src/cli.o src/globals.o src/cgroup.o src/conn_sock.o src/oom.o src/ctrl.o src/ctr_stdio.o src/parent_pipe_fd.o src/ctr_exit.o src/runtime_args.o src/close_fds.o
src/seccomp_notify.o -Wl,-Bstatic -lglib-2.0 -lpthread -lc
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/libglib-2.0.a(gutils.c.o): in function `g_get_user_database_entry':
(.text+0x277): warning: Using 'getpwuid' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: (.text+0xe0): warning: Using 'getpwnam_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: (.text+0x11e): warning: Using 'getpwuid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
Note that I have used the same method to compile CRI-O without any issues.
Do I need to recompile the glibc library and add options like --enable-static-nss to implement static linking of the NSS library?
Or if I use the Nix package manager for compilation, will I not encounter issues like this that depend on the host's glibc libraries?