Weimin,
Ben Sulman at UW-Madison compiled for the Mac. His 'recipe' can be found below. I haven't tried it myself.
Good luck!
Rob
Setting up GDAL C# components on Mac OS X for LANDIS-II
Software I have:
Mac OS X version 10.6.7, with developer tools installed
2.4 GHz Intel Core 2 Duo
Mono version 2.6.7, architecture x86
LANDIS-II version 6.0 (b3)
gdal 1.8.0 source (
http://download.osgeo.org/gdal/gdal-1.8.0.tar.gz)
LANDIS-II version 6 requires a gdal_wrap dynamic library that is compatible with mono. Some of the dll files included with the LANDIS distribution are C# files that mono can read, but others are Windows-compiled libraries that need to be replaced with libraries compiled for Mac. There were two major issues I had to solve to make the GDAL C# components work with mono on my machine:
A. Mac OS X compiles programs with 64-bit architecture by default, which makes the files incompatible with 32-bit Mono program
B. The GDAL distribution does not produce a shared library version of gdal_wrap
Here is the basic procedure I used to compile the gdal_wrap library:
1. Download and unpack the source code for gdal
2. cd gdal-1.8.0/
3. Run ./configure
4. Add this line to gdal-1.8.0/GDALmake.opt (I did this at line 74):
USER_DEFS = -arch i386 -arch x86_64
and at line 78:
LDFLAGS = -arch i386 -arch x86_64
This makes the compiler produce a "fat" file including both 32-bit (i386) and 64-bit (x86_64) architectures. You can also include just the i386 part, which should produce smaller files and compile faster, but may be less ideal if you plan on using the gdal libraries with other programs that might be 64-bit.
IMPORTANT: You need to be consistent with the architectures you include throughout the compilation process or you will probably get errors, so if you are just doing i386, omit the "-arch x86_64" part of the argument for all the subsequent steps.
5. make
Before moving on, you can test the output files using the lipo utility:
lipo -info .libs/libgdal.dylib
This should produce output like:
Architectures in the fat file: ../../.libs/libgdal.dylib are: i386 x86_64
or:
Non-fat file: .libs/libgdal.dylib is architecture: i386
If the i386 architecture is not included, there was a problem and things will not work down the line.
6. sudo make install
This should install the libraries in /usr/local/lib, and mono and further compiling steps should be able to find them.
7. cd swig
8. make
Note: this produces files necessary for gdal bindings to several languages including sharp, ruby, python, and java. If some of those fail or all you want is csharp, you can go into the GNUmakefile in the swig directory and edit the ALL_BINDINGS line to include just the languages you want.
9. cd csharp
10. make
11. make test
All the tests might not work if you are missing some other libraries that gdal uses. if you get an error:
Error occurred: dlopen(libproj.dylib, 1): image not found
I don't this is a problem for LANDIS, since LANDIS does not use libproj
The library should be working correctly with mono if you get this far:
LC_ALL=C mono createdata.exe Data pointlayer
Layer name: pointlayer
Feature Count: 1
Extent: 47,47,19.2,19.2
Layer SRS WKT: (unknown)
Field definition:
Name: String (32.0)
IntField: Integer (0.0)
DbleField: Real (0.0)
DateField: Date (0.0)
…
If it failed, you will get a message that a library was not found. A way to test further is to run mono with lots of extra output:
MONO_LOG_LEVEL=debug mono createdata.exe Data pointlayer
This produces a lot of lines like:
Mono-INFO: DllImport error loading library: 'dlopen(libogrcsharp.dylib, 9): image not found'.
If one of the lines looks like this:
Mono-INFO: DllImport error loading library: 'dlopen(libgdal_wrap.dylib, 9): no suitable image found. Did find:
libgdal_wrap.dylib: mach-o, but wrong architecture'.
then it found a library but the library did not have the correct 32-bit architecture. Otherwise, if it fails then the files themselves are not in a place that mono can find them. Check if there are the correct libraries in gdal-1.8.0/swig/csharp/.libs, and use lipo to make sure they include the i386 architecture.
12. You need to produce a libgdal_wrap.dylib file:
g++ -Wl,-single_module -dynamiclib -arch i386 -o libgdal_wrap.dylib gdal_wrap.o /usr/local/lib/libgdal.dylib
13. Move the file to a place where mono will find it:
sudo cp libgdal_wrap.dylib /usr/local/lib
With luck, LANDIS-II version 6 should now be able to find the GDAL libraries and run. Apologies if I skipped any steps by accident. I wrote this up while retracing my steps a couple days after staying up late figuring this out.
--Ben Sulman