链接无法找到符号,但库被读取并且符号存在 [英] Linked cannot find symbols, but libraries are read and symbols exist

查看:203
本文介绍了链接无法找到符号,但库被读取并且符号存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在试图编译我的项目,并且得到未定义的引用错误。例如:

  installertest.cpp :(。text + 0x9d1):未定义对`XmlRpcValue :: makeArray()'的引用
...
installertest.cpp :(。text + 0xede):未定义对`dbcancel'的引用
installertest.cpp :( .text + 0xefd):未定义对`dbfcmd'的引用
installertest.cpp :(。text + 0xf0f):未定义引用`dbsqlexec'
installertest.cpp :(。text + 0xf2d):未定义引用`SHA1_Init'
...

我的命令行是:

  g ++ -o installertest \ 
-lsybdb \
-lxmlrpc \
-lxmlrpc_cpp \
-lxmlrpc_xmlparse \
-lxmlrpc_xmltok \
-lxmlrpc_util \
-lxmlrpc ++ \
-lxmlrpc_server_cgi \
-lssl \
-std = c ++ 0x \
ContractData.o installertest.o

objdump -T 显示符号位于.so文件中。例如:

  libsybdb.so:
...
0000000000011c30 g DF .text 0000000000000083 Base dbcancel
...

/usr/lib/libxmlrpc_cpp.so:
...
0000000000002e78 g DF .text 0000000000000092 Base _ZN11XmlRpcValue9makeArrayEv
...

strace 显示库文件正在打开并由链接器读取:

  ... 
[pid 5019] stat(/ usr / lib / gcc / x86_64-linux-gnu / 4.6 /../../../ x86_64-linux-gnu / libsybdb.so,{st_mode = S_IFREG | 0644,st_size = 421608,...})= 0
[pid 5019] open(/ usr / lib / gcc / x86_64-linux-gnu / 4.6 /../../../ x86_64-linux-gnu / libsybdb.so,O_RDONLY)= 7
$ [pid 5019] fcntl(7,F_GETFD)= 0
[pid 5019] fcntl(7,F_SETFD,FD_CLOEXEC)= 0
[pid 5019] fstat(7,{st_mode = S_IFREG | 0644 ,st_size = 421608,...})= 0
[pid 5019] mmap(NULL,4096,PROT_READ | PROT_WRITE,MAP_PRIVATE | MAP_ANONYMOUS,-1,0)= 0x2b16c200c000
[pid 5019 ] lseek(7,0,SEEK_SET)= 0
[pid 5019] read(7,\177ELF\2\1\1\0\0\0\\\\\ 0\0\0\0\0\3\0> \0\1\0\0\0P\237\0\0\0\0 \0\0...,4096)= 4096
...
[pid 5019] stat(/ usr / lib / gcc / x86_64-linux-gnu / 4.6 / .. /../../../lib/libxmlrpc.so,{st_mode = S_IFREG | 0644,st_size = 80936,...})= 0
[pid 5019] open(/ usr / lib /gcc/x86_64-linux-gnu/4.6/../../../../lib/libxmlrpc.so,O_RDONLY)= 8
[pid 5019] fcntl(8,F_GETFD)= 0
[pid 5019] fcntl(8,F_SETFD,FD_CLOEXEC)= 0
[pid 5019] fstat(8,{st_mode = S_IFREG | 0644,st_size = 80936,...})= 0
[pid 5019] mmap(NULL,4096,PROT_READ | PROT_WRITE,MAP_PRIVATE | MAP_ANONYMOUS,-1,0)= 0x2b16c200d000
[pid 5019] lseek(8,0,SEEK_SET)= 0
[ pid 5019] read(8,\177ELF\2\1\1\0\0\0\\\\\\\\\\ \0> \\ \\ 0 \1\0\\\\\\\\\\\\\\\\',40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 ..

所涉及的所有文件都针对x86-64,C库的标头为 externC。我试过了我能想到的所有东西,但它仍然不会链接。



我甚至尝试删除所有C ++ 11代码并在没有命令行的情况下编译我的系统是 Ubuntu Precise(12.04)64-bit ,使用 g ++(Ubuntu / Linaro 4.6.3 -1ubuntu5)4.6.3 如果有帮助。所有软件包均已从软件包管理器安装,并安装了开发软件包。



编辑(2017-05-30)标记为 https: //stackoverflow.com/questions/45135/why-does-the-order-in-which-libraries-are-linked-sometimes-cause-errors-in-gcc b $ b其他问题问为什么争论的顺序很重要。
当问题被问到时,论据顺序并不是问题

的。

另外,前面的问题不包含任何有用的扩展,而这个问题显示了问题的
出处。

前面的问题可能被看作是对这个问题的答案的有益扩展,但不是重复。

在目标文件之后,库的链接器标记。所以,而不是

  g ++ -o installertest \ 
-lsybdb \
-lxmlrpc \
-lxmlrpc_cpp \
-lxmlrpc_xmlparse \
-lxmlrpc_xmltok \
-lxmlrpc_util \
-lxmlrpc ++ \
-lxmlrpc_server_cgi \
-lssl \
-std = c ++ 0x \
ContractData.o installertest.o

use

  g ++ -o installertest \ 
ContractData.o installertest.o \\ \\
-lsybdb \
-lxmlrpc \
-lxmlrpc_cpp \
-lxmlrpc_xmlparse \
-lxmlrpc_xmltok \
-lxmlrpc_util \
-lxmlrpc ++ \
-lxmlrpc_server_cgi \
-lssl \
-std = c ++ 0x


I've been trying to compile my project and I'm getting undefined reference errors. eg.:

installertest.cpp:(.text+0x9d1): undefined reference to `XmlRpcValue::makeArray()'
...
installertest.cpp:(.text+0xede): undefined reference to `dbcancel'
installertest.cpp:(.text+0xefd): undefined reference to `dbfcmd'
installertest.cpp:(.text+0xf0f): undefined reference to `dbsqlexec'
installertest.cpp:(.text+0xf2d): undefined reference to `SHA1_Init'
...

