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

Postgres example errors out during compile on Windows #3254

Open
kpeters58 opened this issue Dec 28, 2019 · 10 comments
Open

Postgres example errors out during compile on Windows #3254

kpeters58 opened this issue Dec 28, 2019 · 10 comments
Assignees
Labels
Bug This tag is applied to issues which reports bugs. OS: Windows Bugs/feature requests, that are specific to Windows OS. Unit: vlib Bugs/feature requests, that are related to the vlib.

Comments

@kpeters58
Copy link

kpeters58 commented Dec 28, 2019

Windows 10

Trying to compile the Postgres example from Github:

D:\projects\v\postgres>\vlang\v.exe main.v
C:\Users\kpeters\AppData\Local\Temp\v\main.tmp.c:221:10: fatal error: libpq-fe.h: No such file or directory
 #include <libpq-fe.h>
          ^~~~~~~~~~~~
compilation terminated.
V error: C error. This should never happen.
Please create a GitHub issue: https://github.com/vlang/v/issues/new/choose
@kpeters58 kpeters58 added the Bug This tag is applied to issues which reports bugs. label Dec 28, 2019
@nedpals nedpals added the Unit: vlib Bugs/feature requests, that are related to the vlib. label Dec 29, 2019
@Ivo-Balbaert
Copy link
Contributor

I encountered the same error on Windows 10 with Postgres freshly installed and its installation directory E:\PostgreSQL\bin and E:\PostgreSQL\include (which contains libpq-fe.h !) in the PATH variable.
I also tried the following (which helped in other cases) but the error remains:

Copy libpq-fe.h from E:\PostgreSQL\include to C:\Users\CVO\AppData\Local\Temp\v
copy libpq-fe.h near customer.v: idem
copy libpq-fe.h to C:\mingw-w64\bin\mingw64\x86_64-w64-mingw32\lib: idem
copy libpq.dll near customer.v and in local\temp\v : idem

It is clearly a PostgreSQL on Windows problem, doesn't happen on Linux.

@M4SSD35TRUCT10N M4SSD35TRUCT10N added this to the Beta Release milestone Apr 5, 2020
@serkonda7 serkonda7 changed the title Postgres example errors out during compile Postgres example errors out during compile on WIndows Apr 9, 2021
@enghitalo
Copy link
Contributor

So try installing libpq-dev or its equivalent for your OS:

For Ubuntu/Debian systems: sudo apt-get install libpq-dev
On Red Hat Linux (RHEL) systems: yum install postgresql-devel
For Mac Homebrew: brew install postgresql
For Mac MacPorts PostgreSQL: gem install pg -- --with-pg-config=/opt/local/lib/postgresql[version number]/bin/pg_config
For OpenSuse: zypper in postgresql-devel
For ArchLinux: pacman -S postgresql-libs

@ArtemkaKun ArtemkaKun added the OS: Windows Bugs/feature requests, that are specific to Windows OS. label May 26, 2023
@ArtemkaKun ArtemkaKun changed the title Postgres example errors out during compile on WIndows Postgres example errors out during compile on Windows May 26, 2023
@ArtemkaKun
Copy link
Contributor

@walkingdevel Do you have a possibility to test this and eventually close this?

@ArtemkaKun ArtemkaKun removed this from the Beta Release milestone May 26, 2023
@ghost
Copy link

ghost commented May 26, 2023

@ArtemkaKun, for now, I would keep it open. I will have a Windows device within a month, and then I will be able to check everything.

@omerrob
Copy link
Contributor

omerrob commented Aug 30, 2023

This also happens in macos with macports. I ran the required gem install pg -- --with-pg-config=/opt/local/lib/postgresql[version number]/bin/pg_config command and I can find libpq-fe.h manually if I

$ locate libpq-fe
/opt/local/include/postgresql13/libpq-fe.h

@omerrob
Copy link
Contributor

omerrob commented Aug 30, 2023

OK. So apparently, because https://github.com/vlang/v/blob/master/vlib/db/pg/pg.v will look at $pkgconfig('libpq') to find the correct flags or it will assume postgresql11 is used (macports uses /opt/local/):

$if $pkgconfig('libpq') {
	#pkgconfig --cflags --libs libpq
} $else {
	#flag -lpq
	#flag linux -I/usr/include/postgresql

	#flag darwin -I/opt/local/include/postgresql11
	#flag darwin -L/opt/local/lib/postgresql11

	#flag darwin -I/usr/local/opt/libpq/include
	#flag darwin -L/usr/local/opt/libpq/lib

	#flag darwin -I/opt/homebrew/include
	#flag darwin -L/opt/homebrew/lib

	#flag darwin -I/opt/homebrew/opt/libpq/include
	#flag darwin -L/opt/homebrew/opt/libpq/lib

	#flag windows -I @VEXEROOT/thirdparty/pg/include
	#flag windows -L @VEXEROOT/thirdparty/pg/win64
}

It's possible that because I'm using fish shell, macports didn't set PKG_CONFIG_PATH correctly. Once I ran

set -Ux PKG_CONFIG_PATH /opt/local/lib/postgresql13/pkgconfig/

the build error disappeared.

@smichea
Copy link

smichea commented Nov 27, 2023

i get similar error when trying to run the example in orm doc

builder error: 'libpq-fe.h' not found

I am on win11 and dont have postgres locally (i am using a remote instance)

@JalonSolov
Copy link
Contributor

Even if your postgres server is remote, you still need to have the headers local for your build.

@smichea
Copy link

smichea commented Nov 29, 2023

i managed to do that on wsl but not on windows.

@JalonSolov
Copy link
Contributor

JalonSolov commented Nov 29, 2023

If you have the files in wsl, you should be able to copy them to Windows. The pg driver source in V has these lines for Windows:

	#flag windows -I @VEXEROOT/thirdparty/pg/include
	#flag windows -L @VEXEROOT/thirdparty/pg/win64

So the .h files would go to your <v install dir>/thirdparty/pg/include directory (which you'll need to create). Not sure what goes in the win64 subdir, but likely a dll that's part of the Windows version of postgresql client.

We definitely need better docs on this...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs. OS: Windows Bugs/feature requests, that are specific to Windows OS. Unit: vlib Bugs/feature requests, that are related to the vlib.
Projects
None yet
Development

No branches or pull requests

10 participants