如果不查看我的XCode项目中的每个源文件,有没有办法找出哪个#include会触发以下警告?
#warning This file includes at least one deprecated or antiquated header.
Please consider using one of the 32 headers found in section 17.4.1.2 of the
C++ standard. Examples include substituting the <X> header for the <X.h>
header for C++ includes, or <iostream> instead of the deprecated header
<iostream.h>. To disable this warning use -Wno-deprecated.
单击XCode中的错误只会打开backward_warning.h文件,这完全没用。
我知道警告意味着什么,我知道如何修复它(当我看到有问题的文件并且可以查看它的#includes)...但我只是不知道如何找到导致错误的文件!
答案 0 :(得分:11)
使用GCC的-H
选项 - 将列出正在包含的头文件(以及嵌套指示,以便您可以查看哪个文件包含哪个标题)。
使用-H
时,错误将放在输出流中,清楚地显示编译器如何到达backward_warning.h
。
例如,当我加入hash_map
时,我会看到:
mikeb@ubuntu:~$ g++ -H -c test.cpp
. /usr/include/c++/4.4/backward/hash_map
.. /usr/include/c++/4.4/backward/backward_warning.h
In file included from /usr/include/c++/4.4/backward/hash_map:60,
from test.cpp:3:
/usr/include/c++/4.4/backward/backward_warning.h:28: warning: #warning This file
includes at least one deprecated or antiquated header which may be removed without
further notice at a future date. Please use a non-deprecated interface with equivalent
functionality instead. For a listing of replacement headers and interfaces, consult
the file backward_warning.h. To disable this warning use -Wno-deprecated.
... a bunch of snipped output ...
另外,/showIncludes
在MSVC中执行相同的功能。
答案 1 :(得分:2)
如您所述,文件/usr/include/c++/4.2.1/backward/backward_warning.h
包含您引用的文本。包含backward_warning.h
的标头是:
/usr/include/c++/4.2.1/backward/algo.h
/usr/include/c++/4.2.1/backward/algobase.h
/usr/include/c++/4.2.1/backward/alloc.h
/usr/include/c++/4.2.1/backward/bvector.h
/usr/include/c++/4.2.1/backward/complex.h
/usr/include/c++/4.2.1/backward/defalloc.h
/usr/include/c++/4.2.1/backward/deque.h
/usr/include/c++/4.2.1/backward/fstream.h
/usr/include/c++/4.2.1/backward/function.h
/usr/include/c++/4.2.1/backward/hash_map.h
/usr/include/c++/4.2.1/backward/hash_set.h
/usr/include/c++/4.2.1/backward/hashtable.h
/usr/include/c++/4.2.1/backward/heap.h
/usr/include/c++/4.2.1/backward/iomanip.h
/usr/include/c++/4.2.1/backward/iostream.h
/usr/include/c++/4.2.1/backward/istream.h
/usr/include/c++/4.2.1/backward/iterator.h
/usr/include/c++/4.2.1/backward/list.h
/usr/include/c++/4.2.1/backward/map.h
/usr/include/c++/4.2.1/backward/multimap.h
/usr/include/c++/4.2.1/backward/multiset.h
/usr/include/c++/4.2.1/backward/new.h
/usr/include/c++/4.2.1/backward/ostream.h
/usr/include/c++/4.2.1/backward/pair.h
/usr/include/c++/4.2.1/backward/queue.h
/usr/include/c++/4.2.1/backward/rope.h
/usr/include/c++/4.2.1/backward/set.h
/usr/include/c++/4.2.1/backward/slist.h
/usr/include/c++/4.2.1/backward/stack.h
/usr/include/c++/4.2.1/backward/stream.h
/usr/include/c++/4.2.1/backward/streambuf.h
/usr/include/c++/4.2.1/backward/strstream
/usr/include/c++/4.2.1/backward/tempbuf.h
/usr/include/c++/4.2.1/backward/tree.h
/usr/include/c++/4.2.1/backward/vector.h
因此,您编译的代码必须包含一个标题,例如:
#include <vector.h>
而不是首选:
#include <vector>
编译器正在变得挑剔。修复是找到包含预标准头的代码并更新它以使用标准头。
(如果你编译git
,你会得到类似的关于弃用函数的警告 - 这些函数是OpenSSL的SHA1函数。对它有礼貌是一种麻烦。)
答案 2 :(得分:0)
你在某处有一个旧式标题。
类似这样的事情
IE:
#include <iostream.h> //instead of <iostream>
#include <stdlib.h> //instead of <cstdlib>
#include <stdio.h> //instead of <cstdio>
如果它是从库中包含的那么我认为你是SOL,我个人不会在图书馆里翻找它以使它工作你必须更新他们使用命名空间。和其他这样的。