Building re2c on Mac/OSX/XCode

Having recently got a Macbook Pro, I installed Xcode and tried to port zenlang over to it. The lemon parser was a piece of cake, but re2c... not so much. This is using XCode 4.3 on OSX 10.7.

Having downloaded and extracted the source tarball, I tried running ./configure and got the error "C++ compiler cannot create executables".
The config.log file showed that the test file created by ./configure wasn't getting linked, it could not find crt1.10.6.

So the next step was to find this library (using find /Applications/Xcode.app -name "crt1.10.6*") add it to the environment before running ./configure, as follows:

env LDFLAGS="-L/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.SDK/usr/lib" ./configure

Now configure goes through successfully, but make doesn't. It is unable to find the standard include files, so I had to re-run configure with the include paths, again, discovered using find.

env CPPFLAGS="-I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.SDK/usr/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.SDK/usr/c++/4.2.1"  LDFLAGS="-L/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.SDK/usr/lib" ./configure

Note that we are also adding the include directory for the C++ header files (iostream, iomanip, etc) as well.

Now make should run successfully and create the re2c binary.

A couple of blogs I found suggested using macports, but I was quite sure that autotools won't let me down :)

1 comment:

Susan Ottwell said...

Homebrew installs it in one command

brew install re2c