为什么OpenBSD的G ++使系统标头默认为C链接? [英] Why does OpenBSD's G++ make system headers default to C linkage?

查看:119
本文介绍了为什么OpenBSD的G ++使系统标头默认为C链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将一些代码移植到OpenBSD 5.0,并且遇到了这个非常奇怪的问题.

I am porting some code to OpenBSD 5.0 and I ran into this very strange problem.

我的构建设置使用-isystem /usr/local/include.很难记住,但我相信我这样做是为了避免在将Boost安装到/usr/local/include的系统类型(例如BSD)上使用-Wall引起大量的编译器警告.这似乎在FreeBSD上效果很好.

My build settings use -isystem /usr/local/include. It is hard to remember but I believe I did that to avoid masses of compiler warnings from my use of -Wall on system types -- like BSD -- that install Boost to /usr/local/include. This seems to work great on FreeBSD.

因此,请使用以下程序:

So take the following program:

#include <boost/array.hpp>

int main()
{
        return 0;
}

然后使用以下代码进行构建:

Then build it with:

c++ -O2 -pipe -isystem /usr/local/include -std=c++98 -o test test.cxx

在OpenBSD上,我发现我得到了:

On OpenBSD I discovered that I get:

In file included from /usr/include/g++/string:46,
             from /usr/include/g++/stdexcept:44,
             from /usr/local/include/boost/array.hpp:35,
             from test.cxx:1:
/usr/include/g++/bits/stringfwd.h:48: error: template with C linkage

从那里开始只会变得更糟.

And it only gets worse from there.

我发现我可以通过执行以下操作来更改错误消息:

I discovered that I can change the error messages by doing things such as:

#include <stdexcept>

但这只会使问题更进一步.好像编译器将每个包含文件都包装在extern "C"块中一样.

But that only pushes the problem farther back. It is as if the compiler is wrapping every include file inside an extern "C" block.

到目前为止,唯一可行的方法似乎是改回使用-I /usr/local/include并接受来自-Wall -W的噪声.

So far, the only working method seems to be to change back to using -I /usr/local/include and accept the noise from -Wall -W.

问题是,为什么OpenBSD会这样做? GCC必须使用某种自定义技巧来处理包含这种方式的系统.

The question is, why did OpenBSD do this? It has to be some kind of custom hack to GCC to treat system includes this way.

推荐答案

最近在使用独立式交叉编译器时遇到了相同的问题.

Recently came across the same issue when working with a freestanding cross compiler.

当按如下所示定位旧"系统时,G ++似乎会这样做:

It seems G++ will do this when targeting "old" systems as indicated here:

http://tigcc.ticalc.org/doc/cpp.html#SEC9a

在非常老的系统上,某些预定义的系统头目录得到了更特殊的对待. GNU C ++认为在这些目录中的标头中的代码被外部的"C"块包围.无法通过#pragma或命令行来请求此行为.

On very old systems, some of the pre-defined system header directories get even more special treatment. GNU C++ considers code in headers found in those directories to be surrounded by an extern "C" block. There is no way to request this behavior with a #pragma, or from the command line.

希望这可以为将来的旅行者提供一些见识.

Hope this may provide some insight to future travelers here.

这篇关于为什么OpenBSD的G ++使系统标头默认为C链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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