1

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:

  1. Installed xcode 5.1.1 and its command line tools(looks like it not helpful, it doesn't have automake)
  2. Installed automake libtool manually by homebrew
  3. Followed a typical automake workflow: autoscan, autoconf, aclocal, automake, configure, make... then a bunch of errors appeared.
  4. Searched in google heaps, no complete tutorial about this particular task was found.

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'
1
  • I don't know if this will help, but try ifneq instead of ifeq followed directly by else?
    – ptomato
    May 17, 2014 at 22:35

1 Answer 1

2

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.

3
  • Thanks for your response. I used homebrew to install new autotools. I am not familiar with libtoolize/glibtoolize. Anyway I tried adding 'LIBTOOL=glibtool' and 'LIBTOOLIZE=glibtoolize' in configure.ac, looks like the generated Make still not able to output .lo 'libtool: link: `dictcn.lo' is not a valid libtool object'
    – Rob Lao
    May 18, 2014 at 15:00
  • Adding LIBTOOLIZE and LIBTOOL to configure.ac won't fix it, because it's too late there also. You might want to check out the documentation for autoreconf. And double check what the homebrew libtool scripts are called.
    – ldav1s
    May 19, 2014 at 4:22
  • I think I am using the right libtool now, because I checked the generated 'libtool' file at the root of project, it's version 2.4.2, the same as result of $glibtool --version. Do you have an idea of why Makefile in my library giving correct command-line to build .lo, but not running to build .lo when I typing make?
    – Rob Lao
    May 20, 2014 at 10:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.