我记得,几年前,当我开始使用 mySQL 时,“就这样”设置东西以便找到库(尤其是 mySQL 库!)是一场噩梦。就我而言,我相信 ldconfig 是解决问题的工具。快进到 2012 年——刚刚安装了一个新的“主”系统,其中包括 64 位 Ubuntu 12.04,我正在确保我的所有源代码都能编译。想象一下我很惊讶我又回到了与 libmysqlclient 同一条船上。
我的网络搜索显示了很多可以尝试的内容,但没有任何帮助。一路上,我发现了这个技巧:gcc ... mysql_config --cflags --libs
- 非常好,但这并没有帮助。
因此,例如,结果:
gcc -D_FILE_OFFSET_BITS=64 `mysql_config --cflags --libs` \
-o check-my-ip \
-s check-my-ip.c ../common/ini-file.c
是
/tmp/ccxAgCqr.o: In function `updateTables':
/usr/local/src/check-my-ip/check-my-ip.c:373: undefined reference to `mysql_init'
/usr/local/src/check-my-ip/check-my-ip.c:374: undefined reference to `mysql_real_connect'
/usr/local/src/check-my-ip/check-my-ip.c:381: undefined reference to `mysql_error'
/usr/local/src/check-my-ip/check-my-ip.c:381: undefined reference to `mysql_errno'
/usr/local/src/check-my-ip/check-my-ip.c:397: undefined reference to `mysql_field_count'
/usr/local/src/check-my-ip/check-my-ip.c:398: undefined reference to `mysql_use_result'
/usr/local/src/check-my-ip/check-my-ip.c:399: undefined reference to `mysql_fetch_row'
/usr/local/src/check-my-ip/check-my-ip.c:419: undefined reference to `mysql_free_result'
/usr/local/src/check-my-ip/check-my-ip.c:422: undefined reference to `mysql_field_count'
/usr/local/src/check-my-ip/check-my-ip.c:429: undefined reference to `mysql_close'
/tmp/ccxAgCqr.o: In function `myQuery':
/usr/local/src/check-my-ip/check-my-ip.c:439: undefined reference to `mysql_query'
/usr/local/src/check-my-ip/check-my-ip.c:441: undefined reference to `mysql_error'
/tmp/ccxAgCqr.o: In function `indexExists':
/usr/local/src/check-my-ip/check-my-ip.c:464: undefined reference to `mysql_field_count'
/usr/local/src/check-my-ip/check-my-ip.c:465: undefined reference to `mysql_use_result'
/usr/local/src/check-my-ip/check-my-ip.c:466: undefined reference to `mysql_fetch_row'
/usr/local/src/check-my-ip/check-my-ip.c:471: undefined reference to `mysql_free_result'
collect2: ld returned 1 exit status
make: *** [check-my-ip] Error 1
mysql_config --cflags --libs 的输出是:
-I/usr/include/mysql -DBIG_JOINS=1 -fno-strict-aliasing -g
-L/usr/lib/x86_64-linux-gnu -lmysqlclient -lpthread -lz -lm -lrt -ldl
这些是其他一些可能有助于诊断的命令:
$ ldconfig -p | grep mysql
libmysqlclient.so.18 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libmysqlclient.so.18
libmysqlclient.so (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libmysqlclient.so
$ ls -l /usr/lib/x86_64-linux-gnu/libmysqlclient.so.18
lrwxrwxrwx 1 root root 24 Jun 11 10:21 /usr/lib/x86_64-linux-gnu/libmysqlclient.so.18 -> libmysqlclient.so.18.0.0
$ ls -l /usr/lib/x86_64-linux-gnu/libmysqlclient.so.18.0.0
-rw-r--r-- 1 root root 3408136 Jun 11 10:21 /usr/lib/x86_64-linux-gnu/libmysqlclient.so.18.0.0
我做了一个aptitude search libmysql
并注意到有 37 行,其中大多数具有 i386 名称(例如:libmysqld-pic:i386),我注意到该输出中有零行带有 x86_64(或 -64);这是问题的一部分吗?(这里是那 37 行)
$ aptitude search libmysql
p libmysql++-dev - MySQL C++ library bindings (development)
p libmysql++-dev:i386 - MySQL C++ library bindings (development)
p libmysql++-doc - MySQL C++ library bindings (documentation and exampl
p libmysql++3 - MySQL C++ library bindings (runtime)
p libmysql++3:i386 - MySQL C++ library bindings (runtime)
p libmysql-cil-dev - MySQL database connector for CLI
p libmysql-diff-perl - module for comparing the table structure of two MySQ
p libmysql-java - Java database (JDBC) driver for MySQL
p libmysql-ocaml - OCaml bindings for MySql
p libmysql-ocaml:i386 - OCaml bindings for MySql
p libmysql-ocaml-dev - OCaml bindings for MySql
p libmysql-ocaml-dev:i386 - OCaml bindings for MySql
v libmysql-ocaml-dev-dnim6:i386 -
v libmysql-ocaml-dev-jygp6 -
v libmysql-ocaml-dnim6:i386 -
v libmysql-ocaml-jygp6 -
p libmysql-ruby - Transitional package for ruby-mysql
v libmysql-ruby:i386 -
p libmysql-ruby1.8 - Transitional package for ruby-mysql
v libmysql-ruby1.8:i386 -
p libmysql-ruby1.9.1 - Transitional package for ruby-mysql
v libmysql-ruby1.9.1:i386 -
p libmysql6.4-cil - MySQL database connector for CLI
i libmysqlclient-dev - MySQL database development files
p libmysqlclient-dev:i386 - MySQL database development files
v libmysqlclient15-dev -
v libmysqlclient15-dev:i386 -
i A libmysqlclient18 - MySQL database client library
p libmysqlclient18:i386 - MySQL database client library
p libmysqlcppconn-dev - MySQL Connector for C++ (development files)
p libmysqlcppconn-dev:i386 - MySQL Connector for C++ (development files)
p libmysqlcppconn5 - MySQL Connector for C++ (library)
p libmysqlcppconn5:i386 - MySQL Connector for C++ (library)
i libmysqld-dev - MySQL embedded database development files
p libmysqld-dev:i386 - MySQL embedded database development files
p libmysqld-pic - MySQL database development files
p libmysqld-pic:i386 - MySQL database development files
这是/usr/lib/mysql的内容
$ find /usr/lib/mysql
/usr/lib/mysql
/usr/lib/mysql/plugin
/usr/lib/mysql/plugin/qa_auth_client.so
/usr/lib/mysql/plugin/auth.so
/usr/lib/mysql/plugin/qa_auth_server.so
/usr/lib/mysql/plugin/semisync_master.so
/usr/lib/mysql/plugin/libdaemon_example.so
/usr/lib/mysql/plugin/ha_example.so
/usr/lib/mysql/plugin/adt_null.so
/usr/lib/mysql/plugin/auth_test_plugin.so
/usr/lib/mysql/plugin/auth_socket.so
/usr/lib/mysql/plugin/qa_auth_interface.so
/usr/lib/mysql/plugin/semisync_slave.so
/usr/lib/mysql/plugin/mypluglib.so
我不知道还有什么可以尝试的,还有什么可以看的,并且希望得到任何指示。