当转换为libtool时,automake和autoconf找不到libtool。

4

我正在尝试将libcsv转换为使用libtool,以便在Mac OS X上使用而不会弄乱makefile。当我尝试运行从工具生成的makefile时,我会收到以下错误:

~/software/libcsv (gnu_tools) $ make 
tag=CC   --mode=compile gcc -DPACKAGE_NAME=\"\" -DPACKAGE_TARNAME=\"\" -DPACKAGE_VERSION=\"\"
-DPACKAGE_STRING=\"\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"libcsv\" 
-DVERSION=\"3.0.1\" -I.     -g -O2 -MT libcsv.lo -MD -MP -MF .deps/libcsv.Tpo -c -o libcsv.lo  
libcsv.c
/bin/sh: --mode=compile: command not found
make: [libcsv.lo] Error 127 (ignored)
mv -f .deps/libcsv.Tpo .deps/libcsv.Plo
mv: rename .deps/libcsv.Tpo to .deps/libcsv.Plo: No such file or directory
make: *** [libcsv.lo] Error 1

我正在使用OS X 10.5。经过一番搜索,我发现生成的makefile中有一个空的libtool变量:
<generated makefile>
LD = 
LDFLAGS = 
LIBOBJS = 
LIBS = 
LIBTOOL = 
LIPO = 
LN_S = 
LTLIBOBJS = 
<more generated makefile>

如果我将LIBTOOL设置为libtool,那么一切都很好。我认为我在下面的自动配置或自动化文件中犯了一个错误:

Makefile.am
lib_LTLIBRARIES = libcsv.la
libcsv_la_SOURCES = libcsv.c
include_HEADERS = csv.h
libcsv_la_LDFLAGS = -version-info 3:1:0
ACLOCAL_AMFLAGS = -I m4

configure.ac
dn1 Process this file with autoconf to produce a configure script.
AC_INIT(libcsv.c)
AM_INIT_AUTOMAKE(libcsv, 3.0.1)
AC_PROG_CC
AC_OUTPUT(Makefile)
AC_PROG_LIBTOOL
AC_CONFIG_MACRO_DIR([m4])
AC_CHECK_FUNCS([strerror])
AC_FUNC_MALLOC
C_PROG_RANLIB
AC_PROG_CXX
LT_INIT
LT_OUTPUT
AC_TYPE_SIZE_T

如果有帮助的话,这里是config.log的部分内容:
## ------------------ ##
## Running config.lt. ##
## ------------------ ##
config.lt:680: creating libtool
configure:17115: checking for size_t
configure:17115: gcc -c -g -O2  conftest.c >&5
configure:17115: $? = 0
configure:17115: gcc -c -g -O2  conftest.c >&5
conftest.c: In function 'main':
conftest.c:62: error: syntax error before ')' token
configure:17115: $? = 1
configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME ""
| #define PACKAGE_TARNAME ""
| #define PACKAGE_VERSION ""
| #define PACKAGE_STRING ""
| #define PACKAGE_BUGREPORT ""
| #define PACKAGE_URL ""
| #define PACKAGE "libcsv"
| #define VERSION "3.0.1"
| #define STDC_HEADERS 1
| #define HAVE_SYS_TYPES_H 1
| #define HAVE_SYS_STAT_H 1
| #define HAVE_STDLIB_H 1
| #define HAVE_STRING_H 1
| #define HAVE_MEMORY_H 1
| #define HAVE_STRINGS_H 1
| #define HAVE_INTTYPES_H 1
| #define HAVE_STDINT_H 1
| #define HAVE_UNISTD_H 1
| #define HAVE_DLFCN_H 1
| #define LT_OBJDIR ".libs/"
| #define HAVE_STRERROR 1
| #define HAVE_STDLIB_H 1
| #define HAVE_MALLOC 1
| /* end confdefs.h.  */
| #include <stdio.h>
| #ifdef HAVE_SYS_TYPES_H
| # include <sys/types.h>
| #endif
| #ifdef HAVE_SYS_STAT_H
| # include <sys/stat.h>
| #endif
| #ifdef STDC_HEADERS
| # include <stdlib.h>
| # include <stddef.h>
| #else
| # ifdef HAVE_STDLIB_H
| #  include <stdlib.h>
| # endif
| #endif
| #ifdef HAVE_STRING_H
| # if !defined STDC_HEADERS && defined HAVE_MEMORY_H
| #  include <memory.h>
| # endif
| # include <string.h>
| #endif
| #ifdef HAVE_STRINGS_H
| # include <strings.h>
| #endif
| #ifdef HAVE_INTTYPES_H
| # include <inttypes.h>
| #endif
| #ifdef HAVE_STDINT_H
| # include <stdint.h>
| #endif
| #ifdef HAVE_UNISTD_H
| # include <unistd.h>
| #endif
| int
| main ()
| {
| if (sizeof ((size_t)))
|       return 0;
|   ;
|   return 0;
| }
configure:17115: result: yes

