Use mysql-simple (OS X and dymanic library trouble)

Hi, I’d like to use Haskell for some processing on a MySQL database. Currently, I use Java program to do that but I’d like to change.And an important information, I’m working on OS X Maverick and I use EclipseFP. I installed mysql-simple package. I had some troubles. First, I had to download pcre to get a pcre.h I put into the /usr/include dir. After, to link the mysql-simple package I did an export LD_LIBRARY_PATH=/usr/local/mysql-5.6.11-osx10.7-x86_64/lib. Thus, the library libmysqlclient.18.dylib was found. All stuff above were done by command line. Now, I want to code a simple program: module Main where import Database.MySQL.Simple main::IO() main = undefined hello :: IO Int hello = do conn <- connect defaultConnectInfo [Only i] <- query_ conn "select 2 + 2" return i But when I try to launch a repl from EclipseFP, I’ve got this error: Loading package mysql-0.1.1.7 ... <command line>: can't load .so/.DLL for: /Users/batman/Library/Haskell/ghc-7.8.3-x86_64/lib/mysql-0.1.1.7/libHSmysql-0.1.1.7-ghc7.8.3.dylib (dlopen(/Users/batman/Library/Haskell/ghc-7.8.3-x86_64/lib/mysql-0.1.1.7/libHSmysql-0.1.1.7-ghc7.8.3.dylib, 9): Library not loaded: libmysqlclient.18.dylib Referenced from: /Users/batman/Library/Haskell/ghc-7.8.3-x86_64/lib/mysql-0.1.1.7/libHSmysql-0.1.1.7-ghc7.8.3.dylib Reason: image not found) How can I set the place of this library ? I read some stuff on the web but I don’t understand everything :( Thanks for your help. Chris

On Sat, Oct 25, 2014 at 8:07 AM, Christian Sperandio < christian.sperandio@gmail.com> wrote:
After, to link the mysql-simple package I did an export LD_LIBRARY_PATH=/usr/local/mysql-5.6.11-osx10.7-x86_64/lib. Thus, the library libmysqlclient.18.dylib was found.
This is usually a bad idea, and what you're seeing is the least of the things that can go wrong. The correct fix for all of this is not to use the environment settings, but to build the mysql binding with cabal install mysql-simple --extra-lib-dirs=/usr/local/mysql-5.6.11-osx10.7-x86_64/lib so it actually finds and records the location of the library instead of using an unsafe override that you have to reproduce at runtime (doing that for anything launched from the GUI is difficult, and in some OS X releases impossible, and is always risky). -- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net

I tried your solution but it doesn’t work.
I unregistered the previous install with ghc-pkg unregister (for mysql and mysql-simple) and I tried:
cabal install mysql --extra-lib-dirs=/usr/local/mysql-5.6.11-osx10.7-x86_64/lib
But I get the error again:
Resolving dependencies...
Configuring mysql-0.1.1.7...
Building mysql-0.1.1.7...
Failed to install mysql-0.1.1.7
Last 10 lines of the build log ( /Users/batman/.cabal/logs/mysql-0.1.1.7.log ):
Building mysql-0.1.1.7...
Preprocessing library mysql-0.1.1.7...
dyld: Library not loaded: libmysqlclient.18.dylib
Referenced from: /private/var/folders/fk/339860r16j759wmsfmjkyr4h0000gn/T/mysql-0.1.1.7-25273/mysql-0.1.1.7/dist/build/Database/MySQL/Base/C_hsc_make
Reason: image not found
running dist/build/Database/MySQL/Base/C_hsc_make failed (exit code -5)
command was: dist/build/Database/MySQL/Base/C_hsc_make >dist/build/Database/MySQL/Base/C.hs
cabal: Error: some packages failed to install:
mysql-0.1.1.7 failed during the building phase. The exception was:
ExitFailure 1
Le 25 oct. 2014 à 15:43, Brandon Allbery
On Sat, Oct 25, 2014 at 8:07 AM, Christian Sperandio
wrote: After, to link the mysql-simple package I did an export LD_LIBRARY_PATH=/usr/local/mysql-5.6.11-osx10.7-x86_64/lib. Thus, the library libmysqlclient.18.dylib was found. This is usually a bad idea, and what you're seeing is the least of the things that can go wrong.
The correct fix for all of this is not to use the environment settings, but to build the mysql binding with
cabal install mysql-simple --extra-lib-dirs=/usr/local/mysql-5.6.11-osx10.7-x86_64/lib
so it actually finds and records the location of the library instead of using an unsafe override that you have to reproduce at runtime (doing that for anything launched from the GUI is difficult, and in some OS X releases impossible, and is always risky).
-- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

On Sat, Oct 25, 2014 at 11:09 AM, Christian Sperandio < christian.sperandio@gmail.com> wrote:
I unregistered the previous install with ghc-pkg unregister (for mysql and mysql-simple) and I tried: cabal install mysql --extra-lib-dirs=/usr/local/mysql-5.6.11-osx10.7-x86_64/lib
But I get the error again:
Then I presume whoever wrote those bindings didn't follow the rules, and you'll have to contact them to find out how to get it to work properly. (Unfortunately there's a decent chance they made it work on Linux and don't know about other platforms, and their only suggestion will be the LD_LIBRARY_PATH one which will not work properly on OS X, as you found.) -- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net

