I am unable to build the couchbase ruby gem on os x 10.6.8-Collection of common programming errors
My goal is to install the couchbase ruby gem by building the native extensions, but I am having what seems like an architecture mismatch between the gem and the libcouchbase C library. Here is some background:
- I am running OS X 10.6.8, using rvm, and ruby 1.9.2-p320 built from source
- I was running OS X 10.6.7 and Xcode 3.2.5 up until yesterday but I was unable to build libcouchbase natively
- I then installed brew which is known to help ease the libcouchbase install, and brew told me I needed to upgrade to at least Xcode 3.2.6
- I downloaded the elusive Xcode 4.2 for Snow Leopard because it was over 2 gigs smaller than Xcode 3.2.6 and I figured I would get the latest version.
- Xcode wouldn’t install due to certificate errors which I found were the result of a bug in the System Installer, and the fix was to upgrade to OS X 10.6.8 and then apply a System Update
- A few hours and restarts later, I am running OS X 10.6.8 with XCode 4.2 installed and libcouchbase compiles via brew without any hiccups
- I now attempt to install the couchbase gem but building native extensions fails. It says it is unable to find libcouchbase even when explicitly passing the location of the library
- Inspecting mkmf.log shows the following (bold emphasis added, but I may be wrong about the problem!
“/usr/bin/gcc-4.2 -o conftest -I/Users/emkman/.rvm/rubies/ruby-1.9.2-p320/include/ruby-1.9.1/universal-darwin10.8.0 -I/Users/emkman/.rvm/rubies/ruby-1.9.2-p320/include/ruby-1.9.1/ruby/backward -I/Users/emkman/.rvm/rubies/ruby-1.9.2-p320/include/ruby-1.9.1 -I. -I/usr/local/Cellar/libevent/2.0.19/include -I/opt/local/include -I/usr/local/include -I/Users/emkman/.rvm/rubies/ruby-1.9.2-p320/include -I/usr/include -I/Users/emkman/.rvm/usr/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wpointer-arith -Wwrite-strings -Wno-missing-field-initializers -Wshorten-64-to-32 -Wno-long-long -arch i386 -arch x86_64 -fno-common -pipe -std=c99 -Wall -Wextra conftest.c -L. -L/Users/emkman/.rvm/rubies/ruby-1.9.2-p320/lib -L/usr/local/Cellar/libevent/2.0.19/lib -L/opt/local/lib -L/usr/local/lib -L/Users/emkman/.rvm/rubies/ruby-1.9.2-p320/lib -L/usr/lib -L/Users/emkman/.rvm/usr/lib -L. -arch i386 -arch x86_64 -L/usr/local/lib -arch i386 -arch x86_64 -lruby.1.9.1-static -lpthread -ldl -lobjc ” checked program was:
/* begin */
1: #include "ruby.h"
2:
3: int main() {return 0;}
/* end */
“/usr/bin/gcc-4.2 -I/Users/emkman/.rvm/rubies/ruby-1.9.2-p320/include/ruby-1.9.1/universal-darwin10.8.0 -I/Users/emkman/.rvm/rubies/ruby-1.9.2-p320/include/ruby-1.9.1/ruby/backward -I/Users/emkman/.rvm/rubies/ruby-1.9.2-p320/include/ruby-1.9.1 -I. -I/usr/local/Cellar/libevent/2.0.19/include -I/opt/local/include -I/usr/local/include -I/Users/emkman/.rvm/rubies/ruby-1.9.2-p320/include -I/usr/include -I/Users/emkman/.rvm/usr/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wpointer-arith -Wwrite-strings -Wno-missing-field-initializers -Wshorten-64-to-32 -Wno-long-long -arch i386 -arch x86_64 -fno-common -pipe -std=c99 -Wall -Wextra -arch i386 -arch x86_64 -c conftest.c” checked program was:
/* begin */
1: #include "ruby.h"
2:
3: #include
4: int foo(int x, ...) {
5: va_list va;
6: va_start(va, x);
7: va_arg(va, int);
8: va_arg(va, char *);
9: va_arg(va, double);
10: return 0;
11: }
12: int main() {
13: return foo(10, "", 3.14);
14: return 0;
15: }
/* end */
have_library: checking for libcouchbase_server_versions() in -lcouchbase… ——————– no
“/usr/bin/gcc-4.2 -o conftest -I/Users/emkman/.rvm/rubies/ruby-1.9.2-p320/include/ruby-1.9.1/universal-darwin10.8.0 -I/Users/emkman/.rvm/rubies/ruby-1.9.2-p320/include/ruby-1.9.1/ruby/backward -I/Users/emkman/.rvm/rubies/ruby-1.9.2-p320/include/ruby-1.9.1 -I. -I/usr/local/Cellar/libevent/2.0.19/include -I/opt/local/include -I/usr/local/include -I/Users/emkman/.rvm/rubies/ruby-1.9.2-p320/include -I/usr/include -I/Users/emkman/.rvm/usr/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wpointer-arith -Wwrite-strings -Wno-missing-field-initializers -Wshorten-64-to-32 -Wno-long-long -arch i386 -arch x86_64 -fno-common -pipe -std=c99 -Wall -Wextra conftest.c -L. -L/Users/emkman/.rvm/rubies/ruby-1.9.2-p320/lib -L/usr/local/Cellar/libevent/2.0.19/lib -L/opt/local/lib -L/usr/local/lib -L/Users/emkman/.rvm/rubies/ruby-1.9.2-p320/lib -L/usr/lib -L/Users/emkman/.rvm/usr/lib -L. -arch i386 -arch x86_64 -L/usr/local/lib -arch i386 -arch x86_64 -lruby.1.9.1-static -lcouchbase -lpthread -ldl -lobjc ” ld: warning: ignoring file /usr/local/lib/libcouchbase.dylib, file was built for unsupported file format which is not the architecture being linked (i386) Undefined symbols for architecture i386: “_libcouchbase_server_versions”, referenced from: _t in cckhpWpO.o ld: symbol(s) not found for architecture i386 collect2: ld returned 1 exit status lipo: can’t open input file: /var/folders/AT/ATO2AJa-G3Ogm+J4qma1hE+++TI/-Tmp-/mkmf_20120724-40695-16d2a4n/ccAGPue9.out (No such file or directory) checked program was:
/* begin */
1: #include "ruby.h"
2:
3: #include
4:
5: /*top*/
6: int main() {return 0;}
7: int t() { void ((*volatile p)()); p = (void ((*)()))libcouchbase_server_versions; return 0; }
/* end */
“/usr/bin/gcc-4.2 -o conftest -I/Users/emkman/.rvm/rubies/ruby-1.9.2-p320/include/ruby-1.9.1/universal-darwin10.8.0 -I/Users/emkman/.rvm/rubies/ruby-1.9.2-p320/include/ruby-1.9.1/ruby/backward -I/Users/emkman/.rvm/rubies/ruby-1.9.2-p320/include/ruby-1.9.1 -I. -I/usr/local/Cellar/libevent/2.0.19/include -I/opt/local/include -I/usr/local/include -I/Users/emkman/.rvm/rubies/ruby-1.9.2-p320/include -I/usr/include -I/Users/emkman/.rvm/usr/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wpointer-arith -Wwrite-strings -Wno-missing-field-initializers -Wshorten-64-to-32 -Wno-long-long -arch i386 -arch x86_64 -fno-common -pipe -std=c99 -Wall -Wextra conftest.c -L. -L/Users/emkman/.rvm/rubies/ruby-1.9.2-p320/lib -L/usr/local/Cellar/libevent/2.0.19/lib -L/opt/local/lib -L/usr/local/lib -L/Users/emkman/.rvm/rubies/ruby-1.9.2-p320/lib -L/usr/lib -L/Users/emkman/.rvm/usr/lib -L. -arch i386 -arch x86_64 -L/usr/local/lib -arch i386 -arch x86_64 -lruby.1.9.1-static -lcouchbase -lpthread -ldl -lobjc ” conftest.c: In function ‘t’: conftest.c:7: error: too few arguments to function ‘libcouchbase_server_versions’ conftest.c: In function ‘t’: conftest.c:7: error: too few arguments to function ‘libcouchbase_server_versions’ lipo: can’t figure out the architecture type of: /var/folders/AT/ATO2AJa-G3Ogm+J4qma1hE+++TI/-Tmp-/mkmf_20120724-40695-cblicr/ccG9E6Cp.out checked program was:
/* begin */
1: #include "ruby.h"
2:
3: #include
4:
5: /*top*/
6: int main() {return 0;}
7: int t() { libcouchbase_server_versions(); return 0; }
/* end */
So it seems to me that the problem is that gcc is looking for an i386 build of /usr/local/lib/libcouchbase.dylib and inspecting mine shows
/usr/local/lib/libcouchbase.dylib: Mach-O 64-bit dynamically linked shared library x86_64
So now to my question(s). Is this the problem or a red herring? Do I need to be building libcouchbase as i386 or universal, or is the problem on the gem side? I have been building native gem extensions on this system for many years without problem, including the sometimes nasty mysql gem, but now I have new versions of GCC/Xcode. The rvm release notes say that Xcode 4.2 only works with Ruby 1.9.3 and breaks lots of native extensions, so I completely uninstalled it and then installed GCC-10.6.pkg from https://github.com/kennethreitz/osx-gcc-installer/ which rvm recommends as a working, but I still have the same problem. Here is my brew –env dump:
CC: /usr/bin/llvm-gcc => /usr/llvm-gcc-4.2/bin/llvm-gcc-4.2
CXX: /usr/bin/llvm-g++ => /usr/llvm-gcc-4.2/bin/llvm-g++-4.2
LD: /usr/bin/llvm-gcc => /usr/llvm-gcc-4.2/bin/llvm-gcc-4.2
CFLAGS: -Os -w -pipe -march=core2 -msse4.1 -mmacosx-version-min=10.6
CXXFLAGS: -Os -w -pipe -march=core2 -msse4.1 -mmacosx-version-min=10.6
CPPFLAGS: -isystem /usr/local/include
LDFLAGS: -L/usr/local/lib
MACOSX_DEPLOYMENT_TARGET: 10.6
MAKEFLAGS: -j2
Both now and when I had Xcode 4.2 installed, my -march was set to core2. Should this be native instead? I rebuilt ruby 1.9.2-p320 from source, via rvm/JewelryBox after installing my latest osx-gcc toolchain, to ensure it was using the same flags. It is built as universal-darwin and seems correct:
interpreter: "ruby"
version: "1.9.2p320"
date: "2012-04-20"
platform: "universal.x86_64-darwin10.8.0"
patchlevel: "2012-04-20 revision 35421"
full_version: "ruby 1.9.2p320 (2012-04-20 revision 35421) [universal.x86_64-darwin10.8.0]"
I know this is a lot of info, but I just want to be thorough with the details and show that I have tried almost everything. I should also mention that I have tried the developer preview of the gem combined with the developer preview of libcouchbase, and the error is the same. The two things I haven’t tried:
- Installing XCode 4.1 for Snow Leopard – Apple no longer makes this file available for download even though it is theoretically supported.
- Installing Xcode 3.2.6 for Snow Leopard – I was trying to avoid the 4gb download but I have just started it now and can try it later tonight
Any help is greatly appreciated, especially if you have built the couchbase gem on OS X before.