gcc mismatched-tags选项提供了“无法识别的命令行选项" [英] gcc mismatched-tags option giving `unrecognized command line option`

查看:124
本文介绍了gcc mismatched-tags选项提供了“无法识别的命令行选项"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在gcc上激活选项 -Wmismatched-tags (检测不一致的类/结构声明,这可能在使用正向声明时发生),但是在Ubuntu上我得到了

I was trying to activate the option -Wmismatched-tags on gcc (detect inconsistent class/struct declaration, which might happens when using forward declaration), but on Ubuntu I get

c++: error: unrecognized command line option '-Wmismatched-tags'

我的gcc版本:

# gcc --version
gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
Copyright (C) 2019 Free Software Foundation, Inc.

在这里看起来好像它已集成在gcc 4.9.0中 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61339

Looking here it seems like it was integrated in gcc 4.9.0 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61339

我做错什么了吗,或者该选项实际上不再可用了?

Am I doing something wrong, or is the option actually not available anymore?

我知道 GCC是否可以生成struct/class名称VS等不匹配?,但是答案只有10岁了,我希望在此期间情况有所改善.

I am aware of Can GCC produce struct/class name mismatches like VS?, however the answer is 10 years old and I was hoping things had improved in the meantime.

背景:在我们也使用clang进行构建并将这些不一致视为错误的项目中,我需要这样做.

Background: I need this in a project where we also build with clang, and where these inconsistencies are treated as error.

推荐答案

在这里看起来好像它已集成在gcc 4.9.0中 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61339

实际上不是.据报道是在2014年,但正如OP在第5个帖子:

Actually, it doesn't. It was reported in 2014 but as OP explained in #5th post:

我不能代表MS,但产生了我发布的原始警告c确实似乎担心标签不匹配.

在gcc中, -Wmismatched-tags 仅在2019年12月推出,并且成为GCC 10版本的一部分:

In gcc -Wmismatched-tags was introduced only in December 2019 and became a part of GCC 10 release:

$ git describe e8f1ade269a39ea86a76a2440818e1512ed480ee
basepoints/gcc-10-5517-ge8f1ade269a

幸运的是,这些天我们有docker和GCC官方发布了正式发布为docker映像:

Luckily, these days we have docker and official GCC releases are officially distributed as docker images:

$ docker search gcc
NAME                               DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
gcc                                The GNU Compiler Collection is a compiling s…   587                 [OK]
(...)

所以您可以这样做:

docker run --rm -it gcc

并将源目录安装到Docker容器中或对docker使用 TRAMP集成容器或其他任何容器将代码放入容器并在其中使用最新gcc的首选工具:

and either mount your source directory into the docker container or use TRAMP integration for docker containers or any other preferred tool to put your code into the container and use the newest gcc inside it:

root@53d309d5d619:/# g++ --version
g++ (GCC) 10.2.0
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

root@53d309d5d619:/# g++  hello.cpp  -o hello -Wmismatched-tags

这篇关于gcc mismatched-tags选项提供了“无法识别的命令行选项"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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