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

查看:45
本文介绍了如何在 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

我正在尝试解决错误:已看到 C 源代码但未定义CC" 问题.

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 的源文件.如果您没有定义 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天全站免登陆