gpt4 book ai didi

mysql - ld 找不到 libmysqlclient

转载 作者:太空宇宙 更新时间:2023-11-04 06:04:21 25 4
gpt4 key购买 nike

我记得,几年前当我开始使用 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

我不知道还能尝试什么,还能去哪里寻找,希望得到任何指点。

最佳答案

链接器标志应始终在最后指定:

gcc -D_FILE_OFFSET_BITS=64 `mysql_config --cflags` \
-o check-my-ip \
-s check-my-ip.c ../common/ini-file.c \
`mysql_config --libs`

关于mysql - ld 找不到 libmysqlclient,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13221838/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com