I’ll email the maintainer of the package.
Meanwhile, I have to do the ugly export DYLD_LIBRARY_PATH :/
Thanks for your help :)
Le 25 oct. 2014 à 17:14, Brandon Allbery
On Sat, Oct 25, 2014 at 11:09 AM, Christian Sperandio
wrote: I unregistered the previous install with ghc-pkg unregister (for mysql and mysql-simple) and I tried: cabal install mysql --extra-lib-dirs=/usr/local/mysql-5.6.11-osx10.7-x86_64/lib But I get the error again:
Then I presume whoever wrote those bindings didn't follow the rules, and you'll have to contact them to find out how to get it to work properly. (Unfortunately there's a decent chance they made it work on Linux and don't know about other platforms, and their only suggestion will be the LD_LIBRARY_PATH one which will not work properly on OS X, as you found.)
-- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

On Sat, Oct 25, 2014 at 11:16 AM, Christian Sperandio < christian.sperandio@gmail.com> wrote:
Meanwhile, I have to do the ugly export DYLD_LIBRARY_PATH :/
Actually, don't --- that actually stands a good chance of breaking things in bizarre ways. Use DYLD_FALLBACK_LIBRARY_PATH instead, it's less likely to cause weird breakage. The other problem is that Eclipse is generally launched from the GUI, and getting DYLD_FALLBACK_LIBRARY_PATH visible to the GUI is painful: you need to create ~/.launchd.conf and add something like setenv DYLD_FALLBACK_LIBRARY_PATH /usr/local/ mysql-5.6.11-osx10.7-x86_64/lib to it, then log out and back in so that the GUI is started with it. (This does stand a certain chance of making things go haywire, because you're really not supposed to set that --- but in this case I think you're stuck.) -- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net

Thanks for the trick :)
The solution is perhaps to try another mysql library :/
Le 25 oct. 2014 à 17:20, Brandon Allbery
On Sat, Oct 25, 2014 at 11:16 AM, Christian Sperandio
wrote: Meanwhile, I have to do the ugly export DYLD_LIBRARY_PATH :/ Actually, don't --- that actually stands a good chance of breaking things in bizarre ways. Use DYLD_FALLBACK_LIBRARY_PATH instead, it's less likely to cause weird breakage.
The other problem is that Eclipse is generally launched from the GUI, and getting DYLD_FALLBACK_LIBRARY_PATH visible to the GUI is painful: you need to create ~/.launchd.conf and add something like
setenv DYLD_FALLBACK_LIBRARY_PATH /usr/local/mysql-5.6.11-osx10.7-x86_64/lib
to it, then log out and back in so that the GUI is started with it. (This does stand a certain chance of making things go haywire, because you're really not supposed to set that --- but in this case I think you're stuck.)
-- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

On Sat, Oct 25, 2014 at 11:22 AM, Christian Sperandio < christian.sperandio@gmail.com> wrote:
Thanks for the trick :)
The solution is perhaps to try another mysql library :/
It's the nonstandard location that is the problem, really. The --extra-lib-dirs thing should have caused the special location to be used, but it relies on whoever wrote the bindings paying attention to extra-lib-dirs. On Linux, you have /etc/ld.so.conf as a list of directories to search for shared objects and LD_LIBRARY_PATH to add extra directories to it. On OS X, shared library paths are normally compiled into the things that use them and DYLD_LIBRARY_PATH overrides this completely (which means setting it can cause all programs to fail to find any shared libraries, oops!). DYLD_FALLBACK_LIBRARY_PATH is tried if it can't find the shared library at its normal location, which is risky but safer than DYLD_LIBRARY_PATH. If that shared object /Users/batman/Library/Haskell/ ghc-7.8.3-x86_64/lib/mysql-0.1.1.7/libHSmysql-0.1.1.7-ghc7.8.3.dylib was built with the right option (-headerpad_max_install_names, IIRC) then you may be able to use install_name_tool to fix the shared object path in it. You'll need to use otool -L to check what name is there and then install_name_tool to replace it. Alternately you can check with otool -L what pathname was stored in the mysql shared library itself and maybe fix that with install_name_tool. -- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net

Didn't somebody produce a 100% Haskell mysql client a while back?
On 25 October 2014 16:30, Brandon Allbery
On Sat, Oct 25, 2014 at 11:22 AM, Christian Sperandio < christian.sperandio@gmail.com> wrote:
Thanks for the trick :)
The solution is perhaps to try another mysql library :/
It's the nonstandard location that is the problem, really. The --extra-lib-dirs thing should have caused the special location to be used, but it relies on whoever wrote the bindings paying attention to extra-lib-dirs.
On Linux, you have /etc/ld.so.conf as a list of directories to search for shared objects and LD_LIBRARY_PATH to add extra directories to it. On OS X, shared library paths are normally compiled into the things that use them and DYLD_LIBRARY_PATH overrides this completely (which means setting it can cause all programs to fail to find any shared libraries, oops!). DYLD_FALLBACK_LIBRARY_PATH is tried if it can't find the shared library at its normal location, which is risky but safer than DYLD_LIBRARY_PATH.
If that shared object /Users/batman/Library/Haskell/ ghc-7.8.3-x86_64/lib/mysql-0.1.1.7/libHSmysql-0.1.1.7-ghc7.8.3.dylib was built with the right option (-headerpad_max_install_names, IIRC) then you may be able to use install_name_tool to fix the shared object path in it. You'll need to use otool -L to check what name is there and then install_name_tool to replace it.
Alternately you can check with otool -L what pathname was stored in the mysql shared library itself and maybe fix that with install_name_tool.
-- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners
participants (3)
-
Brandon Allbery
-
Christian Sperandio
-
emacstheviking