本篇记录下编译stress-ng源码遇到的问题
先去官网下载源码stress-ng源码
https://fossies.org/linux/privat/
动态编译完后在ARM板子上执行./stress-ng命令出现错误"/lib/aarach64-linux-gnu/libc.so.6:未找到版本`GLIBC_2.33’”。
./stress-ng
/lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.34' not found
我想的是用静态编译就可以不去动态库依赖glibc版本的问题。
随后静态编译遇到下面日志报错
LD stress-ng
/home/forlinx/rk3588/OK3588-linux-source/prebuilts/gcc/linux-x86/aarch64/gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu/bin/../lib/gcc/aarch64-none-linux-gnu/10.3.1/../../../../aarch64-none-linux-gnu/bin/ld: /home/forlinx/rk3588/OK3588-linux-source/prebuilts/gcc/linux-x86/aarch64/gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu/bin/../aarch64-none-linux-gnu/libc/usr/lib/../lib64/librt.a(shm_open.o): in function `shm_open':
/data/jenkins/workspace/GNU-toolchain/arm-10/src/glibc/rt/../sysdeps/posix/shm_open.c:36: undefined reference to `__shm_directory'
/home/forlinx/rk3588/OK3588-linux-source/prebuilts/gcc/linux-x86/aarch64/gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu/bin/../lib/gcc/aarch64-none-linux-gnu/10.3.1/../../../../aarch64-none-linux-gnu/bin/ld: /home/forlinx/rk3588/OK3588-linux-source/prebuilts/gcc/linux-x86/aarch64/gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu/bin/../aarch64-none-linux-gnu/libc/usr/lib/../lib64/librt.a(shm_unlink.o): in function `shm_unlink':
/data/jenkins/workspace/GNU-toolchain/arm-10/src/glibc/rt/../sysdeps/posix/shm_unlink.c:35: undefined reference to `__shm_directory'
collect2: error: ld returned 1 exit status
make: *** [Makefile:633: stress-ng] Error 1
编译结果实际上是说,没include相应的头文件,或是头文件不存在(即系统不支持该库函数)
但我man shm_open是可以找到帮助文件的(说明系统支持),原因何在???
请注意一下man shm_open的帮助文件的最后几行:
NOTES
These functions are provided in glibc 2.2 and later. Programs using
these functions must specify the -lrt flag to cc in order to link
against the required (“realtime”) library.
POSIX leaves the behavior of the combination of O_RDONLY and O_TRUNC
unspecified. On Linux, this will successfully truncate an existing
shared memory object - this may not be so on other Unices.
The POSIX shared memory object implementation on Linux 2.4 makes use of a dedicated file system,
which is normally mounted under /dev/shm.
如果你注意到的话,这样编译就能通过了:
gcc -o test test.c -lrt
我更改了Makefile
原先是override LDFLAGS += -static -z muldefs
后来是原先是override LDFLAGS += -static -z muldefs -lrt
编译成功
参考文章
[1]: https://blog.csdn.net/jinking01/article/details/109527755