Closed staab closed 4 years ago
I got it! I switched to using pg_config
to reference my installation of postgresql, as documented here. This means that everyone who installs this module will need postgresql installed and pg_config on the path, but that's ok for now.
So that got it compiling on MacOS fine, but then I wanted to run Valgrind on the code, which doesn't currently run on Mojave (a sketchy version can be installed with brew install --HEAD https://raw.githubusercontent.com/sowson/valgrind/master/valgrind.rb
but I'm not sure I trust the port). So, I added a dockerfile to try running valgrind on my library under linux. To do this, I installed libpq-dev
using apt
, and compiled my app, but when I went to run jpm test
I got an error about an undefined symbol. Build/test output is below:
root@e36dfcf520b7:/var/app# jpm build
linking build/pg.so...
generating meta file build/pg.meta.janet...
compiling build/staab.pg___pg.static.o...
creating static library build/pg.a...
root@e36dfcf520b7:/var/app# jpm test
running test/pg.janet ...
error: could not load native build/pg.so: build/pg.so: undefined symbol: PQconnectdb
in native
in <anonymous> [boot.janet] on line 1942, column 26
in require [boot.janet] on line 1963, column 16
in import* [boot.janet] on line 1975, column 15
in _thunk [test/pg.janet] (tailcall) on line 1, column 1
From everything I've read, my configuration should work (I am passing the correct includedir and libdir per pg_config
, as well as -lpq
). When I run nm -D /usr/lib/x86_64-linux-gnu/libpq.so
, PQconnectdb
is listed. If I export export LD_DEBUG=files
I get 157: build/pg.so: error: symbol lookup error: undefined symbol: PQconnectdb (fatal)
.
Side note: the reason I want to run valgrind
is I'm hoping that it'll tell my why I get no output from jpm test
other than "All tests passed" if I uncomment https://github.com/staab/janet-pg/blob/master/staab.pg/pg.c#L41.
For additional background on getting and installing libpq, check out this SO answer.
This is just a dumping place for my progress in compiling/linking my code with postgres. Unless otherwise specified, I'm using
jpm test
to trigger the errors.After getting the right
-I
flag to includelibpq-fe.h
, I started getting:I was able to get that error to go away by including all the
c
files from libpq:I then got:
Which I was able to get rid of by running
cd postgresql/src/interfaces/libpq && make ../../../src/port/pg_config_paths.h
and adding-Ipostgresql/src/port
to my:cflags
section.After looking into it a bit more, that seemed like a bandaid, so I ended up installing the client libraries to
postgresql/build
, using:This let me to change my project.janet to:
At this point, I'm now getting a bunch of errors having to do with types that aren't defined:
If I search postgresql for e.g.,
OM_uint32
, I get a lot of uses of it, but no definition, so I wonder if it's a preprocessor thing. Maybe I need to reference differentc
files, or use a-L
option?In summary, I have no idea what I'm doing. I'll keep this updated as I work on it.