Repository navigation
Can't install on Mac OS X: libpq.5.dylib not found #9
Description
I'm trying to install postgresql-libpq on Mac OS X 10.6.8. I get:
00:06 ijmorlan@27imac.local$ cabal install postgresql-libpq
Resolving dependencies...
[1 of 1] Compiling Main ( /var/folders/Lh/LhVs9ls4Hme1jR+t1DJbm++++TQ/-Tmp-/postgresql-libpq-0.8.2.2-42202/postgresql-libpq-0.8.2.2/Setup.hs, /var/folders/Lh/LhVs9ls4Hme1jR+t1DJbm++++TQ/-Tmp-/postgresql-libpq-0.8.2.2-42202/postgresql-libpq-0.8.2.2/dist/setup/Main.o )
Linking /var/folders/Lh/LhVs9ls4Hme1jR+t1DJbm++++TQ/-Tmp-/postgresql-libpq-0.8.2.2-42202/postgresql-libpq-0.8.2.2/dist/setup/setup ...
Configuring postgresql-libpq-0.8.2.2...
Building postgresql-libpq-0.8.2.2...
Preprocessing library postgresql-libpq-0.8.2.2...
dyld: Library not loaded: libpq.5.dylib
Referenced from: /private/var/folders/Lh/LhVs9ls4Hme1jR+t1DJbm++++TQ/-Tmp-/postgresql-libpq-0.8.2.2-42202/postgresql-libpq-0.8.2.2/dist/build/Database/PostgreSQL/LibPQ_hsc_make
Reason: image not found
running dist/build/Database/PostgreSQL/LibPQ_hsc_make failed (exit code 5)
command was: dist/build/Database/PostgreSQL/LibPQ_hsc_make >dist/build/Database/PostgreSQL/LibPQ.hs
cabal: Error: some packages failed to install:
postgresql-libpq-0.8.2.2 failed during the building phase. The exception was:
ExitFailure 1
00:06 ijmorlan@27imac.local$
Now, my libpq is not in /usr/lib, so maybe that's an issue. But:
00:06 ijmorlan@27imac.local$ pg_config --libdir
/Library/PostgreSQL/9.2/lib
00:08 ijmorlan@27imac.local$
So I figure that the postgresql-libpq configure stuff should be able to find it.
But maybe not, so:
00:08 ijmorlan@27imac.local$ cabal install --extra-lib-dirs=/Library/PostgreSQL/9.2/lib postgresql-libpq
Resolving dependencies...
[... same result ...]
I tried symlinking /Library/PostgreSQL/9.2/lib/libpq.5.dylib into /usr/lib, but then it complained about the version of libiconv. Sure enough, the version in /usr/lib is the slightly older version it can't use, while the one in /Library/PostgreSQL/9.2/lib is the needed version. I don't really want to go randomly upgrading stuff in /usr/lib.
Incidentally, my PostgreSQL installation was made by using the one click installer available from http://www.postgresql.org/download/macosx/.
This is one of those confusing cases where I can't seem to find anybody else asking the same question, but I don't see that I'm doing anything special that would give me a different experience from most other people. Any hints would be much appreciated.
Activity
lpsmith commentedon Mar 7, 2013
Thanks for the report; unfortunately I personally won't be able to help you much here. But if you do find a solution, please share, and I would be eager for any patches as well.
We really need to put together a guide for compiling postgresql-libpq on MacOS and Windows.
ijmorlan commentedon Mar 7, 2013
On Thu, 7 Mar 2013, Leon P Smith wrote:
Ok, thanks. I took a closer look at the postgresql-libpq package, in
particular the Setup.hs, and I think I believe that you are already doing
what I was thinking - you appear to invoke pg_config --libdir as well as
pg_config --includedir, and it gets through compilation, so it seems the
include dir is being used, just not the libdir.
So now I'm going to try to figure out what "cabal install" is doing and
find out why it's not working.
lpsmith commentedon Mar 7, 2013
for the purposes of building a single package, cabal-install mostly just invokes the Cabal commands in a particular sequence (with some further settings in your
~/.cabal/configfile, which cabal proper ignores)So you should try a vanilla cabal build process, without
cabal-install, and try cranking up the verbosity a notch or two.If worse comes to worse, a handy trick I've found when trying to understand cabal is to put print statements in the callback hooks in
Setup.hs. The data structures that these callbacks are passed are quite large, so if you want to examine them I recommend using groom to pretty print them.That's pretty generic advice, but I hope it helps!
ijmorlan commentedon Mar 7, 2013
On Thu, 7 Mar 2013, Leon P Smith wrote:
Thanks for the hints. Yes, I found the "verbose" flags. I dug around a
bit and it turns out that the extra lib dir is not getting set as an rpath
in the intermediate executable that hsc2hs generates and runs. By using
the Mac OS X install_name_tool utility on the intermediate executable, I
was able to get it to run and dump out a bunch of .hs code.
If I can figure out how to tell cabal to arrange for the intermediate
executable to be adjusted the same way I did manually, I think I would be
able to build the package.
I created a ticket on the GHC Trac site because it seems like hsc2hs
perhaps should take responsibility for setting the rpath on the
intermediate executable.
http://hackage.haskell.org/trac/ghc/ticket/7749
Of course, I can't really say, because I don't know enough about hsc2hs or
Mac OS X library handling.
lpsmith commentedon Mar 8, 2013
I just read the ticket; my one comment is that I don't know how many users of
postgresql-libpqthere are on MacOSX. I haven't heard any reports of people using it there, but that doesn't mean there aren't. I don't have a Macintosh at the moment though.I do know there is at least two people who have tried to use
postgresql-libpqon Windows though, one who has managed to get things compiled and one who hasn't. I don't use Windows very often, so I don't know much about this process either.alanpog commentedon Feb 27, 2014
Any news on this? Got same issue here, running OS X 10.9.2:
lpsmith commentedon Feb 27, 2014
Well, again I won't be able to help much, although I would recommend trying this with the verbosity turned up, as well as trying to invoke
runghc Setup.hs configurerunghc Setup.hs buildyourself.@ijmorlan, did you get this working, and if so, how?
lpsmith commentedon Feb 27, 2014
Also, I am curious, could you post the output of the
pg_configcommand?And this may not help, but you might look at this OpenBSD thread, which suggests we should modify
Setup.hsto use the output ofpg_config --libsto set theExtra-Librariesconfiguration parameter correctly. This may or may not be involved in a proper solution for MacOS X, but perhaps this thread might give you some clues.alanpog commentedon Feb 28, 2014
The output of pg_config is copied below:
alanpog commentedon Feb 28, 2014
Running
configandbuildmanually I get this, which is really the original error message:lpsmith commentedon Feb 28, 2014
Ok, so
hsc2hstakes a.hscsource file and generates a C program that when compiled and run, generates a Haskell program. It looks like this C program has been successfully compiled, but fails to run because it's looking for/usr/local/opt/postgresql/lib/libpq.5.6.dylibwhen (inferring from your pg_config output) it looks more like it's actually located at something like/usr/local/Cellar/postgresql/lib/libpq.5.6.dylibReferring to a key paragraph from ijmorlan above:I'm a little unclear on all the details here, but RPATH is a hard-wired dylib search path, embedded in the binary. I'm hoping that a
cabal buildafterwards wouldn't rebuild that executable, but I don't know.Alternatively, you might be able to fix this by adjusting your
DYLD_LIBRARY_PATHenvironment variable regardless of what cabal decides to do; take a look atman dyldfor more info. In any case, settingDYLD_LIBRARY_PATHshould hopefully work even if cabal rebuilds the C program every time.That still leaves the question of what happens to executables that use
postgresql-libpq, as you probably don't want to useDYLD_LIBRARY_PATH"in production". You could probably adjust the RPATH yourself. As for a proper fix, I'm still pretty much in the dark.c-lewis commentedon Dec 12, 2014
I've experienced similar problems on OS X 10.8.5. The workaround I've found that resolves this problem for me (this may not be universal) is to create symbolic links to
libpq.dylibandlibpq.5.dylibin/usr/local/lib. Then, I have toexport DYLD_LIBRARY_PATH=/usr/local/lib, and provide the--extra-lib-dirs=/usr/local/libcommand line parameter to Cabalinstallandconfigurecommands.By setting
export DYLD_PRINT_LIBRARIES=trueI've been able to confirm that/usr/local/lib/libpq.dylibis being loaded when thepostgresql-libpq-0.9.0.1package is loaded, and that the shared libraries thatlibpq.dylibdepends on are being loaded from/Library/PostgreSQL/9.2./lib. The correct shared libraries thatlibpq.dylibdepends on are being loaded, because they are specified with the@loader_pathvariable inlibpq.dylib, which can be verified withotool -L libpq.dylib.Notably, the workaround does not work if
/Library/PostgreSQL/9.2/bin/pg_configis on the path. With the wrong version ofpg_configon the path, not the version in/Library/PostgreSQL/9.2/bin/, the build does produce the following error.This error isn't surprising, because
/usr/lib/libpq.dylibis 64-bit only. I haven't looked into why this doesn't fail the build, but it doesn't.If
/Library/PostgreSQL/9.2/bin/pg_configis on the path, I find I get library not found/image not found errors forlibiconv.2.dylibthat I have not been able to resolve.Hopefully this helps until a real solution is found.
erewok commentedon Apr 3, 2016
Hello all,
I had a somewhat similar issue trying to install this library using
stack, but as this is the only relevant result I found while googling, I thought it might be useful to post what I did to resolve it here. My issue is different because instead ofReason: image not foundforlibpq.5.dylib, I was getting the following error:Because I had installed Postgresql 9.4 using the one-click installer on OSX, all relevant Postgresql files were in
/Library/PostgreSQL/9.4/. Before I even received this error, I had to add/Library/PostgreSQL/9.4/binto myPATHsopg_configcould be found.Anyway, the installer was finding
libiconv.2.dylib, but that was the wrong one:The one I needed was in
/Library/PostgreSQL/9.4/lib:Recent restrictions to OSX make it impossible to just go into
/usr/liband symlink the proper one in, but that didn't seem like that great of an idea anyway. Thus, inspired by the response from @c-lewis above, I symlinked all thedylibs into/usr/local/lib:Finally, I used
stackto install with theextra-lib-dirsargument and it worked fine:I am not sure how relevant this will be to the
Reason: image not foundissue for a differentdylib, but I thought there was a chance it might help someone, and so it seemed worth posting here.buggymcbugfix commentedon Dec 28, 2016
Thank you @pellagic-puffbomb —this saved my day. 👍
kevinmeredith commentedon Apr 25, 2017
Hi @pellagic-puffbomb. Thanks for your helpful answer!
For my own understanding, could you please explain why did you need to run
stack install --extra-lib-dirs=/usr/local/lib postgresql-libpq-0.9.1.1?Thanks
erewok commentedon Apr 26, 2017
@kevinmeredith stack didn't seem to be able to find the
dylibwithout my telling it to also look in/usr/local/lib. I found out that I could also add that toextra-lib-dirsin mystack.yamlfor my project and that I could also add it to my global (for my user)stack.yaml.