c-使用gcc静态编译某些软件包会遇到有关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”标志的同一命令,则该代码可以很好地工作,但是由于项目需要,我们必须静态地编译此代码,因此我们必须使用“ -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创建完全静态链接的二进制文件.

上一篇:ClickHouse应用实践和原理解析


下一篇:qlv视频怎么转换成mp4格式工厂?如何用格式工厂将qlv格式转换成mp4格式?