我正在尝试将 libcs​​v 转换为使用 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 var:

<generated makefile>
LD = 
LDFLAGS = 
LIBOBJS = 
LIBS = 
LIBTOOL = 
LIPO = 
LN_S = 
LTLIBOBJS = 
<more generated makefile>

如果我将 LIBTOOL 设置为 libtool,那么一切都很好。我假设我在 autoconf 或 automake 文件中犯了一个错误,如下所示:

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

那么有人知道我做错了什么吗?

提前致谢。

有帮助吗?

解决方案

我没有给你一个明确的答案,但我建议的第一件事就是把你的 AC_OUTPUT 在你的最后 configure.ac, , 之后 LT_INIT. 。它不是 完全地 虽然很简单,但是想想里面的内容也差不了多少 configure.ac 依次扩展为依次执行的 shell 脚本片段。如果您发出配置的 Makefile 在你发现之前 libtool, ,那么这可以解释 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_LIBTOOL 是已弃用的同义词 LT_INIT (所以两者兼而有之可能是自找麻烦)。

(没什么特别的,请注意 OS X 有一个名为 libtool, ,与 GNU Libtool 无关。我很确定这不是你的问题,但这是一个以前让人们感到困惑的问题)

其他提示

您可以尝试通过运行来重新强制 libtool 集成 libtoolize --force (我在不同主机上遇到了很多不兼容的 libtool 版本的问题,libtoolize --force 在这种情况下很有帮助)。还要注意 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 输出中必须存在行。

我的configure.ac只有:

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

LT_OUTPUT 用于在配置本身中使用 libtool 进行后续测试,并且需要 config.lt 来进行设置。我从来没有使用过它,所以我不知道这需要什么,但把那条线拿出来看看是否能解决你的问题也没什么坏处。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top