mysql client library_mysqlclient[通俗易懂]

2022-11-01 16:26:22 浏览数 (1)

大家好,又见面了,我是你们的朋友全栈君。

linux下用C语言写MySQL程序,用如下命令编译时出错:

[xitong@localhost mysql]$ gcc -o mysql mysql.c -lmysqlclient

错误如下:

/usr/bin/ld: cannot find -lmysqlclient

collect2: ld 返回 1

解决方法:

用locate命令查找mysqlclient所在目录,如下所示:

[xitong@localhost mysql]$ locate mysqlclient

结果显示:

/usr/local/mysql/lib/mysql/libmysqlclient.a

/usr/local/mysql/lib/mysql/libmysqlclient.la

/usr/local/mysql/lib/mysql/libmysqlclient.so

/usr/local/mysql/lib/mysql/libmysqlclient.so.16

/usr/local/mysql/lib/mysql/libmysqlclient.so.16.0.0

/usr/local/mysql/lib/mysql/libmysqlclient_r.a

/usr/local/mysql/lib/mysql/libmysqlclient_r.la

/usr/local/mysql/lib/mysql/libmysqlclient_r.so

/usr/local/mysql/lib/mysql/libmysqlclient_r.so.16

/usr/local/mysql/lib/mysql/libmysqlclient_r.so.16.0.0

编译时加入路径/usr/local/mysql/lib/mysql,如下:

[xitong@localhost mysql]$ gcc -o mysql mysql.c -L/usr/local/mysql/lib/mysql -lmysqlclient

[xitong@localhost mysql]$

编译通过,问题解决。

再加一点,编译问题解决了,运行的时候发现出现如下错误:

./mysql: error while loading shared libraries: libmysqlclient.so.16: cannot open shared object file: No such file or directory

借用一网友的解决方法,添加环境变量:

[xitong@localhost mysql]$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/mysql/lib/mysql/

再次运行编译好的程序,OK

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

0 人点赞