Linux ld链接问题

我在编译一个执行文件的时候需要链接两个库文件 libfilelist.so和libsqlite3.so。其中libfilelist.so为自己编译出来的库文件。libsqlite3.so为SQLite3库文件,

这两个文件都存在,而且链接的路径也已经修改(/etc/ld.so.conf.d/中添加了libfilelist.so路径),链接时也成功。如

#gcc -o main main.c -I../inc -L../lib -lfilelist -lsqlite3

编译链接成功,但是执行的时候出问题

./main: symbol lookup error: /home/pyc/myWorkspace/filelist/lib/libfilelist.so: undefined symbol: sqlite3_open

# ldd main
linux-gate.so.1 =>  (0xb77c6000)
libfilelist.so => /home/pyc/myWorkspace/filelist/lib/libfilelist.so (0xb7780000)
libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xb75d6000)
/lib/ld-linux.so.2 (0xb77c7000)

发现成功链接了libfilelist.so文件,但是libsqlite3.so没有链接上。

ldd -r main
undefined symbol: sqlite3_open (/home/pyc/myWorkspace/filelist/lib/libfilelist.so)
linux-gate.so.1 =>  (0xb7782000)
libfilelist.so => /home/pyc/myWorkspace/filelist/lib/libfilelist.so (0xb773c000)
libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xb7592000)
/lib/ld-linux.so.2 (0xb7783000)
undefined symbol: sqlite3_errmsg (/home/pyc/myWorkspace/filelist/lib/libfilelist.so)
undefined symbol: sqlite3_prepare_v2 (/home/pyc/myWorkspace/filelist/lib/libfilelist.so)
undefined symbol: sqlite3_column_int (/home/pyc/myWorkspace/filelist/lib/libfilelist.so)
undefined symbol: sqlite3_step (/home/pyc/myWorkspace/filelist/lib/libfilelist.so)
undefined symbol: sqlite3_reset (/home/pyc/myWorkspace/filelist/lib/libfilelist.so)
undefined symbol: sqlite3_clear_bindings (/home/pyc/myWorkspace/filelist/lib/libfilelist.so)
undefined symbol: sqlite3_finalize (/home/pyc/myWorkspace/filelist/lib/libfilelist.so)
undefined symbol: sqlite3_column_blob (/home/pyc/myWorkspace/filelist/lib/libfilelist.so)
undefined symbol: sqlite3_column_text (/home/pyc/myWorkspace/filelist/lib/libfilelist.so

发现因为没有链接libsqlite3.so所以导致了很多的函数没有找到定义。这其中原因应该是Ubuntu上安装了binutils-gold,执行ld -v可以看到不一样的地方

#ld -v

GNU gold (GNU Binutils for Ubuntu 2.22) 1.11

正常机器是

#ld -v

GNU ld (GNU Binutils for Ubuntu) 2.22

这应该安装了binutils-gold之后导致了ld链接出了问题。所以我们将binutils-gold删除掉即可。

#sudo apt-get remove binutils-gold

再重新编译执行,OK了


本文参考:http://stackoverflow.com/questions/14405601/gnu-scientific-library-cblas-symbol-lookup-error



你可能感兴趣的:(Linux ld链接问题)