My command-line is:

g++ -o installertest \
    -lsybdb \
    -lxmlrpc \
    -lxmlrpc_cpp \
    -lxmlrpc_xmlparse \
    -lxmlrpc_xmltok \
    -lxmlrpc_util \
    -lxmlrpc++ \
    -lxmlrpc_server_cgi \
    -lssl \
    -std=c++0x \
    ContractData.o installertest.o

objdump -T shows that the symbols are in the .so file. eg.:

libsybdb.so:
...
0000000000011c30 g    DF .text  0000000000000083  Base        dbcancel
...

/usr/lib/libxmlrpc_cpp.so:
...
0000000000002e78 g    DF .text  0000000000000092  Base        _ZN11XmlRpcValue9makeArrayEv
...

strace shows that the library files are being opened and read by the linker:

...
[pid  5019] stat("/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/libsybdb.so", {st_mode=S_IFREG|0644, st_size=421608, ...}) = 0
[pid  5019] open("/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/libsybdb.so", O_RDONLY) = 7
[pid  5019] fcntl(7, F_GETFD)           = 0
[pid  5019] fcntl(7, F_SETFD, FD_CLOEXEC) = 0
[pid  5019] fstat(7, {st_mode=S_IFREG|0644, st_size=421608, ...}) = 0
[pid  5019] mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x2b16c200c000
[pid  5019] lseek(7, 0, SEEK_SET)       = 0
[pid  5019] read(7, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0P\237\0\0\0\0\0\0"..., 4096) = 4096
...
[pid  5019] stat("/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../lib/libxmlrpc.so", {st_mode=S_IFREG|0644, st_size=80936, ...}) = 0
[pid  5019] open("/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../lib/libxmlrpc.so", O_RDONLY) = 8
[pid  5019] fcntl(8, F_GETFD)           = 0
[pid  5019] fcntl(8, F_SETFD, FD_CLOEXEC) = 0
[pid  5019] fstat(8, {st_mode=S_IFREG|0644, st_size=80936, ...}) = 0
[pid  5019] mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x2b16c200d000
[pid  5019] lseek(8, 0, SEEK_SET)       = 0
[pid  5019] read(8, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\300?\0\0\0\0\0\0"..., 4096) = 4096
...

All files involved are targeted to x86-64 and the header for the C libraries are extern "C". I have tried everything I can think of and it still won't link.

I've even tried removing all C++11 code and compiling without the command-line switch, still nothing.

My system is Ubuntu Precise (12.04) 64-bit using g++ (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3 if that helps. All packages were installed from the package manager and development packages are installed.

Edit (2017-05-30): Marked as duplicate of https://stackoverflow.com/questions/45135/why-does-the-order-in-which-libraries-are-linked-sometimes-cause-errors-in-gcc
Other question asks why order of arguments is important. Argument order was not known to be an issue when question was asked.
Also, previous question does not contain any helpful expansion, whereas this question shows the issue at hand.
Previous question may be seen as a helpful expansion on the answer to this one, but not a duplication.

解决方案

You have to put the libraries' linker flags after the object files. So, instead of

g++ -o installertest \
-lsybdb \
-lxmlrpc \
-lxmlrpc_cpp \
-lxmlrpc_xmlparse \
-lxmlrpc_xmltok \
-lxmlrpc_util \
-lxmlrpc++ \
-lxmlrpc_server_cgi \
-lssl \
-std=c++0x \
ContractData.o installertest.o

use

g++ -o installertest \
ContractData.o installertest.o \
-lsybdb \
-lxmlrpc \
-lxmlrpc_cpp \
-lxmlrpc_xmlparse \
-lxmlrpc_xmltok \
-lxmlrpc_util \
-lxmlrpc++ \
-lxmlrpc_server_cgi \
-lssl \
-std=c++0x

这篇关于链接无法找到符号,但库被读取并且符号存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