为什么编译过程报“/usr/bin/ld: cannot find -lmysqlclient”

Why does the compilation process report "/usr/bin/ld: cannot find -lmysqlclient"

提问人:wu jiqiang 提问时间:10/15/2023 更新时间:10/15/2023 访问量:26

问:

libmysqlclient 已包含在 “/usr/lib64/” 中,例如:

sudo find / -name 'libmysqlclient*'
/usr/lib64/mysql/libmysqlclient_r.so
/usr/lib64/mysql/libmysqlclient.so.18
/usr/lib64/mysql/libmysqlclient.so.18.0.0
/usr/lib64/mysql/libmysqlclient.so

链接器的搜索路径包含“/usr/lib64”,例如:

ld --verbose | grep SEARCH_DIR
SEARCH_DIR("=/usr/x86_64-redhat-linux/lib64"); SEARCH_DIR("=/usr/lib64"); SEARCH_DIR("=/usr/local/lib64"); SEARCH_DIR("=/lib64"); SEARCH_DIR("=/usr/x86_64-redhat-linux/lib"); SEARCH_DIR("=/usr/local/lib"); SEARCH_DIR("=/lib"); SEARCH_DIR("=/usr/lib");

为什么编译命令仍然报错?

g++ -o server  main.cpp timer/lst_timer.cpp http/http_conn.cpp log/log.cpp CGImysql/sql_connection_pool.cpp webserver.cpp config.cpp -g -lpthread -lmysqlclient
/usr/bin/ld: cannot find -lmysqlclient
collect2: error: ld returned 1 exit status
make: *** [server] Error 1

我根据gpt的提示尝试了以下命令,但没有一个有效。

“将编译命令中的-lmysqlclient更改为-lmariadb或-lmariadbclient”

C 生成文件 G++ 链接器错误

评论

0赞 wu jiqiang 10/15/2023
linux版本为CentOS7
1赞 Some programmer dude 10/15/2023
/usr/lib64在公共库搜索路径中,但不是。链接器搜索子目录。Add 以添加路径。/usr/lib64/mysql-L/usr/lib64/mysql

答: 暂无答案