【问题标题】:what to do with missing libgcc_s.a缺少 libgcc_s.a 怎么办
【发布时间】:2013-09-19 03:49:19
【问题描述】:

使用外部工具链别名 code sourcery lite 2011 使用 buildroot 交叉编译库,结果

output/host/opt/ext-toolchain/bin/../lib/gcc/arm-none-linux-gnueabi/4.6.1/../../../../arm-none-linux-gnueabi/bin/ld: cannot find -lgcc_s
collect2: ld returned 1 exit status

由于明显缺少libgcc_s.a

# find . -iname "libgcc*"        
./output/host/usr/arm-buildroot-linux-gnueabi/sysroot/lib/libgcc_s.so
./output/host/usr/arm-buildroot-linux-gnueabi/sysroot/lib/libgcc_s.so.1
./output/host/opt/ext-toolchain/arm-none-linux-gnueabi/libc/armv4t/lib/libgcc_s.so.1
./output/host/opt/ext-toolchain/arm-none-linux-gnueabi/libc/armv4t/lib/libgcc_s.so
./output/host/opt/ext-toolchain/arm-none-linux-gnueabi/libc/thumb2/lib/libgcc_s.so.1
./output/host/opt/ext-toolchain/arm-none-linux-gnueabi/libc/thumb2/lib/libgcc_s.so
./output/host/opt/ext-toolchain/arm-none-linux-gnueabi/libc/lib/libgcc_s.so.1
./output/host/opt/ext-toolchain/arm-none-linux-gnueabi/libc/lib/libgcc_s.so
./output/host/opt/ext-toolchain/lib/gcc/arm-none-linux-gnueabi/4.6.1/armv4t/libgcc.a
./output/host/opt/ext-toolchain/lib/gcc/arm-none-linux-gnueabi/4.6.1/armv4t/libgcc_eh.a
./output/host/opt/ext-toolchain/lib/gcc/arm-none-linux-gnueabi/4.6.1/plugin/libgcc
./output/host/opt/ext-toolchain/lib/gcc/arm-none-linux-gnueabi/4.6.1/thumb2/libgcc.a
./output/host/opt/ext-toolchain/lib/gcc/arm-none-linux-gnueabi/4.6.1/thumb2/libgcc_eh.a
./output/host/opt/ext-toolchain/lib/gcc/arm-none-linux-gnueabi/4.6.1/libgcc.a
./output/host/opt/ext-toolchain/lib/gcc/arm-none-linux-gnueabi/4.6.1/libgcc_eh.a

有什么办法可以绕过这个问题,但仍然是静态链接?是否有 CLFAGS 或 LDFLAGS 选项可以静态链接除libgcc_s 之外的所有内容?

到目前为止尝试过的东西(除了阅读 ldgcc 手册页的适用部分):

CFLAGS="-static -static-libgcc"
CFLAGS="-static -shared-libgcc"
CFLAGS="-static -static-libgcc -Wl,-Bstatic"
CFLAGS="-static -shared-libgcc -Wl,-Bstatic"

添加-Wl,-lgcc_s,-Bstatic 后,我得到了大量未定义/未知的符号...(-Bshared 不是一个有效的选项说 ld)

/home/bernhard/buildroot-2013.08/output/target/usr/lib/libgio-2.0.a(libgio_2_0_la-glocalfileinfo.o): In function `_g_local_file_info_get':
glocalfileinfo.c:(.text+0x2d90): warning: Using 'getgrgid' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/home/bernhard/buildroot-2013.08/output/target/usr/lib/libgio-2.0.a(libgio_2_0_la-glocalvfs.o): In function `g_local_vfs_parse_name':
glocalvfs.c:(.text+0x174): warning: Using 'getpwnam' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/home/bernhard/buildroot-2013.08/output/target/usr/lib/libglib-2.0.a(libglib_2_0_la-gutils.o): In function `g_get_user_database_entry':
gutils.c:(.text+0x254): warning: Using 'getpwuid' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
gutils.c:(.text+0x24c): warning: Using 'setpwent' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
gutils.c:(.text+0x25c): warning: Using 'endpwent' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
gutils.c:(.text+0xa0): warning: Using 'getpwnam_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
gutils.c:(.text+0xe0): warning: Using 'getpwuid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/home/bernhard/buildroot-2013.08/output/target/usr/lib/libgio-2.0.a(libgio_2_0_la-gnetworkaddress.o): In function `g_network_address_parse_sockaddr':
gnetworkaddress.c:(.text+0x1ac): warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
<<<< SNIP >>>>
/home/bernhard/buildroot-2013.08/output/target/usr/lib/libxml2.a(xmlschemastypes.o): In function `xmlSchemaGetCanonValue':
xmlschemastypes.c:(.text+0x7680): undefined reference to `trunc'
xmlschemastypes.c:(.text+0x76bc): undefined reference to `trunc'
xmlschemastypes.c:(.text+0x7710): undefined reference to `floor'
xmlschemastypes.c:(.text+0x7760): undefined reference to `floor'
collect2: ld returned 1 exit status

【问题讨论】:

标签: c compilation flags buildroot libgcc


【解决方案1】:

有可能消除libgcc_s.a 的使用以及阻止gcc 使用内部内置函数(例如它的内置memcpy)的标志,但最好通过定位和使用它来为您服务.

看起来这个选项应该阻止使用内置的-fno-builtin。更多详情请看这里:http://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html

与共享的 libgcc_s.so 链接

如果libgcc_s.a 丢失,或者希望将共享 libgcc_s 与其他静态可执行文件一起使用,则应该可以完成这项工作:

CFLAGS="-static -Wl,-Bdynamic,-lgcc_s,-Bstatic"

【讨论】:

  • 以上是 find 在交叉编译器的安装路径中查找 libgcc_s 的输出(是的,它安装在当前工作目录 . 的 buildroot 目录中),因此它只是好像不存在...
  • 嗯,不知何故它跳过了那个。我会尝试gcc -vstrace 来验证它是否正在尝试使用该特定路径。
  • 啊,仔细查看 find 输出 - 那里没有 libgccc_s.a,所以静态链接不起作用。您可以尝试动态链接它 - 我会更新答案以显示如何。
  • 啊,看起来应该是-Bdynamic 不共享。
  • 第一次通过在命令行中放置一个库来决定它的包含方式。如果设置了静态,它必须是静态的,如果是动态的,它可以是动态的或静态的。因此,-Bstatic -lx -Bdynamic -ly 仅将 x 视为静态,而将 y 视为其中之一。通常,为了强制一个库是静态的,我们会使用-Bstatic -lx -Bdynamic,这样它就可以在前后添加其他参数而不会破坏任何内容。
猜你喜欢
  • 1970-01-01
  • 2021-12-03
  • 1970-01-01
  • 2010-10-19
  • 2011-06-01
  • 2021-05-01
  • 2011-07-11
  • 2022-09-25
  • 1970-01-01
相关资源
最近更新 更多