应用程序无法链接到mysql库(CentOS) [英] app failing to link to mysql libraries (CentOS)

查看:442
本文介绍了应用程序无法链接到mysql库(CentOS)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

链接步骤为我所有的mysql调用获取未定义的引用:

The link step gets undefined references for all my mysql calls:

~/private/WDI/git$ make
c++ -L/usr/lib/x86_64-linux-gnu -lmysqlclient -lpthread -lz -lm -lrt -ldl -o tom tom.o Block.o IPC.o ConnectMxctl.o CI_Metadata.o Log.o
tom.o: In function `connect_to_table_managers()':
/home/chap/private/WDI/git/tom.cpp:128: undefined reference to `mysql_num_rows'
/home/chap/private/WDI/git/tom.cpp:132: undefined reference to `mysql_num_fields'
/home/chap/private/WDI/git/tom.cpp:133: undefined reference to `mysql_fetch_row'
/home/chap/private/WDI/git/tom.cpp:153: undefined reference to `mysql_num_rows'
/home/chap/private/WDI/git/tom.cpp:157: undefined reference to `mysql_fetch_row'
/home/chap/private/WDI/git/tom.cpp:167: undefined reference to `mysql_free_result'

c ++命令中的链接库由mysql_config --libs生成.这是该目录的部分清单:

The link libraries in the c++ command were generated by mysql_config --libs. Here's a partial listing of the directory:

/usr/lib/x86_64-linux-gnu$ ll libmysql*
-rw-r--r-- 1 root root 4838468 Jul 23 23:28 libmysqlclient.a
lrwxrwxrwx 1 root root      16 Jul 23 23:28 libmysqlclient_r.a -> libmysqlclient.a
lrwxrwxrwx 1 root root      17 Jul 23 23:28 libmysqlclient_r.so -> libmysqlclient.so
lrwxrwxrwx 1 root root      20 Jul 23 23:28 libmysqlclient_r.so.18 -> libmysqlclient.so.18
lrwxrwxrwx 1 root root      24 Jul 23 23:28 libmysqlclient_r.so.18.0.0 -> libmysqlclient.so.18.0.0
lrwxrwxrwx 1 root root      20 Jul 23 23:28 libmysqlclient.so -> libmysqlclient.so.18
lrwxrwxrwx 1 root root      24 Jul 23 23:28 libmysqlclient.so.18 -> libmysqlclient.so.18.0.0
-rw-r--r-- 1 root root 3408144 Jul 23 23:28 libmysqlclient.so.18.0.0

所以出现处于适当的位置.为什么这些符号无法解析?

So things appear to be in their proper places. Why would these symbols be unresolvable?

推荐答案

您应该将大多数独立的库放在命令的末尾,以便编译器可以正确找到符号和定义:

You should put most independent library in the end of the command, so compiler can find symbol and definitions properly:

c++ -L/usr/lib/x86_64-linux-gnu -o tom tom.o Block.o IPC.o \
  ConnectMxctl.o CI_Metadata.o Log.o \
  -lmysqlclient -lpthread -lz -lm -lrt -ldl 

通过这种方式,编译器将继续从下一个链接文件中搜索未定义的符号.例如,如果IPO.o使用了CI_Metadata.o中定义的符号(类型/类/结构/函数等),则编译器可以找到它,因为您将CI_Metadata.o放在了IPO.o之后.大多数库都是独立的,这就是为什么它们位于compile/link命令的末尾.

By doing it this way, compiler will continue searching undefined symbols from next linking files. For exampile if IPO.o has uses symbol(type/class/struct/function etc) defined in CI_Metadata.o, compiler can find it because you put CI_Metadata.o after IPO.o. Most libraries are independent, that's why they are in the end of compile/link command.

这篇关于应用程序无法链接到mysql库(CentOS)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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