I am getting this:
我得到这个:
./ListBench: symbol lookup error: /usr/lib/libfoo.so: undefined symbol: memset, version GLIBC_2.2.5
./ListBench:符号查找错误:/usr/lib/libfoo.so:未定义符号:memset,版本GLIBC_2.2.5
Why is memset undefined in libc.so?
为什么在libc.so中未定义memset?
# ldd /usr/lib/foo.so
linux-vdso.so.1 => (0x00007fff167ff000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f2f907eb000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f2f905e3000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f2f903c6000)
/lib64/ld-linux-x86-64.so.2 (0x00007f2f90d86000)
# nm /lib/x86_64-linux-gnu/libc.so.6 | grep memset
nm: /lib/x86_64-linux-gnu/libc.so.6: no symbols
# objdump -T /lib/x86_64-linux-gnu/libc.so.6 | grep memset
00000000000904e0 g DF .text 0000000000000066 GLIBC_2.2.5 wmemset
00000000000f0620 g DF .text 0000000000000017 GLIBC_2.4 __wmemset_chk
0000000000083690 g iD .text 0000000000000029 GLIBC_2.2.5 memset
00000000000ecec0 g iD .text 0000000000000029 GLIBC_2.3.4 __memset_chk
# ldd --version
ldd (Debian EGLIBC 2.13-38) 2.13
foo.so is compiled using
foo.so是使用编译的
gcc -shared -g -std=gnu99 -pedantic -fPIC -Wall -Wno-unused -fno-strict-aliasing -o libfoo.so sync.o ksnap.o time_util.o bitmap.o -lc -pthread -lrt;
2 个解决方案
#1
1
look for dynamic symbols, e.g.
寻找动态符号,例如
nm -D /lib/x86_64-linux-gnu/libc.so.6 | grep memset
00000000000fb210 i __memset_chk
00000000000fe910 T __wmemset_chk
0000000000086c30 i memset
000000000009cb00 T wmemset
and quite often (depending upon optimization level and compiler used when compiling your /usr/lib/foo.so
shared object) memset
could either be inlined or magically compiled as __builtin_memset
(see other builtins of GCC). On my Debian/Sid/x86-64 memset
is a macro in /usr/include/bits/string.h
included from <string.h>
并且经常(取决于编译/usr/lib/foo.so共享对象时使用的优化级别和编译器)memset可以内联或神奇地编译为__builtin_memset(参见GCC的其他内置函数)。在我的Debian / Sid / x86-64 memset上,来自
Check carefully that you have indeed #include<string.h>
in every C source file calling memset
... Don't forget to always pass -Wall
to gcc
(it would warn if you forgot the inclusion)...
仔细检查你在调用memset的每个C源文件中确实有#include
#2
0
The problem was a wrong order of linking options (-lfoo had to be last). Reordering them solved the problem.
问题是链接选项的顺序错误(-lfoo必须是最后一个)。重新排序它们解决了这个问题。
#1
1
look for dynamic symbols, e.g.
寻找动态符号,例如
nm -D /lib/x86_64-linux-gnu/libc.so.6 | grep memset
00000000000fb210 i __memset_chk
00000000000fe910 T __wmemset_chk
0000000000086c30 i memset
000000000009cb00 T wmemset
and quite often (depending upon optimization level and compiler used when compiling your /usr/lib/foo.so
shared object) memset
could either be inlined or magically compiled as __builtin_memset
(see other builtins of GCC). On my Debian/Sid/x86-64 memset
is a macro in /usr/include/bits/string.h
included from <string.h>
并且经常(取决于编译/usr/lib/foo.so共享对象时使用的优化级别和编译器)memset可以内联或神奇地编译为__builtin_memset(参见GCC的其他内置函数)。在我的Debian / Sid / x86-64 memset上,来自
Check carefully that you have indeed #include<string.h>
in every C source file calling memset
... Don't forget to always pass -Wall
to gcc
(it would warn if you forgot the inclusion)...
仔细检查你在调用memset的每个C源文件中确实有#include
#2
0
The problem was a wrong order of linking options (-lfoo had to be last). Reordering them solved the problem.
问题是链接选项的顺序错误(-lfoo必须是最后一个)。重新排序它们解决了这个问题。