Can't install diesel-cli for MySQL on CentOS 7 with MariaDB


#1

I realize that variations of this question have been asked many times and many places in the past, but I haven’t been able to find a solution to my particular case, and I thought it might be helpful to have it discussed here in the forum, in case it be helpful to someone else in the future.

I have Rust and MariaDB installed on a CentOS 7 (desktop) system. When I try to install diesel-cli for just MySQl with the command:

# cargo install diesel_cli --no-default-features --features mysql

I get the dreaded error:

/usr/bin/ld: cannot find -lmysqlclient

The thing is, there are copies of libmysqlclient on the system. This is what happens when I do a search for them:

# find / -name *libmysqlclient* | egrep -v "gradle|tmp"
/usr/lib64/libmysqlclient.so.15
/usr/lib64/libmysqlclient.so.16.0.0
/usr/lib64/libmysqlclient.so.15.0.0
/usr/lib64/libmysqlclient_r.so.16.0.0
/usr/lib64/libmysqlclient.so.16
/usr/lib64/libmysqlclient.so.18
/usr/lib64/libmysqlclient.so.18.0.0
/usr/lib64/libmysqlclient_r.so.15
/usr/lib64/libmysqlclient_r.so.15.0.0
/usr/lib64/libmysqlclient_r.so.16

Moreover, the directory where these instances of libmysqlclient are located is correctly pointed to by the mysql_config command,

# mysql_config --variable=pkglibdir
/usr/lib64

which, as I understand it, is relied upon during the build of diesel-cli to locate libmysqlclient.

So, does anyone have any ideas as to why diesel-cli won’t build? Any ideas for potential solutions or ways to figure out a solution?

Thanks!

P.S. - In case it might be helpful, here is information about the MariaDB packages I have installed on the system:

yum list installed *mariadb*
Installed Packages
MariaDB-client.x86_64           10.3.13-1.el7.centos           @mariadb
MariaDB-common.x86_64           10.3.13-1.el7.centos           @mariadb
MariaDB-compat.x86_64           10.3.13-1.el7.centos           @mariadb
MariaDB-devel.x86_64            10.3.13-1.el7.centos           @mariadb
MariaDB-server.x86_64           10.3.13-1.el7.centos           @mariadb

#2

I think you may need to tell rustc/the linker explicitly where to find libmysqlclient. See the documentation of mysqlclient-sys for possibilities.


#3

Thanks. However, it’s my understanding from the documentation you linked to that the command:

# mysql_config --variable=pkglibdir

is one of the ways the linker is supposed to determine where libmysqlclient is located. The documentation says:

If the library cannot be found using pkg-config , it will invoke the command mysql_config --variable=pkglibdir

In my case, that mysql_config command gives the right output, namely /usr/lib64, which is where the libmysqlclient files are located on my system (see my original post in this thread). Yet the build of diesel-rs still fails with the error I mentioned.


#4

That not necessarily means that the build will succeed. As far as I can see in the build script mysqlclient-sys first checks for the location via pkg-config and only falls back to mysql_config if that does not return anything.
Please check the output of the pkg-config, mysqlclient-sys build script and the final linker call of rustc.


#5

Thanks again. I’m not sure why the build isn’t getting to the mysql_config config when searching for the library location because using pkg-config should fail. There is no pkg-config information available on my system for mysqlclient, as indicated by this:

# pkg-config --print-variables mysqlclient
Package mysqlclient was not found in the pkg-config search path.
Perhaps you should add the directory containing `mysqlclient.pc'
to the PKG_CONFIG_PATH environment variable
No package 'mysqlclient' found

I guess I could solve the problem by hand building a mysqlclient.pc file on my own, but I’m a bit worried about what might happen if I did that (that is, how it might affect other things beyond the build of diesel-cli).

Unfortunately, this means I’ll have to put off working with diesel for now. I’m a bit surprised this has been an issue, given that MariaDB is the default MySQL implementation on CentOS 7.

Thanks again for your suggestions.


#6

I’ve successfully built diesel_cli on CentOS 7 with the system-supplied versions of MariaDB:

$ yum list installed mariadb\*
Installed Packages
mariadb.x86_64                          1:5.5.60-1.el7_5                   @base
mariadb-devel.x86_64                    1:5.5.60-1.el7_5                   @base
mariadb-libs.x86_64                     1:5.5.60-1.el7_5                   @base
mariadb-server.x86_64                   1:5.5.60-1.el7_5                   @base

With those, pkg-config doesn’t work either, and mysql_config --variable=pkglibdir gives /usr/lib64/mysql.


#7

Just thought I would provide an update for anyone interested.

One suggestion I got in a Reddit thread on this issue was to set the PKG_CONFIG_PATH environment variable to the directory where the file mariadb.pc is located on my system (/usr/share/pkgconfig). I tried that even though the directory is one of the ones that pkg-config checks by default on my system, and I still was not able to build diesel-cli.

I’ve also tried setting a couple of other environment variables such as MYSQLCLIENT_LIB_DIR and MYSQLCLIENT_NO_PKG_CONFIG to get diesel-cli to build, but either I set them wrong, or setting them doesn’t address the root problem, because diesel-cli still would not build.


#8

So I finally was able to build diesel-cli.

The issue that was keeping the build from finishing was that there were no libmysqlclient.so and libmysqlclient_r.so files in the directory where all the libmysqlclient files are located. Once I created these files as symbolic links to the most recent version of libmysqlclient.so, the build was able to finish with no errors.

I believe this problem is more likely to occur if, as is my case, you work with the most recent version of MariaDB from MariaDB, rather than the version that you get through the basic CentOS 7 repository. When I booted up a somewhat older version of CentOS 7 that uses the older version of MariaDB that comes with the distribution, I was able to build diesel-cli without any problems (after installing mariadb-devel). When I compared the libmysqlclient files between the two CentOS7 installations, I found that the new installation was missing the symbolic link files I mentioned earlier.


#9

Thanks. As you can see by my previous post, working with the system-supplied versions of MariaDB on another CentOS 7 system is what helped me figure out why I couldn’t get diesel-cli to build on my system with the latest version of MariaDB from MariaDB. I appreciate your sharing your experience.