如何在C ++ Autotools项目中禁用C编译器

时间:2017-11-01 17:01:23

标签: c++ autotools autoconf

我在向C ++库添加Autotools支持的早期阶段。此时,我使用以下配置运行autoreconf

$ cat Makefile.am
AUTOMAKE_OPTIONS = foreign
bin_PROGRAMS=cryptest

$ cat configure.ac
AC_INIT(Crypto++, 6.0, http://www.cryptopp.com/wiki/Bug_Report)
AM_INIT_AUTOMAKE
AC_PROG_CXX
AC_CONFIG_FILES([Makefile])

正在制作:

$ autoreconf --install --force
/usr/share/automake-1.15/am/depend2.am: error: am__fastdepCC does not appear in AM_CONDITIONAL
/usr/share/automake-1.15/am/depend2.am:   The usual way to define 'am__fastdepCC' is to add 'AC_PROG_CC'
/usr/share/automake-1.15/am/depend2.am:   to 'configure.ac' and run 'aclocal' and 'autoconf' again
Makefile.am: error: C source seen but 'CC' is undefined
Makefile.am:   The usual way to define 'CC' is to add 'AC_PROG_CC'
Makefile.am:   to 'configure.ac' and run 'autoconf' again.
autoreconf: automake failed with exit status: 1

我首先尝试解决 error: C source seen but 'CC' is undefined 问题。

基于邮件列表阅读的传统智慧是添加AC_PROG_CC来解决问题。我真的不想解决C ++标志会导致C编译器的问题,特别是在像IBM的xlc和Sun的cc等编译器上。鉴于GNU完全是用户选择,这似乎也是错误的。

我如何告诉Autotools这个项目是一个C ++项目,它不应该用C或C编译器做任何事情?

以下是它引起的一些问题。

$ egrep 'CC|CFLAGS' Makefile
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
        $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
...
LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
        $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \
        $(AM_CFLAGS) $(CFLAGS)
...
CCLD = $(CC)
...
LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
        $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
$ autoreconf --version
autoreconf (GNU Autoconf) 2.69

$ autoconf --version
autoconf (GNU Autoconf) 2.69

$ automake --version
automake (GNU automake) 1.15

1 个答案:

答案 0 :(得分:2)

当您定义类似bin_PROGRAMS=cryptest的程序时,automake会查找cryptest_SOURCES以确定cryptest的源文件是什么。如果您没有定义cryptest_SOURCES,则automake会自动生成一个,方法是将“.c”(默认情况下)附加到程序名称,例如:好像你定义了cryptest_SOURCES=cryptest.c。要覆盖默认值,您可以明确定义每个程序的来源,例如cryptest_SOURCES=cryptest.cpp,或者您可以定义AM_DEFAULT_SOURCE_EXT=.cpp以使所有自动生成的源文件名以“.cpp”而不是“.c”结尾。

当然,如果您的源名称与程序名称不匹配,或者有多个源(包括您希望“make dist”包含的任何头文件),那么无论如何您都需要明确的定义,例如cryptest_SOURCES=cryptest.cpp cryptest-part2.cpp cryptest.h

请参阅:https://www.gnu.org/software/automake/manual/automake.html#Default-_005fSOURCES

编辑添加:假设您将使用AC宏来测试编译器的功能,您将首先要调用AC_LANG([C++])(在AC_PROG_CXX之后)告诉autoconf它应该测试C ++编译器,而不是C编译器。

相关问题