如何在C ++ Autotools项目中禁用C编译器 [英] How to disable C compiler in C++ Autotools project

查看:133
本文介绍了如何在C ++ Autotools项目中禁用C编译器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正处于将Autotools支持添加到C ++库的早期阶段.此时,我正在使用以下配置运行autoreconf.

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

它正在产生:

$ 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 问题.

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

基于邮件列表阅读的传统观点是添加AC_PROG_CC来解决此问题.我真的不希望解决C ++标志会导致C编译器出现的问题,尤其是在IBM xlc和Sun cc等编译器上.鉴于GNU完全取决于用户的选择,这似乎也是错误的.

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.

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

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

推荐答案

定义诸如bin_PROGRAMS=cryptest之类的程序时,automake会查找cryptest_SOURCES以确定哪些是最加密的源文件.如果您未定义cryptest_SOURCES,automake将通过在程序名称后附加".c"(默认)来自动生成一个.就像您已定义cryptest_SOURCES=cryptest.c一样.要覆盖默认值,您可以为每个程序明确定义源代码,例如cryptest_SOURCES=cryptest.cpp,或者您可以定义AM_DEFAULT_SOURCE_EXT=.cpp,以使所有自动生成的源文件名都以".cpp"而不是".c"结尾.

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".

当然,如果您的源名称与程序名称不匹配,或者有多个源(包括您要包含在"make dist"中的任何头文件),则无论如何都将需要显式定义,例如cryptest_SOURCES=cryptest.cpp cryptest-part2.cpp cryptest.h.

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.

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

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

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.

这篇关于如何在C ++ Autotools项目中禁用C编译器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