diesel: error: Could not compile `mysqlclient-sys`.
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
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 24 (4 by maintainers)
for anyone wanting to actually use MySQL and who is having issues running cargo install, just to clarify adding the location of
mysqlclient.libto your environment variables will fix this.E.g.
MYSQLCLIENT_LIB_DIR=C:\Program Files\MySQL\MySQL Connector C 6.1\lib\vs14Tips: if you build failed and follow this issue to change your environment variable, you should execute
cargo cleanbefore next build. seems cargo not re-run build script if you continue last build, and it will always get an error.设置这些环境变量:
在命令提示符或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中的位置更改路径:
删除:C:\Users**\AppData\Local\Temp\cargo-insta 文件
cargo install diesel_cliFor 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.
Please download mysqlclient from: https://downloads.mysql.com/archives/c-c/
I tried everything – adding mysqlclient.lib to $PATH, passing -L… but it is still not compiling.
This works. Note: use
cargo clean -p mysqlclient-systo only clean mysql client crate.We call this out explicitly in the getting started guide
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 postgresbe 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?I created a guide
The TLDR is that MySQL moved
mysqlclient.libfrom the C connector to the Server between v6 and v7.Set
MYSQLCLIENT_LIB_DIRtoC:\Program Files\MySQL\MySQL Server 8.0\libThis worked for me, thanks.
for those people on osx brew install mysql did the trick for me
@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.
Windows 10 can’t solve this problem.
Hello everybody, I managed to resolve the issue by doing the following:
MYSQLCLIENT_LIB_DIR, informing the location of the MySQL Server installation LIB folder: “C:\Program Files\MySQL\MySQL Server 8.0”;DEP_MYSQLCLIENT_LIB_DIR, informing the location “C:\Program Files\MySQL\MySQL Connector C 6.1\lib\vs14”;cargo install diesel_cli --no-default-features --features mysqlin PowerShell. I ran it as administrator.Just pointing out that some of these steps may not be necessary, but I didn’t have time to test each one more carefully.
cargo clean Setting environment variables in CLion’s run configuration, and then running it, should solve the problem.
I’m using Windows 11. In my case, I installed the latest MySQL server with the C/C++ connector. Then set an environment variable
MYSQLCLIENT_LIB_DIRwith the locationC:\Program Files\MySQL\MySQL Server 8.0\lib. Then opened up a new PowerShell session and installed the Diesel-cli. Hopes this helps. Thanks