6

我有几个 C++ 类,我想使用 autotools 和 libtool 将它们编译成一个共享库。这些是我的 configure.ac 和 Makefile.am 文件:

配置.ac:

AC_PREREQ(2.67)
AC_INIT(somelib.so, 1.0, someone@somewhere.com)
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)

生成文件.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 只创建静态库,尽管我调用 configure --disable-static --enable-shared 来明确指示脚本创建共享对象。我的文件有什么问题?

- - 编辑 - -

来自 libtool 的链接 cmd:

/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'
4

1 回答 1

5

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.

于 2012-05-09T15:34:37.880 回答