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

Installing diesel_cli on Windows : some assembly required #487

Closed
Shtong opened this Issue Oct 27, 2016 · 16 comments

Comments

Projects
None yet
9 participants
@Shtong

Shtong commented Oct 27, 2016

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_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 bad
  • Set LIB envvar to both the PostgreSQL lib directory, and the directory containing the Sqlite3 binaries. Required for link to 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:X64 in my case)
  • Rename (or copy) the libpq.lib file located in the PostgreSQL lib directory into pq.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.

@sgrif

This comment has been minimized.

Member

sgrif commented Oct 29, 2016

Is it safe to assume that the location of sqlite3.dll is on your path?

@Shtong

This comment has been minimized.

Shtong commented Nov 2, 2016

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.

@sgrif

This comment has been minimized.

Member

sgrif commented Nov 2, 2016

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.

@Shtong

This comment has been minimized.

Shtong commented Nov 3, 2016

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)

@sgrif

This comment has been minimized.

Member

sgrif commented Dec 10, 2016

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 sgrif closed this Dec 10, 2016

@viperscape

This comment has been minimized.

viperscape commented May 24, 2017

@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

@spasius

This comment has been minimized.

spasius commented Oct 25, 2017

Linker takes errors when building with diesel for postgres on Windows 7 64-bit, both stable and nightly.
rust-postgres works fine.

@gbip

This comment has been minimized.

gbip commented Nov 13, 2017

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.

@spease

This comment has been minimized.

spease commented Dec 5, 2017

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.

@spease

This comment has been minimized.

spease commented Dec 5, 2017

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

@ForsakenHarmony

This comment has been minimized.

ForsakenHarmony commented Feb 13, 2018

@sgrif what happened to that postgres driver?

@martinth

This comment has been minimized.

martinth commented Aug 24, 2018

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 🤞

@sgrif

This comment has been minimized.

Member

sgrif commented Aug 31, 2018

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

@spease

This comment has been minimized.

spease commented Aug 31, 2018

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.

@shawntabrizi

This comment has been minimized.

shawntabrizi commented Oct 23, 2018

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"

@spease

This comment has been minimized.

spease commented Oct 23, 2018

This is fantastic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment