Diesel: error: Could not compile `mysqlclient-sys`.

Created on 31 Oct 2017  ·  16Comments  ·  Source: diesel-rs/diesel

cargo install diesel_cli, error:

error: could not find native static library mysqlclient, maybe an -L flag is missing?

error: Could not compile mysqlclient-sys.

……………………
mysql version 5.7
win7 x64
rust 1.22.0-nightly

mysql

Most helpful comment

for anyone wanting to actually use MySQL and who is having issues running cargo install, just to clarify adding the location of mysqlclient.lib to your environment variables will fix this.

E.g.

MYSQLCLIENT_LIB_DIR=C:\Program Files\MySQL\MySQL Connector C 6.1\lib\vs14

All 16 comments

Try setting MYSQLCLIENT_LIB_DIR to point to the directory where mysqlclient.dll is stored.

I'm having the same issue on Windows 10 x64.
I don't have MySQL in any shape or form installed, and I have no intention of using it.
This seems like it should be an optional component only required if you are actually using MySQL.

UPDATE:
I tried installing the MySQL C connector from mysql.com, pointing MYSQLCLIENT_LIB_DIR to it, and even renaming the libmysql.dll and .lib files to libmysqlclient.* like the package seems to expect, but it did not work.

However, it's possible to disable building the MySQL support by specifing "--no-default-features --features postgres" on the cargo commandline, so if you aren't using MySQL that would solve this particular issue. Now I'm getting a linking error on libpq.lib instead. (presumably unrelated to this issue)

UPDATE 2:
Fixed that last problem by setting the PQ_LIB_DIR environment variable to Postgresql's lib directory.

We call this out explicitly in the getting started guide

screen shot 2017-12-03 at 1 24 56 pm

for anyone wanting to actually use MySQL and who is having issues running cargo install, just to clarify adding the location of mysqlclient.lib to your environment variables will fix this.

E.g.

MYSQLCLIENT_LIB_DIR=C:\Program Files\MySQL\MySQL Connector C 6.1\lib\vs14

Tips:
if you build failed and follow this issue to change your environment variable, you should execute cargo clean before next build.
seems cargo not re-run build script if you continue last build, and it will always get an error.

Windows 10 can't solve this problem.

image

image

image

@shijunti19 That's certainly a configuration issue because it's working on our CI. See the CI setup for an example how to set those variables.

The way the getting started docs are set up will fail for many first time users. We might be better off just having cargo install diesel_cli --no-default-features --features postgres be the default one and moving the mysql-requiring thing in "A Note on Installing diesel_cli"

I think this will be a much better first experience. We shouldn't force people to install mysql like that because we can't assume what database they want to use. Maybe we can prompt for what database driver they want on cargo install diesel_cli?

@savovs I don't think its a good idea to simplify the setup of one supported back end at the cost of making the setup of the other two targets more difficult.

I tried everything -- adding mysqlclient.lib to $PATH, passing -L... but it is still not compiling.
image

设置这些环境变量:

  • PQ_LIB_DIR
  • SQLITE3_LIB_DIR
  • MYSQLCLIENT_LIB_DIR

在命令提示符或PowerShell中输入以下内容:

`
setx PQ_LIB_DIR "C:\Program Files\PostgreSQL\10\lib"
[...]

setx SQLITE3_LIB_DIR "C:\SQLite"
[...]

setx MYSQLCLIENT_LIB_DIR "C:\Program Files\MySQL\MySQL Connector C 6.1\lib\vs14"
[...]
`

注意:您可能必须根据这些文件在PC中的位置更改路径:

  • libpq.lib
  • sqlite.lib
  • mysqlclient.lib

删除:C:\Users**\AppData\Local\Temp\cargo-insta 文件

cargo install diesel_cli

image

I'm having the same issue on Windows 7 x64.

Tips:
if you build failed and follow this issue to change your environment variable, you should execute cargo clean before next build.
seems cargo not re-run build script if you continue last build, and it will always get an error.

This works. Note: use cargo clean -p mysqlclient-sys to only clean mysql client crate.

Please download mysqlclient from: https://downloads.mysql.com/archives/c-c/

for those people on osx brew install mysql did the trick for me

For those that still have errors on Windows, you need to install the MySQL Server (but you can skip/cancel the configuration if you do not actually want to run a server).
The Library should now be under C:\Program Files\MySQL\MySQL Server <mysql_version>\lib\mysqlclient.lib.

I don't know if the old library in the connector/c archive is the same than this library, but the server version worked for me.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pjenvey picture pjenvey  ·  4Comments

jimmycuadra picture jimmycuadra  ·  3Comments

kollapsderwellenfunktion picture kollapsderwellenfunktion  ·  4Comments

Fuckoffee picture Fuckoffee  ·  3Comments

mattico picture mattico  ·  4Comments