我不能用openwrt工具链构建静态二进制文件。
# staging_dir/toolchain-i386_i686_gcc-4.8-linaro_glibc-2.21/bin/i486-openwrt-linux-gnu-gcc -o /tmp/main /tmp/main.c -static
/tmp/main.c: In function 'main':
/tmp/main.c:3:2: warning: incompatible implicit declaration of built-in function 'printf' [enabled by default]
printf("Hello world");
^
/home/elison/cop-poc/copernicus-openwrt/staging_dir/toolchain-i386_i686_gcc-4.8-linaro_glibc-2.21/lib/gcc/i486-openwrt-linux-gnu/4.8.3/../../../../i486-openwrt-linux-gnu/lib/libc.a(iofclose.o): In function `_IO_new_fclose':
iofclose.c:(.text+0x1a6): undefined reference to `_Unwind_Resume'
/home/elison/cop-poc/copernicus-openwrt/staging_dir/toolchain-i386_i686_gcc-4.8-linaro_glibc-2.21/lib/gcc/i486-openwrt-linux-gnu/4.8.3/../../../../i486-openwrt-linux-gnu/lib/libc.a(iofclose.o):(.eh_frame+0x13): undefined reference to `__gcc_personality_v0'
/home/elison/cop-poc/copernicus-openwrt/staging_dir/toolchain-i386_i686_gcc-4.8-linaro_glibc-2.21/lib/gcc/i486-openwrt-linux-gnu/4.8.3/../../../../i486-openwrt-linux-gnu/lib/libc.a(iofflush.o): In function `_IO_fflush':
iofflush.c:(.text+0xe9): undefined reference to `_Unwind_Resume'
/home/elison/cop-poc/copernicus-openwrt/staging_dir/toolchain-i386_i686_gcc-4.8-linaro_glibc-2.21/lib/gcc/i486-openwrt-linux-gnu/4.8.3/../../../../i486-openwrt-linux-gnu/lib/libc.a(iofflush.o):(.eh_frame+0x13): undefined reference to `__gcc_personality_v0'
/home/elison/cop-poc/copernicus-openwrt/staging_dir/toolchain-i386_i686_gcc-4.8-linaro_glibc-2.21/lib/gcc/i486-openwrt-linux-gnu/4.8.3/../../../../i486-openwrt-linux-gnu/lib/libc.a(wfileops.o): In function `_IO_wfile_underflow':
wfileops.c:(.text+0x4e6): undefined reference to `_Unwind_Resume'
/home/elison/cop-poc/copernicus-openwrt/staging_dir/toolchain-i386_i686_gcc-4.8-linaro_glibc-2.21/lib/gcc/i486-openwrt-linux-gnu/4.8.3/../../../../i486-openwrt-linux-gnu/lib/libc.a(wfileops.o):(.eh_frame+0x5b): undefined reference to `__gcc_personality_v0'
/home/elison/cop-poc/copernicus-openwrt/staging_dir/toolchain-i386_i686_gcc-4.8-linaro_glibc-2.21/lib/gcc/i486-openwrt-linux-gnu/4.8.3/../../../../i486-openwrt-linux-gnu/lib/libc.a(fileops.o): In function `_IO_new_file_underflow':
fileops.c:(.text+0x361): undefined reference to `_Unwind_Resume'
/home/elison/cop-poc/copernicus-openwrt/staging_dir/toolchain-i386_i686_gcc-4.8-linaro_glibc-2.21/lib/gcc/i486-openwrt-linux-gnu/4.8.3/../../../../i486-openwrt-linux-gnu/lib/libc.a(fileops.o):(.eh_frame+0xe7): undefined reference to `__gcc_personality_v0'
/home/elison/cop-poc/copernicus-openwrt/staging_dir/toolchain-i386_i686_gcc-4.8-linaro_glibc-2.21/lib/gcc/i486-openwrt-linux-gnu/4.8.3/../../../../i486-openwrt-linux-gnu/lib/libc.a(backtrace.o): In function `backtrace_helper':
backtrace.c:(.text+0x21): undefined reference to `_Unwind_GetIP'
backtrace.c:(.text+0x43): undefined reference to `_Unwind_GetGR'
backtrace.c:(.text+0x4e): undefined reference to `_Unwind_GetCFA'
/home/elison/cop-poc/copernicus-openwrt/staging_dir/toolchain-i386_i686_gcc-4.8-linaro_glibc-2.21/lib/gcc/i486-openwrt-linux-gnu/4.8.3/../../../../i486-openwrt-linux-gnu/lib/libc.a(backtrace.o): In function `__backtrace':
backtrace.c:(.text+0x9a): undefined reference to `_Unwind_Backtrace'
/home/elison/cop-poc/copernicus-openwrt/staging_dir/toolchain-i386_i686_gcc-4.8-linaro_glibc-2.21/lib/gcc/i486-openwrt-linux-gnu/4.8.3/../../../../i486-openwrt-linux-gnu/lib/libc.a(iofputs.o): In function `_IO_fputs':
iofputs.c:(.text+0x107): undefined reference to `_Unwind_Resume'
/home/elison/cop-poc/copernicus-openwrt/staging_dir/toolchain-i386_i686_gcc-4.8-linaro_glibc-2.21/lib/gcc/i486-openwrt-linux-gnu/4.8.3/../../../../i486-openwrt-linux-gnu/lib/libc.a(iofputs.o):(.eh_frame+0x13): undefined reference to `__gcc_personality_v0'
/home/elison/cop-poc/copernicus-openwrt/staging_dir/toolchain-i386_i686_gcc-4.8-linaro_glibc-2.21/lib/gcc/i486-openwrt-linux-gnu/4.8.3/../../../../i486-openwrt-linux-gnu/lib/libc.a(iogetdelim.o): In function `_IO_getdelim':
iogetdelim.c:(.text+0x22b): undefined reference to `_Unwind_Resume'
/home/elison/cop-poc/copernicus-openwrt/staging_dir/toolchain-i386_i686_gcc-4.8-linaro_glibc-2.21/lib/gcc/i486-openwrt-linux-gnu/4.8.3/../../../../i486-openwrt-linux-gnu/lib/libc.a(iogetdelim.o):(.eh_frame+0x13): undefined reference to `__gcc_personality_v0'
/home/elison/cop-poc/copernicus-openwrt/staging_dir/toolchain-i386_i686_gcc-4.8-linaro_glibc-2.21/lib/gcc/i486-openwrt-linux-gnu/4.8.3/../../../../i486-openwrt-linux-gnu/lib/libc.a(fseek.o): In function `fseek':
fseek.c:(.text+0xe2): undefined reference to `_Unwind_Resume'
/home/elison/cop-poc/copernicus-openwrt/staging_dir/toolchain-i386_i686_gcc-4.8-linaro_glibc-2.21/lib/gcc/i486-openwrt-linux-gnu/4.8.3/../../../../i486-openwrt-linux-gnu/lib/libc.a(fseek.o):(.eh_frame+0x13): undefined reference to `__gcc_personality_v0'
/home/elison/cop-poc/copernicus-openwrt/staging_dir/toolchain-i386_i686_gcc-4.8-linaro_glibc-2.21/lib/gcc/i486-openwrt-linux-gnu/4.8.3/../../../../i486-openwrt-linux-gnu/lib/libc.a(ftello.o): In function `__ftello':
ftello.c:(.text+0x13c): undefined reference to `_Unwind_Resume'
/home/elison/cop-poc/copernicus-openwrt/staging_dir/toolchain-i386_i686_gcc-4.8-linaro_glibc-2.21/lib/gcc/i486-openwrt-linux-gnu/4.8.3/../../../../i486-openwrt-linux-gnu/lib/libc.a(ftello.o):(.eh_frame+0x13): undefined reference to `__gcc_personality_v0'
/home/elison/cop-poc/copernicus-openwrt/staging_dir/toolchain-i386_i686_gcc-4.8-linaro_glibc-2.21/lib/gcc/i486-openwrt-linux-gnu/4.8.3/../../../../i486-openwrt-linux-gnu/lib/libc.a(ioseekoff.o): In function `_IO_seekoff':
ioseekoff.c:(.text+0x1ab): undefined reference to `_Unwind_Resume'
/home/elison/cop-poc/copernicus-openwrt/staging_dir/toolchain-i386_i686_gcc-4.8-linaro_glibc-2.21/lib/gcc/i486-openwrt-linux-gnu/4.8.3/../../../../i486-openwrt-linux-gnu/lib/libc.a(ioseekoff.o):(.eh_frame+0x67): undefined reference to `__gcc_personality_v0'
collect2: error: ld returned 1 exit status
我的主机gcc是Debian8上的4.9.2版。
我使用以下配置构建了openwrt工具链:
GCC编译器版本:带有Linaro增强的GCC 4.8.x
C库实现:使用(e)glibc
(e)glibc版本:glibc 2.21
工具链信息:
# staging_dir/toolchain-i386_i686_gcc-4.8-linaro_glibc-2.21/bin/i486-openwrt-linux-gnu-gcc -v
Reading specs from /home/elison/cop-poc/copernicus-openwrt/staging_dir/toolchain-i386_i686_gcc-4.8-linaro_glibc-2.21/lib/gcc/i486-openwrt-linux-gnu/4.8.3/specs
COLLECT_GCC=staging_dir/toolchain-i386_i686_gcc-4.8-linaro_glibc-2.21/bin/i486-openwrt-linux-gnu-gcc
COLLECT_LTO_WRAPPER=/home/elison/cop-poc/copernicus-openwrt/staging_dir/toolchain-i386_i686_gcc-4.8-linaro_glibc-2.21/libexec/gcc/i486-openwrt-linux-gnu/4.8.3/lto-wrapper
Target: i486-openwrt-linux-gnu
Configured with: /home/elison/cop-poc/copernicus-openwrt/build_dir/toolchain-i386_i686_gcc-4.8-linaro_glibc-2.21/gcc-linaro-4.8-2014.04/configure --with-bugurl=https://dev.openwrt.org/ --with-pkgversion='OpenWrt/Linaro GCC 4.8-2014.04 unknown' --prefix=/home/elison/cop-poc/copernicus-openwrt/staging_dir/toolchain-i386_i686_gcc-4.8-linaro_glibc-2.21 --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=i486-openwrt-linux-gnu --with-gnu-ld --enable-target-optspace --disable-libgomp --disable-libmudflap --disable-multilib --disable-nls --with-host-libstdcxx=-lstdc++ --with-gmp=/home/elison/cop-poc/copernicus-openwrt/staging_dir/host --with-mpfr=/home/elison/cop-poc/copernicus-openwrt/staging_dir/host --with-mpc=/home/elison/cop-poc/copernicus-openwrt/staging_dir/host --disable-decimal-float --disable-libssp --enable-__cxa_atexit --with-headers=/home/elison/cop-poc/copernicus-openwrt/staging_dir/toolchain-i386_i686_gcc-4.8-linaro_glibc-2.21/include --disable-libsanitizer --enable-languages=c,c++ --enable-shared --enable-threads --with-slibdir=/home/elison/cop-poc/copernicus-openwrt/staging_dir/toolchain-i386_i686_gcc-4.8-linaro_glibc-2.21/lib
Thread model: posix
gcc version 4.8.3 (OpenWrt/Linaro GCC 4.8-2014.04 unknown)
这里提到的答案没有帮助:
https://stackoverflow.com/a/22774664/879142
添加--enable static as Additional gcc configure选项也没有帮助。
正如互联网上其他地方所发现的,在链接器标志中添加-lgcc_eh也没有帮助。
最佳答案
aarch64 openwrt linux gcc thread.c-static-lpthread-lc-lgcc_eh
作品
关于c - 无法使用Openwrt工具链构建静态二进制文件:对_Unwind_Resume和__gcc_personality_v0的 undefined reference ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40465212/