Closed Shtong closed 7 years ago
Is it safe to assume that the location of sqlite3.dll
is on your path?
I did not have it in the path at the time I wrote the issue. I just made another test adding sqlite3 to the path and it allowed me to skip the "add sqlite3 the the LIB
envvar" part, although using SQLITE3_LIB_DIR
is still required to compile libsqlite3-sys
.
I don't control the libsqlite3-sys
project, so you'll have to open an issue with them. The only step that you listed that I can potentially do anything about is the renaming libpq.lib
which seems odd to me, and I've never had to do on Windows.
I'll see if I can find where that lib name (pq.lib
) comes from, that will be an occasion to learn rustc! As for sqlite3, since it's not required for the tutorial, maybe the tutorial should be updated to install diesel-cli without sqlite support (replacing cargo install diesel_cli
with something like cargo install diesel_cli --features postgres
)
(sorry for the close, clicked the wrong button)
Closing this issue, as any changes to make this easier will happen to https://github.com/sgrif/pq-sys, not Diesel. I will also be releasing a new PG driver early next year which will not depend on libpq, and should make this easier.
@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
Linker takes errors when building with diesel for postgres on Windows 7 64-bit, both stable and nightly. rust-postgres works fine.
I can't build diesel for sqlite on windows 10 64 bit with the stable and the nightly toolchain.
LINK : fatal error LNK1181: cannot open input file 'sqlite3.lib'
I tried adding the sqlite dll in .rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib
, but I have no idea how to get sqlite3.
It seems that this link present some steps to correctly setup sqlite3.
I'm also getting this error. I was able to generate sqlite3.lib, but I don't know how to set the libpath arguments for the linker.
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 what happened to that postgres driver?
Since this page is ranked high when you search for "diesel sqlite windows":
For reference , if you want to install diesl_cli
for usage with Sqlite, you:
C:\sqlite64
)%comspec% /K "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64
cd C:\sqlite64
and run lib /def:sqlite3.def /out:sqlite3.lib
C:\sqlite64
to PATH
SQLITE3_LIB_DIR
also pointing to C:\sqlite64
cargo install diesel_cli --no-default-features --features sqlite
Not really straightforward if you aren't a Window developer (which I'm not) but this should work 🤞
@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 might be able to simplify those instructions if you use chocolatey to install sqlite. Of course, that assumes you have chocolately installed.
That being said, a cholocatey package that provides the lib would make it virtually painless if you had chocolatey installed. Is there a license-related reason for it not being provided with SQLite?
I can’t help but think there should also be a better way...eg have the application check for the library and generate it using the above commands if needed. But I don’t know enough about the executable format to know if it’s impossible to execute any code before it attempts to load dependant libraries.
I think the best way to address this issue now is following these instructions:
If you are using a system without an easy way to install sqlite (for example Windows), you can use a bundled version instead:
cargo install diesel_cli --no-default-features --features "sqlite-bundled"
This is fantastic
Since this page is ranked high when you search for "diesel sqlite windows":
For reference , if you want to install
diesl_cli
for usage with Sqlite, you:* download the precompiled Windows binaries from https://sqlite.org/download.html * extract them to a folder (i.e. `C:\sqlite64`) * run a cmd terminal with the 64bit msvc toolchain in the path: "Win + R" and execute `%comspec% /K "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64` * `cd C:\sqlite64` and run `lib /def:sqlite3.def /out:sqlite3.lib` * add `C:\sqlite64` to `PATH` * create an environment variable `SQLITE3_LIB_DIR` also pointing to `C:\sqlite64` * restart terminal and run `cargo install diesel_cli --no-default-features --features sqlite`
Not really straightforward if you aren't a Window developer (which I'm not) but this should work 🤞
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:\sqlite64
and run C:\path\to\MinGW\bin\dlltools.exe -d sqlite3.def -o sqlite3.a
Everything else is the same 😃
Thank you guys so much for answering this Result Type Err lol
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:
libsqlite3-sys = { version = "...", features = ["bundled"] }
in cargo.toml
as noted in https://github.com/diesel-rs/diesel/issues/1647
I tried setx PQ_LIB_DIR "C:\Program Files\PostgreSQL\12\lib"
even thou it is already in the Path env variable, but cargo install diesel_cli --no-default-features --features postgres
still end up with = note: LINK : fatal error LNK1181: cannot open input file 'libpq.lib'
Over 4 years later and this still doesn't work? Can't get past this... same as kubikx above...
Look at @shawntabrizi ’s answer above. Does that help?
EDIT: My bad, Postgres not sqlite
After many env updates and reboots I got this to work... the setx path has to be correct and Windows rebooted at least once.
Of course now the diesel command does absolutely nothing. Is there another Rust ORM that works?
Of course now the diesel command does absolutely nothing. Is there another Rust ORM that works?
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.
@godbrain This issue has been closed since more than 4 years, so that is clearly not the right place to ask questions that are basically about your environment. I know that it can be quite hard to setup everything correctly on windows and this turns on google as one of the top results, but commenting on a such an old issue is really not the right way to solve that problem. We a have a quite active gitter channel for this kind of problems, where you can get help without sending a notification to all people subscribed to this issue/repository. Generally speaking: Using WSL is probably the easiest way to get everything working on windows, so if you have trouble figuring out the corresponding linker paths for the microsoft tool chains, use WSL. It's really nothing we have much control over.
Of course now the diesel command does absolutely nothing. Is there another Rust ORM that works?
This comment is borderline hostile, is it does not contain anything somehow related to the original issue you are commenting on or even actionable criticism. Please consider how you talk about the projects of other people in the future. I do not consider this as tolerable behaviour here.
Thanks @fluxxu , I'll give that a try but I even tried running it directly from that directory.
@weiznich, sorry to spam the group on this old ticket. Unfortunately though running a basic command to get diesel running from the web site instructions still doesn't work after 4 years. If this doesn't run natively on Windows and needs WSL to run that's fine but I don't see that documented anywhere so here I am at this old ticket. It also worries me when I go to the web site and it says copyright 2018 like it's not being maintained. I would like to see this working as I have found an interest in Rust and wanted to set something up with diesel and rocket. I think it would help people in the future who want to use Rust if some of this was noted on the website.
I am currently writing apps in .net core, Phoenix/elixir and laravel/php and was hoping to add Rust as an option. I admit I got a little frustrated with this as I was up until 1am working on it. I could have worded things differently but I really was wondering if this was the only Rust ORM or not.
Thanks for your help on this and I will be more positive in the future.
@godbrain It does work on windows natively, you just need to figure out some paths/environment variables. Unfortunately we cannot provide exact installation guide there, as those tend be invalid quite fast, because of windows changing things and not having clear standards of how to configure that in a reliable way. (Additionally I do not use windows by myself, so I'm not that much of help there, so I normally just point to our CI (postgres example) as things work there.) To word that a bit differently: I've come from a c/c++ background, there such linker errors are quite common and people know how to fix them for their platform. I'm basically assuming the same thing here as I do not know how to describe this better. So if anyone comes up with some concrete robust cross platform installation description, just submit a PR here.
I could have worded things differently but I really was wondering if this was the only Rust ORM or not.
The question here is what exactly do you consider to be a ORM. There is tql which is something along the lines of a classical ORM. Diesel on the other hand is quite opinionated, so expect that it works differently in some places as other ORM's.
@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 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.
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’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,
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.
and it’s not “hostile” to ask if there is an alternative with support.
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.
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.
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.
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
C:\Users\User\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib
Download source from source (https://www.sqlite.org/download.html)
For example: source https://www.sqlite.org/2020/sqlite-amalgamation-3310100.zip
Download binary from binary
For example: binary https://www.sqlite.org/2020/sqlite-dll-win64-x64-3310100.zip
Extract 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:x64
When using command:
cargo install diesel_cli --no-default-features --features postgres
pgsql/lib/libpq.lib
to your cargoup lib dirC:\Users\User\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib
)@weiznich Sorry my reply caused such frustration. Note that I hadn't even worked for the company I had been trying to use diesel at for a year, and we opted not to use Rust. Processing tens of GB for biopharma research was nonviable due to #1775, and there was strong internal inertia for C++ that I doubt any Rust solution could have overcome. Note also that I posted a solution for sqlite in this ticket when I found one. What I would usually expect is that the configuration used for the test harness would be documented as the "supported solution" so the work involved to figure it out would have already been done, and this would also have the nice property of validating the supported method whenever the tests are run.
Thanks for all the work you're doing.
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
Edit: version numbers are not important - use whatever is required for your project and refer to the current docs
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.
@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
@weiznich
We won't add OS specific instructions because we don't have the resources to keep them up to date
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.
@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.
- download sqlite3.lib file
- C:\Users...rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-msvc\lib\ add sqlite3.lib file this directory
This was actually the only thing that worked for me, for anyone else having this issue.
Update: Let me clarify that my issue was not related to diesel_cli, but when compiling the app itself.
- Get mysql connector from: https://downloads.mysql.com/archives/c-c/
- Get postgress from : https://www.enterprisedb.com/downloads/postgres-postgresql-downloads
- setx MYSQLCLIENT_LIB_DIR "C:\Program Files\MySQL\MySQL Connector C 6.1\lib\vs14"
- setx PQ_LIB_DIR "C:\PostgreSQL\12\lib"
- Finally you can install diesel client through below: cargo install diesel_cli --no-default-features --features "sqlite-bundled mysql postgres" --force
This should be top comment
@Kubikx My solution for this problem was adding entry to root .cargo/config.toml
[target.x86_64-pc-windows-msvc.pq]
rustc-link-search = ["C:\\Program Files\\PostgreSQL\\13\\lib"]
rustc-link-lib = ["libpq"]
Although I'm still looking for these solution of this error:
error while loading shared libraries: api-ms-win-crt-heap-l1-1-0.dll: cannot open shared object file: No such file or directory
But I know that this dll exists and installed.
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):
What I had to do in order to successfully compile:
SQLITE3_LIB_DIR
envvar 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 badLIB
envvar to both the PostgreSQL lib directory, and the directory containing the Sqlite3 binaries. Required forlink
to find the required librarieslink /lib /def:sqlite3.def /MACHINE:X64
in my case)libpq.lib
file located in the PostgreSQL lib directory intopq.lib
After compilation was done, I had to copy the following DLLs in my ~/.cargo/bin
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.