有人知道我做错了什么吗?谢谢。
3个回答

7
我对你的问题没有确定的答案,但我首先建议你将AC_OUTPUT放在configure.ac的末尾,在LT_INIT之后。虽然这并不完全正确,但可以将configure.ac的内容依次扩展为逐个执行的shell脚本片段。如果在找到libtool之前发出已配置的Makefile,那么这可能解释了LIBTOOL为空的原因。
您的configure.ac的相当常规的布局应该如下:
dnl Process this file with autoconf to produce a configure script.
AC_INIT(libcsv.c)
AM_INIT_AUTOMAKE(libcsv, 3.0.1)
AC_CONFIG_MACRO_DIR([m4])

dnl find programs
AC_PROG_CC
AC_PROG_CXX
LT_INIT
AC_PROG_RANLIB

dnl check functionality
AC_CHECK_FUNCS([strerror])
AC_FUNC_MALLOC
AC_TYPE_SIZE_T

AC_OUTPUT(Makefile)

我认为你不需要使用 LT_OUTPUT,而且文档指出AC_PROG_LIBTOOLLT_INIT的一个弃用的同义词(因此两者都使用可能会有问题)。
(顺便提一句,注意OS X有一个名为libtool的命令,它与GNU Libtool无关。我很确定这不是你在这里遇到的问题,但这是一个曾经困惑人们的陷阱)

Norman,非常感谢您。将AC_OUTPUT移到文件末尾,然后删除AC_PROG_LIBTOOL就解决了问题。 - robertpostill

1

您可以尝试通过运行libtoolize --force来加强libtool集成(我在不同主机上遇到了许多不兼容的libtool版本问题,libtoolize --force在这种情况下非常有帮助)。此外,请注意configure输出中的libtool消息,它们必须像这样:

checking if libtool supports shared libraries... yes
configure: creating libtool
appending configuration tag "CXX" to libtool
appending configuration tag "F77" to libtool

特别是输出中必须包含configure: creating libtool行。


嗨Rudi,感谢您的回复。我重新运行了libtoolize --force,并观察到以下输出: checking how to hardcode library paths into programs... immediate configure: creating ./config.lt config.lt: creating libtool checking for size_t... yes但在make步骤中仍然出现相同的响应,所以恐怕这并没有解决问题。 - robertpostill
你可以通过执行 sh -x configure 命令来运行配置脚本并获取更详细的输出,然后在输出中搜索 LIBTOOL=。同时,在 configure 脚本中查找 LIBTOOL= 行(在上面应该有一行 # Always use our own libtool.)。顺便问一下:使用哪个版本的 autoconf 创建了 configure 脚本(configure --help)?也许使用更新的 autoconf+aclocal+automake+libtool 工具重新生成构建系统可能会有所帮助(首先备份,因为这一步可能会严重破坏事情)。 - Rudi
Rudi, 抱歉回复晚了,我没有检查到有评论。无论如何,./configure --version 返回: $ ./configure --version configure 由GNU Autoconf 2.65生成 版权所有(C)2009年自由软件基金会。 此配置脚本是自由软件;自由软件基金会授予无限制的复制、分发和修改权限。 - robertpostill
在configure中搜索LIBTOOL,结果如下: grep LIBTOOL configure LIBTOOL LIBTOOL_DEPS="$ltmain" LIBTOOL='$(SHELL) $(top_builddir)/libtool'

### BEGIN LIBTOOL CONFIG

### END LIBTOOL CONFIG

### BEGIN LIBTOOL TAG CONFIG: CXX

### END LIBTOOL TAG CONFIG: CXX

- robertpostill

0

我的 configure.ac 文件只包含:

LT_INIT([dlopen])
AC_SUBST([LIBTOOL_DEPS])

LT_OUTPUT 用于在 configure 中使用 libtool 进行后续测试,需要一个 config.lt 来设置。我从未使用过它,所以不知道其中的所有细节,但是删除该行代码并查看是否解决了您的问题是无妨的。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接