Build shared library,written in c++, by using gnu autotools on Mac/OS X?
I want to port a c++ program I wrote from linux to mac, which including shared library projects. I used gnu automake to do the build things. Now I have many issues stop me from using automake to build my program on mac.
What effort I have made:
Here is some issues I can describe:
The first thing is to let the shared lib to be built. I found the libtool name is 'glibtool' on mac, so I need to use glibtool instead of libtool, I put this: LIBTOOL=glibtool in Makefile.am do the trick. And I also need to check OS let it only do this for Darwin system. The following should work in shell but seems not working for Makefile.am:
ifeq ($(OS), Windows_NT)
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S), Darwin)
LIBTOOL = glibtool
endif
endif
It will lead to "error:else without if". Not sure how to achieve this?
The left is the generated Makefile basically not working. Typing 'make':
cd ../.. && /bin/sh /Users/viewpl/lab/rdwtwdb-git-code/rdwtwdb/missing automake-1.14 --gnu plugin/dictcn/Makefile source='../../rwd_util.cpp' object='../../rwd_util.lo' libtool=yes DEPDIR=.deps depmode=none /bin/sh ../../depcomp glibtool --tag=CXX --mode=compile g++ -DHAVE_CONFIG_H -I/usr/include/ -I/usr/include/libxml2/ -I/usr/local/opt/libxml2/include/libxml2/ -I/usr/local/opt/readline/include -I/usr/local/include/ -iquote../../include/ -iquote../../ -g -O2 -c -o ../../rwd_util.lo ../../rwd_util.cpp glibtool --tag=CXX --mode=link g++ -g -O2 -rpath /usr/local/bin/plugin/ -o libdictcn.la -rpath /usr/local/lib/rwd dictcn.lo ../../rwd_util.lo -liconv -lltdl -lz -lxml2 -lreadline -lpthread -lportaudio -ldl -lcurl glibtool: link: `../../rwd_util.lo' is not a valid libtool object
Missing .lo files, looks like it doesn't compile .cpp into .lo. I tried to work around by running the g++ statement manually, it can help to generate .lo. I end up by this error:
glibtool: link: c++ -dynamiclib -Wl,-undefined -Wl,dynamic_lookup -o .libs/libdictcn.0.dylib .libs/dictcn.o ../../.libs/rwd_util.o -liconv -lltdl -lz -lxml2 -lreadline -lpthread -lportaudio -ldl -lcurl -O2 -install_name /usr/local/bin/plugin/ /usr/local/lib/rwd/libdictcn.0.dylib -compatibility_version 1 -current_version 1.0 -Wl,-single_module clang: error: no such file or directory: '/usr/local/lib/rwd/libdictcn.0.dylib'
I spent much time searching on internet but doesn't help much. The documentation of Apple's official site is not very helpful to solving gnu autotools usage problems on mac.
The complete source code can be found by this:
git clone http://git.code.sf.net/p/rdwtwdb/gitcode rdwtwdb-gitcode
I am using OS X Mavericks v10.9.2. Thanks for any advice.
Add more information to help asking why I cannot build .lo
when typing make
under the library folder, Makefile has been generated by using glibtool
When typing make
under the library fold, it complains .lo
files are missing:
source='dictcn.cpp' object='dictcn.lo' libtool=yes
DEPDIR=.deps depmode=none /bin/sh ../../depcomp
/bin/sh ../../libtool --tag=CXX --mode=compile g++ -DHAVE_CONFIG_H -I/usr/include/ -I/usr/include/libxml2/ -I/usr/local/opt/libxml2/include/libxml2/ -I/usr/local/opt/readline/include -I/usr/local/include/ -iquote../../include/ -iquote../../ -g -O2 -c -o dictcn.lo dictcn.cpp
source='../../rwd_util.cpp' object='../../rwd_util.lo' libtool=yes
DEPDIR=.deps depmode=none /bin/sh ../../depcomp
/bin/sh ../../libtool --tag=CXX --mode=compile g++ -DHAVE_CONFIG_H -I/usr/include/ -I/usr/include/libxml2/ -I/usr/local/opt/libxml2/include/libxml2/ -I/usr/local/opt/readline/include -I/usr/local/include/ -iquote../../include/ -iquote../../ -g -O2 -c -o ../../rwd_util.lo ../../rwd_util.cpp
/bin/sh ../../libtool --tag=CXX --mode=link g++ -g -O2 -rpath /usr/local/bin/plugin/ -o libdictcn.la -rpath /usr/local/lib/rwd dictcn.lo ../../rwd_util.lo -liconv -lltdl -lz -lxml2 -lreadline -lpthread -lportaudio -ldl -lcurl
libtool: link: `dictcn.lo' is not a valid libtool object
make: *** [libdictcn.la] Error 1
But the way to build .lo
has been given in the output. Why it doesn't use it to build .lo
? I looked into Makefile itself, found the rule to build .lo
is this:
.cpp.lo:
$(AM_V_CXX)source='$<' object='$@' libtool=yes
DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp)
$(AM_V_CXX_no)$(LTCXXCOMPILE) -c -o $@ $<
Final target is to build .la
file successfully
Despite of the previous issue, I can build .lo
manually. It's not too bad if I can half-automake the project. But when I trying to build the last .la
, this missing .dylib
error stop me from doing that:
/bin/sh ../../libtool --tag=CXX --mode=link g++ -g -O2 -rpath /usr/local/bin/plugin/ -o libdictcn.la -rpath /usr/local/lib/rwd dictcn.lo ../../rwd_util.lo -liconv -lltdl -lz -lxml2 -lreadline -lpthread -lportaudio -ldl -lcurl
libtool: link: warning: ignoring multiple `-rpath's for a libtool library
libtool: link: g++ -dynamiclib -Wl,-undefined -Wl,dynamic_lookup -o .libs/libdictcn.0.dylib .libs/dictcn.o ../../.libs/rwd_util.o -liconv -lltdl -lz -lxml2 -lreadline -lpthread -lportaudio -ldl -lcurl -O2 -install_name /usr/local/bin/plugin/ /usr/local/lib/rwd/libdictcn.0.dylib -compatibility_version 1 -current_version 1.0 -Wl,-single_module
clang: error: no such file or directory: '/usr/local/lib/rwd/libdictcn.0.dylib'
Your problem is that the ifeq
... endif
makefile syntax won't work in automake
because of indentation. This answer shows a more reliable way of handling uname
cases in configure.ac
.
I'm not that familiar with homebrew. Does homebrew also call libtool
and glibtool
and libtoolize
and glibtoolize
like the native OS X GNU Libtool?
At any rate, setting up LIBTOOL
in Makefile.am
is far too late. It needs to be handled by autoreconf
which invokes libtoolize
which writes libtool.m4
(the template for libtool
written by configure
). Something like this could work if that's the case:
LIBTOOLIZE=glibtoolize autoreconf -fvi
Whenever I had to build on OS X with the GNU Build System, I'd install all the autotools. The OS X autotools were invariably ancient and unusable on OS X. The homebrew libtools package might be OK, but again I don't have any experience with them, so I really can't say for certain.
链接地址: http://www.djcxy.com/p/54922.html上一篇: Junit内联比较器初始化错误