Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error: Could not compile mysqlclient-sys. #1286

Closed
ziselive opened this issue Oct 31, 2017 · 24 comments
Closed

error: Could not compile mysqlclient-sys. #1286

ziselive opened this issue Oct 31, 2017 · 24 comments
Labels

Comments

@ziselive
Copy link

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

@weiznich
Copy link
Member

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

@weiznich weiznich added the mysql label Nov 7, 2017
@forbjok
Copy link

forbjok commented Dec 3, 2017

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.

@sgrif
Copy link
Member

sgrif commented Dec 3, 2017

We call this out explicitly in the getting started guide

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

@sgrif sgrif closed this as completed Dec 3, 2017
@eastuto
Copy link

eastuto commented Mar 2, 2018

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

@sbwtw
Copy link

sbwtw commented Sep 27, 2018

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.

@shijunti19
Copy link

Windows 10 can't solve this problem.

image

image

image

@weiznich
Copy link
Member

weiznich commented Dec 29, 2018

@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.

@vladinator1000
Copy link

vladinator1000 commented Jun 22, 2019

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?

@weiznich
Copy link
Member

@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.

@SOF3
Copy link

SOF3 commented Jun 29, 2019

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

@deletelog
Copy link

deletelog commented Jul 20, 2019

设置这些环境变量:

  • 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

@jellybobbin
Copy link

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

@shamiao
Copy link

shamiao commented Jul 30, 2019

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.

@ScottHuangZL
Copy link

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

@dataf3l
Copy link

dataf3l commented Dec 3, 2019

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

@StevenInacio
Copy link

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.

@leontoeides
Copy link

leontoeides commented Feb 18, 2023

Re: Diesel CLI on Windows 10 for MySQL. If the above advice doesn't work for you, this worked for me:

  • Install MySQL Server 8.0, not just the connector, sadly.
  • Put the C:\Program Files\MySQL\MySQL Server 8.0\lib (adjust 8.0 version number as needed) in your PATH variable. (MYSQLCLIENT_LIB_DIR environment variable might be necessary too - not sure - but it alone did not do the trick for me.)
  • To avoid complaints about libcrypto-1_1-x64.dll missing, be sure to also add C:\Program Files\MySQL\MySQL Server 8.0\bin to your PATH variable.

This may not be ideal, but it worked for me.

@ShayBox
Copy link

ShayBox commented Mar 13, 2023

I created a guide
The TLDR is that MySQL moved mysqlclient.lib from the C connector to the Server between v6 and v7.
Set MYSQLCLIENT_LIB_DIR to C:\Program Files\MySQL\MySQL Server 8.0\lib

@ORCA-Soft-MiguelAngel
Copy link

I created a guide The TLDR is that MySQL moved mysqlclient.lib from the C connector to the Server between v6 and v7. Set MYSQLCLIENT_LIB_DIR to C:\Program Files\MySQL\MySQL Server 8.0\lib

This worked for me, thanks.

@anuradhaindika83
Copy link

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_DIR with the location C:\Program Files\MySQL\MySQL Server 8.0\lib. Then opened up a new PowerShell session and installed the Diesel-cli. Hopes this helps. Thanks

@bcdlbgm
Copy link

bcdlbgm commented Aug 6, 2023

cargo clean
Setting environment variables in CLion's run configuration, and then running it, should solve the problem.

@moepitman
Copy link

Still no joy. I have MySQL Server 8.0 installed and have set MYSQL_LIB_DIR to C:\Program Files\MySQL\MySQL Server 8.0\lib. I have checked to make sure the mysqlclient.lib file is there.
Next I tried ShayBox's guide, version two, and installed vcpkg. That part worked fine. But when trying to install the libraries, it quickly fails on the first build of boost-atomic:x64-windows, with the error:
Could not find b2 in
C:/ProgramData/vcpkg/vcpkg/installed/x64-windows/tools/boost-build
Any ideas would be appreciated.

@miaomiao1992
Copy link

Re: Diesel CLI on Windows 10 for MySQL. If the above advice doesn't work for you, this worked for me:

  • Install MySQL Server 8.0, not just the connector, sadly.
  • Put the C:\Program Files\MySQL\MySQL Server 8.0\lib (adjust 8.0 version number as needed) in your PATH variable. (MYSQLCLIENT_LIB_DIR environment variable might be necessary too - not sure - but it alone did not do the trick for me.)
  • To avoid complaints about libcrypto-1_1-x64.dll missing, be sure to also add C:\Program Files\MySQL\MySQL Server 8.0\bin to your PATH variable.

This may not be ideal, but it worked for me.

mysql8 does not support x86_64,how to solve this problem?

@mathbigai
Copy link

Hello everybody,
I managed to resolve the issue by doing the following:

  • I installed version 8.0 of MySQL Server;
  • I also installed C Connector in version 6.1;
  • For the Environment variables, I created a User Variable called MYSQLCLIENT_LIB_DIR, informing the location of the MySQL Server installation LIB folder: "C:\Program Files\MySQL\MySQL Server 8.0";
  • Then I created another System Variable called DEP_MYSQLCLIENT_LIB_DIR, informing the location "C:\Program Files\MySQL\MySQL Connector C 6.1\lib\vs14";
  • Then I ran the code cargo install diesel_cli --no-default-features --features mysql in 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests