diesel: Installing diesel_cli on Windows : some assembly required
Hello
I was about to do the Diesel tutorial, but had to do some unexpected work at the “install diesel_cli” step, in order to make diesel_cli actually compile.
The command I wanted to run is: rustup run nightly cargo install diesel_cli
My environment is a Windows 10 x64 with VS14 installed, as well as PostgreSQL 9.6 (installed with the official installer) and the SQlite .dll and .def that I manually downloaded and put into some folder.
While I had several errors, they were all pretty similar to this one (missing .lib input files):
Compiling diesel_cli v0.8.0
Running `rustc D:\\Users\\Shtong\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\diesel_cli-0.8.0\\src\\main.rs --crate-name diesel --crate-type bin -C opt-level=3 --cfg feature=\"postgres\" --cfg feature=\"default\" --cfg feature=\"sqlite\" --cfg feature=\"diesel\" -C metadata=29283389226be5db --out-dir D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release --emit=dep-info,link -L dependency=D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps --extern chrono=D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps\\libchrono-7342810e34d1c30d.rlib --extern diesel=D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps\\libdiesel-759af232b86b362b.rlib --extern clap=D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps\\libclap-8f0c0e13919e3e65.rlib --extern dotenv=D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps\\libdotenv-695bff8444756e3d.rlib -L D:\\Programs\\Sqlite3`
error: linking with `link.exe` failed: exit code: 1181
|
= note: "D:\\Programs\\VisualStudio14\\VC\\bin\\amd64\\link.exe" "/LIBPATH:D:\\Programs\\VisualStudio14\\VC\\lib\\amd64" "/LIBPATH:C:\\Program Files (x86)\\Windows Kits\\10\\lib\\10.0.10240.0\\ucrt\\x64" "/LIBPATH:C:\\Program Files (x86)\\Windows Kits\\8.1\\lib\\winv6.3\\um\\x64" "/NOLOGO" "/NXCOMPAT" "/LIBPATH:D:\\Users\\Shtong\\.multirust\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\diesel.0.o" "/OUT:D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\diesel.exe" "/OPT:REF,ICF" "/DEBUG" "/LIBPATH:D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps" "/LIBPATH:D:\\Programs\\Sqlite3" "/LIBPATH:D:\\Users\\Shtong\\.multirust\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps\\libchrono-7342810e34d1c30d.rlib" "D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps\\libdiesel-759af232b86b362b.rlib" "D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps\\libbyteorder-f3f7821512ca2fd0.rlib" "D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps\\libtime-750bfdd52feafcb7.rlib" "D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps\\libpq_sys-d9fc24829db90d4f.rlib" "D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps\\liblibsqlite3_sys-755891849c290f5c.rlib" "D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps\\libnum-1fa4854b44bb6a54.rlib" "D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps\\libnum_iter-50df698bc905252c.rlib" "D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps\\libnum_integer-52fdddf28cd8e924.rlib" "D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps\\libnum_traits-92bb90166cd1857c.rlib" "D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps\\libdotenv-695bff8444756e3d.rlib" "D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps\\libregex-19c946c0da62af0b.rlib" "D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps\\libutf8_ranges-5c6a6dacba3be7ce.rlib" "D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps\\libregex_syntax-c54ab5597cd8541d.rlib" "D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps\\libaho_corasick-d1dfd931d7cac82f.rlib" "D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps\\libmemchr-c555f740a543880f.rlib" "D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps\\libclap-8f0c0e13919e3e65.rlib" "D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps\\libunicode_segmentation-e3fd0169850011a0.rlib" "D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps\\libterm_size-9fd23557733de795.rlib" "D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps\\libvec_map-d843695eff67d492.rlib" "D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps\\libbitflags-0e272044714c8076.rlib" "D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps\\libunicode_width-bcfd50e6d35d16e0.rlib" "D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps\\liblibc-ad32fde1bd850538.rlib" "D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps\\libansi_term-aa5dcc2affa8dc75.rlib" "D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps\\libstrsim-b42a694875d9a3b0.rlib" "D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps\\libthread_local-a3c0092e9fb6507d.rlib" "D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps\\libthread_id-bcd46c79a620a618.rlib" "D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps\\libkernel32-df86a08647459244.rlib" "D:\\Users\\Shtong\\AppData\\Local\\Temp\\cargo-install.6Y8hTMX3pHdT\\release\\deps\\libwinapi-0889532d327ff4e2.rlib" "D:\\Users\\Shtong\\.multirust\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libstd-6eb85298.rlib" "D:\\Users\\Shtong\\.multirust\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libpanic_unwind-6eb85298.rlib" "D:\\Users\\Shtong\\.multirust\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libunwind-6eb85298.rlib" "D:\\Users\\Shtong\\.multirust\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liblibc-6eb85298.rlib" "D:\\Users\\Shtong\\.multirust\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librand-6eb85298.rlib" "D:\\Users\\Shtong\\.multirust\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcollections-6eb85298.rlib" "D:\\Users\\Shtong\\.multirust\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liballoc-6eb85298.rlib" "D:\\Users\\Shtong\\.multirust\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liballoc_system-6eb85298.rlib" "D:\\Users\\Shtong\\.multirust\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_unicode-6eb85298.rlib" "D:\\Users\\Shtong\\.multirust\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcore-6eb85298.rlib" "D:\\Users\\Shtong\\.multirust\\toolchains\\nightly-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcompiler_builtins-6eb85298.rlib" "pq.lib" "sqlite3.lib" "sqlite3.lib" "sqlite3.lib" "msvcrt.lib" "kernel32.lib" "ws2_32.lib" "userenv.lib" "shell32.lib" "advapi32.lib" "msvcrt.lib"
= note: LINK : fatal error LNK1181: cannot open input file 'sqlite3.lib'
error: aborting due to previous error
What I had to do in order to successfully compile:
- Set the
SQLITE3_LIB_DIRenvvar to the directory containing the sqlite3 dll. This was not required by diesel itself but by one of its dependencies, and the error message suggested to set that var, so I guess it’s not that bad - Set
LIBenvvar to both the PostgreSQL lib directory, and the directory containing the Sqlite3 binaries. Required forlinkto find the required libraries - Generate the Sqlite3.lib file manually, since it’s not contained in the windows precompiled library official download (can be made with
link /lib /def:sqlite3.def /MACHINE:X64in my case) - Rename (or copy) the
libpq.libfile located in the PostgreSQL lib directory intopq.lib
After compilation was done, I had to copy the following DLLs in my ~/.cargo/bin
- sqlite3.dll
- libpq.dll
- api-ms-win-crt-heap-l1-1-0.dll
- api-ms-win-crt-locale-l1-1-0.dll
- api-ms-win-crt-math-l1-1-0.dll
- api-ms-win-crt-runtime-l1-1-0.dll
- api-ms-win-crt-stdio-l1-1-0.dll
- api-ms-win-crt-string-l1-1-0.dll
I’m not sure if Diesel was designed to build on Windows in the first place (I couldn’t find any mention of platform-specific instructions or warnings), but these steps allowed me to build Diesel and successfully run the migrations.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 26
- Comments: 42 (11 by maintainers)
Commits related to this issue
- added db + diesel to backend https://github.com/diesel-rs/diesel/issues/487 — committed to H3rmt/grades by H3rmt 2 years ago
I think the best way to address this issue now is following these instructions:
Since this page is ranked high when you search for “diesel sqlite windows”:
For reference , if you want to install
diesl_clifor usage with Sqlite, you:C:\sqlite64)%comspec% /K "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64cd C:\sqlite64and runlib /def:sqlite3.def /out:sqlite3.libC:\sqlite64toPATHSQLITE3_LIB_DIRalso pointing toC:\sqlite64cargo install diesel_cli --no-default-features --features sqliteNot really straightforward if you aren’t a Window developer (which I’m not) but this should work 🤞
I had some trouble getting diesel to work with windows with sqlite. In the end this is what i did i think it’s probably the simplest for most windows users.
installed diesel cli
cargo install diesel_cli --no-default-features --features "sqlite-bundled"follow other instructions on setting up a project ie creating an env file, and running diesel setup.
use the following dependencies for your project dotenv = “^0.15.0” libsqlite3-sys = { version = “^0”, features = [“bundled”] } diesel = {version = “^1.4.5”, features = [“sqlite”]}
oddly the project built without libsqlite3-sys = { version = “^0”, features = [“bundled”] }, however when your ran cargo test it failed to link. I think somehow cargo build was finding the sqlite lib from the installation of diesel_cli or somewhere else in my system (i am not sure). With these instructions you don’t need to install anything on your system or mess with the path!
Hope others find this useful
Solution
C:\Users\User\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\libMissing sqlite3.lib (by default)
Download source from source (https://www.sqlite.org/download.html)
For example: source
https://www.sqlite.org/2020/sqlite-amalgamation-3310100.zipDownload binary from binary
For example: binary
https://www.sqlite.org/2020/sqlite-dll-win64-x64-3310100.zipExtract both archives to the same directory
Open Developer Command Prompt for VS 2017 by typing Developer Command in Windows Search
Go to directory where you’ve extracted source code and binary files (via opened cmd)
Run
lib /DEF:sqlite3.def /OUT:sqlite3.lib /MACHINE:x64Missing libpq.lib
When using command:
pgsql/lib/libpq.libto your cargoup lib dir(
C:\Users\User\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib)@weiznich
I think one or two OS specific notes won’t hurt anyone. IMO Getting started should be straightforward, not running into errors and googling for solutions.
@bugproof Discussing the same thing again and again won’t change my decision here. I cannot keep that up to date, I cannot maintain OS specific instructions. If someone volunteers in doing so feel free to do that, but I won’t. Especially Instructions for windows are hard to maintain for me as I do not have access to a windows machine and there are to many variants to install dependencies to list all. That said I will unsubscribe from this issue now, as this is solved from my point of view and I do not want to have the same discussion over and over again.
@bugproof As already mentioned multiple times: We won’t add OS specific instructions because we don’t have the resources to keep them up to date. Other than that: Feel free to submit improvements here
I got the same error, but not when building cli, but when building the app. Since this is one of the top results on Google now (even though it’s a bit different problem), I’ll add that in my case it was enough to just add:
in
cargo.tomlas noted in https://github.com/diesel-rs/diesel/issues/1647@godbrain ’s criticism is totally fair. It was a massive hassle when I tried to get diesel working on Windows, and it reflected very poorly on Rust, with diesel seemingly being the pre-eminent Rust ORM.
I’d consider install instructions to be a prerequisite for providing support for a platform. If diesel has chosen not to provide those, then I think it’s fair to say it doesn’t fully support Postgres on Windows, and it’s not “hostile” to ask if there is an alternative with support.
It’s not scalable for professional or especially side project work for every library to require the user to spend several hours figuring out how the environment is supposed to be set up, or rely on the total unknown of someone on Gitter helping. If I had to do that for every one of the ~20-30 direct dependencies of my current project, I’d never get any actual work done.
As I feel there are increasingly more people complaining about things and trying to “suggest” me how I should spend my free time working on diesel I think I should clarify how I prioritize my work on diesel:
To comment on a few specific points of @spease comment:
It’s not my “fault” that there are no bigger ORM style crates in rust, so either feel free to write your own and show how much better you can do or try to be constructively here. In the end if this continues I may consider to just work on and use my own private fork of diesel.
I like to disagree. Postgres on windows is a supported platform, as we are testing everything there. It’s just not my fault that there are perceived 100 different ways to install dependencies on windows that are all slightly incompatible with each other. I just do not see how it would be possible to write a documentation that covers all of this, without even having access to at least one of those environments. In the end that’s the environment the developer has choosen to work in and where I expect them to know how to make things work.
The question itself is not hostile, but the wording. I do not consider: " Is there another Rust ORM that works?" after stating that diesel obviously don’t work (without providing information what did not work), as a friendly question. It would be OK, if the statement “Of course now the diesel command does absolutely nothing.” contained any information about what exactly does not work or at least how to reproduce that. Without that I take this statement as offence against my previous work (as we test those things and they work there). I at least expect that people assume that we are trying to make things work as easily as possible on all platforms and that maybe the error is in their enviroment and not in diesel itsel.
So to just clarify that: Instead of figuring it out on your own you expect that I spend basically the same time to figure it out for you without knowing anything about your environment? You can do that, but don’t expect any help from me then. There is not much more that we can tell here than: You need to provide the libraries present in the linker error, which is already written on the web page. How that is done depends on to much things in your environment, that we cannot be much more concrete.
If you really want that certain things happen, there are a few possible ways to get there:
That’s my last comment on this kind of issues, in future I will just unsubscribe those, and let them be. It’s better for my health.
I know this all may sound quite harsh, but it needs to be said. So to end this with something actionable for all those that are complaining: Here is the source code for the web page, the other documentation is written in this repository. Code for actually linking libpq is here. Feel free to submit a concrete improvement instead of just complaining.
I tried
setx PQ_LIB_DIR "C:\Program Files\PostgreSQL\12\lib"even thou it is already in the Path env variable, butcargo install diesel_cli --no-default-features --features postgresstill end up with= note: LINK : fatal error LNK1181: cannot open input file 'libpq.lib'Figured it out.
As admin: choco install sqlite3 cd C:\ProgramData\chocolatey\lib\SQLite\tools lib /def:sqlite3.def /out:sqlite3.lib
As dev user: cd C:\ProgramData\chocolatey\lib\SQLite\tools cargo install --no-default-features --features sqlite
@sgrif I know this is closed, but I am receiving linker errors when building with diesel for postgres. Interesting, I can use the rust-postgres lib without issue. Any news on the new pg driver for diesel? Thanks
@JulianRuiseco I’m not sure what you expect to hear here. It’s definitively not a good way to get support for something by just commenting with complaints on old issues. Using diesel on windows is definitively supported (see the CI config for a known working installation variant), but at least I do not have access to a windows PC and do not want to spend my free time on fixing other peoples broken environments caused by installing dependencies from who knows where. If you expectation, then yes you shouldn’t use diesel on windows.
I think this shouldn’t be closed until there is a real fix for this, even something simple like adding windows instructions to the docs. Setting environment variables like PQ_LIB_DIR. Pretty much everyone who wants to try diesel will have this problem.
Hello @weiznich, I never meant to cause a big problem here. I also assumed a lot of people were working on this project and not mostly just yourself. I understand you don’t have all your free time to support this. I don’t understand how anyone really has time to support so many open source projects to be honest. I was just hoping to get a web environment up and running on Rust and ran into a few issues on the way. Since I have environments to run this for Windows and Linux I created an install “helper” doc for Windows 10 and have attached it. I will leave it to you if you want it added to the repo. Thank You dieselinstallonwin10.pdf
@martinth Would love to get that info as a PR to some part of our documentation (not entirely sure where the right place would be)
You have to add the folder that contains DLL files to your PATH env. It does nothing because it crashed. If you double click diesel.exe in
C:\Users\YourName\.cargo\bin, you’ll see the message box says some DLL is missing.Thanks so much for this
For those looking for help using the gnu toolchain on windows (with MinGW), step 3 isn’t necessary and step 4 becomes:
cd C:\sqlite64and runC:\path\to\MinGW\bin\dlltools.exe -d sqlite3.def -o sqlite3.aEverything else is the same 😃