[CMake] Trouble building static universal libraries on MacOSX: ar bad, /usr/bin/libtool good
Dan Kegel
dank at kegel.com
Wed Sep 25 22:01:37 EDT 2013
Our project depends on 53 different open soure packages,
all downloaded and built by a nice 900 line shell script.
(Build systems are so standardized that usually it's just one line to download,
build, and install a random open source project, yay!)
Yesterday I had the pleasure of coaxing it into building
fat libraries on MacOSX. This went amazingly well, but
when building OpenCV, I ran into a problem with cmake.
I'm using cmake 2.8.11.2, probably from homebrew.
The symptom was
/usr/bin/ar cr ../lib/libIlmImf.a
CMakeFiles/IlmImf.dir/Half/half.cpp.o
CMakeFiles/IlmImf.dir/Iex/IexBaseExc.cpp.o ...
/usr/bin/ranlib ../lib/libIlmImf.a
/usr/bin/ranlib: for architecture: i386 file:
../lib/libIlmImf.a(IlmThread.cpp.o) has no symbols
...
/usr/local/Cellar/cmake/2.8.11.2/bin/cmake -E cmake_progress_report
/Users/dank/src/yobuild-builder/unified/btmp/OpenCV-2.4.3/CMakeFiles
1 2 3 4 5 6 7
[ 31%] Built target IlmImf
make: *** [all] Error 2
It seems that, on the mac, when building universal static libraries,
one ought not use ar;
instead, one is supposed to use apple's libtool (completely different
from gnu libtool,
which on the mac is called glibtool to avoid clashing).
Replacing "/usr/bin/ar cr ../lib/libIlmImf.a" with "libtool -o
../lib/libIlmImf.a" seems to
solve the problem. I was able to coax cmake into doing this with :
--- OpenCV-2.4.3/CMakeLists.txt.old 2013-09-25 18:33:24.000000000 -0700
+++ OpenCV-2.4.3/CMakeLists.txt 2013-09-25 18:35:34.000000000 -0700
@@ -60,6 +60,11 @@
project(OpenCV CXX C)
+if(APPLE)
+ SET(CMAKE_CXX_ARCHIVE_CREATE "/usr/bin/libtool -v -o <TARGET>
<LINK_FLAGS> <OBJECTS>")
+ SET(CMAKE_C_ARCHIVE_CREATE "/usr/bin/libtool -v -o <TARGET>
<LINK_FLAGS> <OBJECTS>")
+endif()
Is this a chink in cmake's support for universal libraries on MacOSX?
More information about the CMake
mailing list