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

Library Linking is not Working #71

Open
azertyIA opened this issue Jan 6, 2025 · 3 comments
Open

Library Linking is not Working #71

azertyIA opened this issue Jan 6, 2025 · 3 comments

Comments

@azertyIA
Copy link

azertyIA commented Jan 6, 2025

I wanted to try what backend development would be like in Haskell, so I'm kind of new to this, but I keep getting this error log. I tried setting my env path to the Postgres 17 libs and bins, and a bunch of other alternatives, and it seems it found some form of a libpq file. Still, there's not enough information or context on what library linking even means here, so I'm probably missing something big (for example using Windows might just be a massive hindrance).

checking for the pg_config program... C:\Program Files\PostgreSQL\17\bin\pg_config.exe
checking for the PostgreSQL libraries CPPFLAGS... -IC:/PROGRA~1/POSTGR~1/17/include
checking for the PostgreSQL libraries LDFLAGS... -LC:/PROGRA~1/POSTGR~1/17/lib
checking for the PostgreSQL libraries LIBS... -lpq 
checking for the PostgreSQL version... 17.2        
checking if PostgreSQL version 17.2 is >= 10.22... yes
checking for libpq-fe.h... yes
checking for the PostgreSQL library linking is working... no
@phadej
Copy link
Collaborator

phadej commented Jan 7, 2025

what library linking even means here,

configure script tries to compile a simple C program, which should link against postgresql client library. There is a chance that the script is misguided, but more likely that's an issue with your setup

You can try to debug it yourself:

cabal get postgresql-libpq-configure
cd postgresql-libpq-configure-0.11
sh configure

or even just by trying to compile

#include <libpq-fe.h>

int
main (void)
{

		    char conninfo[]="dbname = postgres";
		    PGconn     *conn;
		    conn = PQconnectdb(conninfo);

  return 0;
}

program first

@azertyIA
Copy link
Author

azertyIA commented Jan 11, 2025

It looks like I'm just having an error compiling the script you gave. I almost have everything working, but I can't do anything if I don't link the library argument like so:

gcc sample.c -m64 -L "C:/Program FIles/Postgresql/17/bin" -lpq  

I tried including "C:/Program FIles/Postgresql/17/bin" in both LIBRARY_PATH and LD_LIBRARY_PATH envs, but I haven't gotten anywhere far yet. If I don't link the library argument then I get errors like (there's a hundred more using -lpq):

C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Program Files/PostgreSQL/17/bin/../lib/libpq.a(src/interfaces/libpq/libpq.a.p/fe-secure-openssl.c.obj):(.text$mn+0x4d): undefined reference to `pg_snprintf'

Edit: I have tried changing -lpq to -llibpq because I figured out what -l actually does and this compiles fine, so if I want cabal build to finally work, I just need to somehow auto-include that -l argument:

gcc sample.c -m64 -l libpq

Edit 2: I was messing around some more and I tried changing the configure script to use -llibpq instead of -lpq and it actually linked all the way through. I'm not sure why it should work though. Maybe on later versions it just got renamed, so for now I'll just make a copy of the library and rename it "pq," which didn't end up working.

@azertyIA
Copy link
Author

By the looks of it, -lpq typically works because apt get libpq-dev (or something along those lines) just has pq as its library file, I'm guessing. But there is no equivalent to Windows, except for the entire Postgres installation which uses libpq and needs the -llibpq argument.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants