问题
经常会遇到:
/usr/bin/ld: xxxx.so: undefined reference to `libiconv'
/usr/bin/ld: xxxx.so: undefined reference to `libiconv_close'
/usr/bin/ld: xxxx.so: undefined reference to `libiconv_open'
或者:
./test: error while loading shared libraries: xxxx.so: cannot open shared object file: No such file or directory
查看:
$ ldd test
linux-vdso.so.1 (0x00007ffe09f3e000)
/$LIB/libonion.so => /lib/x86_64-linux-gnu/libonion.so (0x00007fbb415e9000)
xxxx.so => not found
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fbb413ec000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fbb413e6000)
/lib64/ld-linux-x86-64.so.2 (0x00007fbb416f6000)
检查makefile
xxxx.so
工程 makefile
需要添加依赖项 iconv
LIBRARY = -lm -liconv -L/usr/local/lib
编译安装缺少的库 libiconv
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.16.tar.gz
tar zxvf libiconv-1.16.tar.gz
cd libiconv-1.16
./configure --prefix=/usr/local
make
make install
自定义so库建立连接
cp xxxx.so /usr/local/lib
ln -s /usr/local/lib/xxxx.so /usr/lib/xxxx.so