How to disable C compiler in C++ Autotools project

2019-03-04 18:06发布

I'm in the early stages of adding Autotools support to a C++ library. At this point I'm running autoreconf with the following configuration.

$ 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])

It is producing:

$ 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

I'm trying to tackle the error: C source seen but 'CC' is undefined issue first.

Conventional wisdom based on mailing list reading is to add AC_PROG_CC to work around the issue. I really don't feel like working around the problems C++ flags are going to cause a C compiler, especially on compilers like IBM's xlc and Sun's cc. It also seem wrong given GNU is all about user choice.

How do I tell Autotools this project is a C++ project, and it should not do anything with C or a C compiler?


Here are some of the issues it is causing.

$ 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条回答
forever°为你锁心
2楼-- · 2019-03-04 18:27

When you define a program like bin_PROGRAMS=cryptest, automake looks for cryptest_SOURCES to figure out what are the source files for cryptest. If you don't define cryptest_SOURCES, automake will automatically generate one by appending ".c" (by default) to the program name, e.g. as if you had defined cryptest_SOURCES=cryptest.c. To override the default, you could explicitly define the source for each of your programs, e.g. cryptest_SOURCES=cryptest.cpp, or you could define AM_DEFAULT_SOURCE_EXT=.cpp to make all automatically generated source file names end in ".cpp" instead of ".c".

Of course, if your source name doesn't match the program name, or there are multiple sources (including any header files you want to be included by "make dist"), you're going to need the explicit definition anyway, e.g. cryptest_SOURCES=cryptest.cpp cryptest-part2.cpp cryptest.h.

See: https://www.gnu.org/software/automake/manual/automake.html#Default-_005fSOURCES

Edited to add: Assuming you're going to be using AC macros to test features of the compiler, you're going to want to call AC_LANG([C++]) first (after AC_PROG_CXX) to tell autoconf that it should be testing the C++ compiler, not the C compiler.

查看更多
登录 后发表回答