Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Libtool creates static library only - I need shared objects

I have a couple of C++ classes and I want to compile them into a shared library using autotools and libtool. These are my configure.ac and Makefile.am files:

configure.ac:

AC_PREREQ(2.67)
AC_INIT(somelib.so, 1.0, [email protected])
AC_LANG(C++)
AM_INIT_AUTOMAKE(somelib, 1.0)

LT_INIT([disable-static])
AM_DISABLE_STATIC
AM_PROG_LIBTOOL
AC_LIBTOOL_DLOPEN
AC_PROG_LIBTOOL

AC_CONFIG_SRCDIR([Logger.cpp])
AC_CONFIG_HEADER([config.h])

# Checks for programs.
AC_PROG_CXX
AC_PROG_CC

AC_SUBST(LIBTOOL_DEPS)
AC_LTDL_DLLIB
AC_PROG_RANLIB

AC_SUBST(LIBTOOL_DEPS)
AC_LTDL_DLLIB

# Checks for libraries.

# Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS([cstring unistd.h pthread.h])

# Checks for typedefs, structures, and compiler characteristics.
AC_HEADER_STDBOOL
AC_C_CONST
AC_C_INLINE
AC_TYPE_SIZE_T

# Checks for library functions.
AC_FUNC_MALLOC
AC_FUNC_REALLOC
AC_TYPE_SIGNAL
AC_CHECK_FUNCS([mkdir strdup dup2])
AC_CHECK_LIB(pthread, pthread_create, [], [ echo "ERROR!: libpthread not found!"; exit -1], [])
AC_CHECK_LIB(xml2, htmlReadMemory, [], [ echo "ERROR!: libxml2 not found!"; exit -1], [])

AC_CONFIG_MACRO_DIR([m4])
AC_OUTPUT(Makefile)

Makefile.am:

AUTOMAKE_OPTIONS = foreign

ACLOCAL_AMFLAGS = -I m4
CPPFLAGS = `xml2-config --cflags` -g -fPIC -Wall -O2
AM_LDFLAGS = `xml2-config --libs` -pthread -shared -L$(libdir) -L.libs -lboost_iostreams -lz -lbz2 -L/shared/hudson/arm/lib -I/shared/hudson/arm/include

LIBVER=1:0:0

lib_LTLIBRARIES = somelib.la
somelib_la_SOURCES = <sources go here>

somelib_la_LDFLAGS = -version-info $(LIBVER)

library_includedir=$(includedir)/os
library_include_HEADERS = <headers go here>

Libtool only creates static libs, although I call configure --disable-static --enable-shared to explicitly instruct the script to create shared objects. What is wrong with my files?

--- EDIT ---

The link cmd from libtool:

/bin/bash ./libtool --tag=CXX   --mode=link arm-cortex_a8-linux-gnueabi-g++  -g -O2 -version-info 1:0:0  -o somelib.la -rpath /usr/local/lib AutoMutex.lo IniParser.lo Logger.lo Mutex.lo ProcInfo.lo Timer.lo XmlDocContainer.lo XmlNode.lo XmlParser.lo XmlSchemaValidator.lo XmlTree.lo ByteArray.lo IXmlEngine.lo LoggerSetup.lo Process.lo Thread.lo Utils.lo XmlError.lo XmlObjectEngine.lo XmlSchemaEngine.lo XmlSimpleEngine.lo Unziper.lo MUTool.lo  -lxml2 -lpthread -ldl -ldl
libtool: link: arm-cortex_a8-linux-gnueabi-ar cru .libs/somelib.a  AutoMutex.o IniParser.o Logger.o Mutex.o ProcInfo.o Timer.o XmlDocContainer.o XmlNode.o XmlParser.o XmlSchemaValidator.o XmlTree.o ByteArray.o IXmlEngine.o LoggerSetup.o Process.o Thread.o Utils.o XmlError.o XmlObjectEngine.o XmlSchemaEngine.o XmlSimpleEngine.o Unziper.o MUTool.o
libtool: link: arm-cortex_a8-linux-gnueabi-ranlib .libs/somelib.a
libtool: link: ( cd ".libs" && rm -f "somelib.la" && ln -s "../somelib.la" "somelib.la" )
make[1]: Leaving directory `/home/bg/workspace/git/somelib/src'
like image 443
Zbigh1 Avatar asked May 09 '12 10:05

Zbigh1


1 Answers

If libtool somehow believes it's on a platform that doesn't support shared libraries, it simply ignores you and builds static libraries instead. I see you're cross-compiling, perhaps libtool doesn't know how to build shared libraries for the target platform.

You'll want to check your configure output for a line that says something like

checking whether to build shared libraries...no

and then read config.log to find out why.

like image 139
ptomato Avatar answered Oct 23 '22 10:10

ptomato