使用 gcc 静态编译一些包时出现关于 libprocps.a 的错误

Using gcc compile some package statically got an error about libprocps.a

# g++ -v                                        
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/7/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 7.3.0-27ubuntu1~18.04' --with-bugurl=file:///usr/share/doc/gcc-7/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-7 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 7.3.0 (Ubuntu 7.3.0-27ubuntu1~18.04)

好吧,我正在尝试使用 gcc 静态编译我的代码:

g++ build/test.o -o build/test -std=c++11 -DCURVE_MNT4 -DNO_PROCPS -I ./src/ -static -lm -lff -lstdc++ -lgmpxx -lgmp -lprocps

如果您只是 运行 不带“-static”标志的相同命令,该代码工作得很好,但由于项目需要,我们必须静态编译此代码,因此我们必须使用“-静态”标志,这里是一些日志:

# g++ build/test.o -o build/test -std=c++11 -DCURVE_MNT4 -DNO_PROCPS -I ./src/ -static -lm -lsnark -lff -lstdc++ -lgmpxx -lgmp -lprocps

......
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libprocps.a(pwcache.o): In function `pwcache_get_group':
(.text+0x1c8): warning: Using 'getgrgid' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libprocps.a(pwcache.o): In function `pwcache_get_user':
(.text+0x58): warning: Using 'getpwuid' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libprocps.a(readproc.o): In function `sd2proc':
(.text+0x1233): undefined reference to `sd_pid_get_machine_name'
(.text+0x1247): undefined reference to `sd_pid_get_owner_uid'
(.text+0x1296): undefined reference to `sd_pid_get_session'
(.text+0x12b1): undefined reference to `sd_session_get_seat'
(.text+0x12c7): undefined reference to `sd_pid_get_slice'
(.text+0x12dd): undefined reference to `sd_pid_get_unit'
(.text+0x12f3): undefined reference to `sd_pid_get_user_unit'
collect2: error: ld returned 1 exit status
Makefile:22: recipe for target 'build/test' failed
make: *** [build/test] Error 1

伙计们有什么想法吗? 我希望有办法解决这个问题,"gcc " 方式或 "ar -r" 方式或“libprocps.a” 的替代方案对我来说很好,我只是想知道如何编译成功使用标志“-static”,谢谢大家

在没有 systemd 支持的情况下重新编译 libprocps (--with-systemd=no) 摆脱了 systemd 依赖并允许@Will_Z 创建一个完全静态链接的二进制文件。