I recently had the need to run some older Lisp code on OSX 10.5.8 which used CLSQL, unfortunately this was enough to cause me a couple of lost hours trying to compile and load the CLSQL helper libraries.
I decided to start slowly by starting my Common Lisp implementation and running each of the following lines in the REPL.
1 |
(load (merge-pathnames "quicklisp/setup.lisp" (user-homedir-pathname))) |
1 |
(ql:quickload "clsql") |
1 |
(clsql:connect (list *db-host* *db-name* *db-user* *db-user-password*) :database-type :mysql :if-exists :old) |
I was greeted with the debugger, which I can’t say was a big surprise because I remembered having to compile some C helper libraries when I last used CLSQL on Linux. I checked clsql source inside quicklisp’s folder (~/quicklisp/dists/quicklisp/software/clsql-20101207-git/ in my case) and noticed the obvious Makefile there. My first (dumb) instinct was to jump right in and try to run make
1 |
$> make |
Which failed miserably because I didn’t have the development tools installed. So basically I had to get a running compiler and necessary tools like make.
I’m assuming you already have MySQL and all the necessary development headers (personally I installed it from a MySQL DMG image file I got from MySQL’s website and it came with all the required headers)
2. Getting GCC, make and required system development headers
As I googled around for indications on how to install GCC I noticed a pattern, most results suggested the need to install XCode 3.1.4 (apparently is the last version to run on OSX 10.5.x) which I found at Apple’s development center. I believe you need to register as a developer in order to actually download the software. After getting the 1Gb disk image I didn’t follow the regular install procedure and instead went into the Packages folder and installed the following packages:
DeveloperToolsCLI.pkg
DevSDK.pkg
gcc4.0.pkg
3. Compiling CLSQL helper libraries
With all the required tools i went back to CLSQL’s source tried running make again. The results weren’t all that better:
1 2 3 4 5 6 7 8 9 10 |
maclambda:clsql-20101207-git $> make make -C db-mysql cc -I /usr/local/include/mysql -I /usr/include/mysql -I /sw/include/mysql -I /opt/local/include/mysql -I /opt/local/include/mysql5/mysql -I /usr/local/mysql/include -arch x86_64 -arch i386 -bundle /usr/lib/bundle1.o -flat_namespace -undefined suppress clsql_mysql.c -o clsql_mysql.dylib ld: duplicate symbol dyld_stub_binding_helper in /usr/lib/bundle1.o and /usr/lib/bundle1.o for architecture x86_64 collect2: ld returned 1 exit status ld: duplicate symbol dyld_stub_binding_helper in /usr/lib/bundle1.o and /usr/lib/bundle1.o for architecture i386 collect2: ld returned 1 exit status lipo: can't open input file: /var/folders/1N/1NfnFctDEfmlk22M6UhJjU+++TI/-Tmp-//ccx81yR4.out (No such file or directory) make[1]: *** [clsql_mysql.so] Error 1 make: *** [db-mysql] Error 2 |
Basically this means that the first helper library packaged with CLSQL (clsql_mysql) failed to compile. After looking around the web I found that I should be replacing the string
1 |
-bundle /usr/lib/bundle1.o |
by
1 |
-dynamiclib |
on all occurences of lines similar to:
1 |
cc -arch x86_64 -arch i386 -bundle /usr/lib/bundle1.o -flat_namespace -undefined suppress $(source) -o $(dylib) |
in both “db-mysql/Makefile” and “uffi/Makefile” files. These minor changes have allowed me to successfully compile both helper libraries (db-mysql.dylib and clsql_uffi.dylib)
4. Conclusion
After completing these steps, I restarted my Lisp image and repeated the commands listed at the beginning of this post, I got one more error telling me it couldn’t load the libmysqlclient library but I solved that by adding the path to libmysqlclient. Something like the following lines
1 2 3 4 |
(ql:quickload "clsql") #+MACOSX (clsql-sys:push-library-path "/usr/local/mysql/lib/") (ql:quickload "clsql-mysql") |