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

Linking on Windows #587

Closed
Timmmm opened this Issue Jan 21, 2017 · 5 comments

Comments

Projects
None yet
3 participants
@Timmmm

Timmmm commented Jan 21, 2017

It would be nice if the Readme explained how to compile this on Windows. As it stands I either get ld: cannot find -lpq or and equivalent error for pq.lib depending on whether I'm using the -msvc or -gnu toolchains. It actually fails when compiling diesel_codegen.

I installed PostgreSQL using the BigSQL windows installer, and it put libpq.a and libpq.dll in C:\Program Files\PostgreSQL\pg96\lib but I have no idea how to tell cargo to look there and google did not help.

@Cobrand

This comment has been minimized.

Cobrand commented Jan 21, 2017

You should probably copy/paste libpq.a and .dll in C:<where you installed rust>\lib\rustlib\x86_64-pc-windows-gnu\lib
if you don't want to copy the dll, you could edit $HOME/.cargo/config so that the linker knows where to lookup your dll, I think like this :

[target.x86_64-pc-windows-msvc.pq]
rustc-link-search = ["C:\\Program Files\\PostgreSQL\\pg96\\lib"]
rustc-link-lib = ["pq"]

or you could specify the lookup directly in your cargo command line, like so :

cargo rustc --release -- -L C:\\Program Files\\PostgreSQL\\pg96\\lib

I am on linux myself so I can't say that these work for sure (at least the first one should), but at least it's something

@Timmmm

This comment has been minimized.

Timmmm commented Jan 21, 2017

I also found that the instructions in pq-sys worked, specifically set an environment variable LIB_PQ_DIR=C:\Program Files\PostgreSQL\pg96\lib worked. You have to do cargo clean after setting it.

How do I edit .cargo/config? Something like this?

[build]
rustflags = ["-L" "C:/Program Files/PostgreSQL/pg96/lib"]
@Cobrand

This comment has been minimized.

Cobrand commented Jan 21, 2017

I edited my post

@Timmmm

This comment has been minimized.

Timmmm commented Jan 21, 2017

Ah this did the trick:

[target.x86_64-pc-windows-msvc.gnu]
rustc-link-search = ["C:\\Program Files\\PostgreSQL\\pg96\\lib"]

No need for the rustc-link-lib.

@sgrif

This comment has been minimized.

Member

sgrif commented Feb 2, 2017

Looks like this has been resolved. You can also do this by adding the PG directory to your PATH, there's an executable in the PG install directory which does this for you as well.

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