全网首发:终极解决办法:/usr/bin/ld: libcc.so: no symbol version section for versioned symbol `memcpy@GLIBC_2.0‘

简介: 全网首发:终极解决办法:/usr/bin/ld: libcc.so: no symbol version section for versioned symbol `memcpy@GLIBC_2.0‘

  具体错误:

       [cc] Starting link
       [cc] /usr/bin/ld: libtest1.so: no symbol version section for versioned symbol `memcpy@GLIBC_2.0'
       [cc] /usr/bin/ld: 最后的链结失败: nonrepresentable section on output
       [cc] collect2: error: ld returned 1 exit status

  关于此类错误,吾有不少博文。这意思就是没有这个函数。具体来说:

tsit@tsit-loong:~/jogamp232-loongarch64/gluegen$ strings /usr/lib/loongarch64-linux-gnu/libc.so.6 | grep GLIBCGLIBC_2.27
GLIBC_2.28
GLIBC_PRIVATE
GNU C Library (Debian GLIBC 2.28-10.lnd.26) stable release version 2.28.
sit@tsit-loong:~/jogamp232-loongarch64/gluegen$ objdump -T /usr/lib/loongarch64-linux-gnu/libc.so.6 | fgrep memcpy
000000000008d328  w   DF .text  0000000000000008  GLIBC_2.27  wmemcpy
00000000000eeb78 g    DF .text  000000000000001c  GLIBC_2.27  __wmemcpy_chk
0000000000086588 g    DF .text  00000000000003f4  GLIBC_2.27  memcpy
00000000000ed228 g    DF .text  0000000000000014  GLIBC_2.27  __memcpy_chk

也就是链接时要求使用2.0,实际上是2.27。

  • 解决办法一

加链接库,下文中三个逐个加试试:

g++ -o  main main.c -lm -ldl -lrt

有时确实可以解决问题。

  • 解决办法二
g++ -Wl,--no-as-needed  -o  main main.c -lm -ldl -lrt
  • 终极解决办法

     回到问题本身。我们平常调用函数memcpy,不管怎么编译,并不会出现这个问题。出问题的都是下载的源码编译时。这就有意思了,为什么会出现这个错误?一定是代码写法不同导致的。


    基于这个思路,我们来搜索一下GLIBC,果然发现了一个文件glibc-compat-symbols.h,内容是:

#ifndef __GLIBC_COMPAT_SYMBOLS_H__
#define __GLIBC_COMPAT_SYMBOLS_H__ 1
/**
 *
 * Note: Patching a specific glibc symbol version is only required if *not* statically linking glibc,
 *       which should be preferred.
 *
 * Note: JogAmp's minimum GLIBC is 2.4 due to '__stack_chk_fail' (stack overflow checking)
 *   
 *   GLIBC 2.4 - March 2006  - Standard for LSB 4.0, Used in SLES 10
 *   
 * We could add compile/link option '-fno-stack-protector', however stack protection seems reasonable
 * and a pre 2006 distribution a bit too 'far fetched' for our multimedia bindings anyway.
 *
 * Check build-in macro definitions via 'gcc -dM -E - < /dev/null'
 */
#if defined(__linux__) /* Actually we like to test whether we link against GLIBC .. */
    #if defined(__GNUC__)
        #if defined(__aarch64__)
           #define GLIBC_COMPAT_SYMBOL(FFF) __asm__(".symver " #FFF "," #FFF "@GLIBC_2.4");
        #elif defined(__arm__)
           #define GLIBC_COMPAT_SYMBOL(FFF) __asm__(".symver " #FFF "," #FFF "@GLIBC_2.4");
        #elif defined(__amd64__)
           #define GLIBC_COMPAT_SYMBOL(FFF) __asm__(".symver " #FFF "," #FFF "@GLIBC_2.2.5");
        #else
           #define GLIBC_COMPAT_SYMBOL(FFF) __asm__(".symver " #FFF "," #FFF "@GLIBC_2.0");
        #endif /*__amd64__*/
    #elif defined(__clang__)
        #if defined(__aarch64__)
           #define GLIBC_COMPAT_SYMBOL(FFF) asm(".symver " #FFF "," #FFF "@GLIBC_2.4");
        #elif defined(__arm__)
           #define GLIBC_COMPAT_SYMBOL(FFF) asm(".symver " #FFF "," #FFF "@GLIBC_2.4");
        #elif defined(__amd64__)
           #define GLIBC_COMPAT_SYMBOL(FFF) asm(".symver " #FFF "," #FFF "@GLIBC_2.2.5");
        #else
           #define GLIBC_COMPAT_SYMBOL(FFF) asm(".symver " #FFF "," #FFF "@GLIBC_2.0");
        #endif /*__amd64__*/
    #else
        #warning GLIBC_COMPAT_SYMBOL not supported with current compiler on GNU/Linux
        #define GLIBC_COMPAT_SYMBOL(FFF)
    #endif
#else
    #warning GLIBC_COMPAT_SYMBOL not supported with target OS
    #define GLIBC_COMPAT_SYMBOL(FFF)
#endif
GLIBC_COMPAT_SYMBOL(memcpy)
#endif /*__GLIBC_COMPAT_SYMBOLS_H__*/


其中果然有一个字串叫GLIBC_2.0。这不就好办了嘛。

办法一:把2.0改成2.27(或相应的字串)。

办法二:干脆改为""。这样到哪里编译都皆大欢喜。

目录
相关文章
|
iOS开发
Xcode报错解决方法:ld: symbol(s) not found for architecture arm64
Xcode报错解决方法:ld: symbol(s) not found for architecture arm64
3345 0
MAC编译lame ld: symbol(s) not found for architecture x86_64/_lame_init_old“, referenced from
MAC编译lame ld: symbol(s) not found for architecture x86_64/_lame_init_old“, referenced from
293 0
缺少链接库报错:ld: symbol(s) not found for architecture x86_64
缺少链接库报错:ld: symbol(s) not found for architecture x86_64
258 0
|
Perl
ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1
ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1
728 0
MAC编译lame ld: symbol(s) not found for architecture x86_64/_lame_init_old“, referenced from
MAC编译lame ld: symbol(s) not found for architecture x86_64/_lame_init_old“, referenced from
461 0
|
8月前
|
JavaScript 前端开发
ES6:什么是Symbol?
ES6:什么是Symbol?
98 1
|
8月前
ES6之Symbol
ES6之Symbol
|
8月前
|
JavaScript 前端开发
|
8月前
|
JavaScript 前端开发 开发者
|
2月前
|
设计模式 JavaScript 前端开发
es6加上symbol的基础数据类型
【10月更文挑战第30天】ES6 中的 `Symbol` 作为一种新的基础数据类型,为 JavaScript 提供了一种创建唯一标识符和处理对象属性名冲突的有效方式,丰富了 JavaScript 的数据类型体系和编程模式,在实际开发中具有重要的应用价值。