用g++编译最简单的C++程序hello.C出现可以用-Wno-deprecated屏蔽的警告,想问个究竟
2014-06-24 17:48
393 查看
程序如下:
#include <iostream.h>
main ()
{
cout << "hello, world!" << endl;
}
警告如下:
in file included from /usr/include/c++/3.2.2/backward/iostream.h:31,
from hello.c:1:
/usr/include/c++/3.2.2/backward/backward_warning.h:32:2: warning:
#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 <sstream> instead of
the deprecated header <strstream.h>. to disable this warning use -wno-deprecated.
出现上面的警告是什么原因,要怎么解决才可以不用-wno-deprecated参数直接编译。
网友:blh
c++的程序和c时有区别的,修改如下
#include <iostream>
using namespace std;
main ()
{
cout << "hello, world!" << endl;
}
网友:ybei
<iostream.h>是老的c++函数库,g++建议你使用新的<iostream>
使用方法就像楼上说的
要注意using namespace std 不能省
网友:interbanker
#include <iostream.h>
main ()
{
cout << "hello, world!" << endl;
}
------------------------------------
当使用gcc编译的时候提示出错:
gcc hello.cpp -o hello
undefined first referenced
symbol in file
endl(ostream &) /usr/tmp/cckxbuns.o
ostream::operator<<(ostream &(*)(ostream &))/usr/tmp/cckxbuns.o
cout /usr/tmp/cckxbuns.o
ostream::operator<<(char const *) /usr/tmp/cckxbuns.o
hello: fatal error: symbol referencing errors. no output written to hello
collect2: ld returned 1 exit status
当使用g++编译
g++ hello.cpp -o hello
编译通过,
我把hello.cpp改成hello.c,还是用g++ hello.c -o hello,编译通过
综上所述,编译不通过的原因不是因为命名空间的问题。
因为gcc编译的是c语言,g++编译的是c++程序。
另注:
gcc assumes preprocessed (.i) files are c and assumes c
style linking.
g++ assumes preprocessed (.i) files are c++ and assumes
c++ style linking.
网友:onlymilan
#include <iostream.h> 是window下的
#include <iostream>
using namespace std; 这才是unix/linux下的
网友:fierygnu
呵呵。
老c++用.h做头文件,没有namespace std,新标准规定不要.h,有namespace。这个跟平台没关系,跟编译器实现遵循的标准有关系。
网友:onlymilan
命名空间是新的c++标准中的,新版本的c++编译器支持命名空间,unix/linux下的g++都支持
所以,在unix/linux下这样写
#include <iostream>
using namespace std;
绝对不会有警告。
而在windows vc++ 下这样写
#include <iostream>
using namespace std;
就会出错。如果使用#include <iostream.h>就没问题。
而在unix/linux下使用#include <iostream.h>就会出警告,因为这是老版本的c++标准
#include <iostream.h>
main ()
{
cout << "hello, world!" << endl;
}
警告如下:
in file included from /usr/include/c++/3.2.2/backward/iostream.h:31,
from hello.c:1:
/usr/include/c++/3.2.2/backward/backward_warning.h:32:2: warning:
#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 <sstream> instead of
the deprecated header <strstream.h>. to disable this warning use -wno-deprecated.
出现上面的警告是什么原因,要怎么解决才可以不用-wno-deprecated参数直接编译。
网友:blh
c++的程序和c时有区别的,修改如下
#include <iostream>
using namespace std;
main ()
{
cout << "hello, world!" << endl;
}
网友:ybei
<iostream.h>是老的c++函数库,g++建议你使用新的<iostream>
使用方法就像楼上说的
要注意using namespace std 不能省
网友:interbanker
#include <iostream.h>
main ()
{
cout << "hello, world!" << endl;
}
------------------------------------
当使用gcc编译的时候提示出错:
gcc hello.cpp -o hello
undefined first referenced
symbol in file
endl(ostream &) /usr/tmp/cckxbuns.o
ostream::operator<<(ostream &(*)(ostream &))/usr/tmp/cckxbuns.o
cout /usr/tmp/cckxbuns.o
ostream::operator<<(char const *) /usr/tmp/cckxbuns.o
hello: fatal error: symbol referencing errors. no output written to hello
collect2: ld returned 1 exit status
当使用g++编译
g++ hello.cpp -o hello
编译通过,
我把hello.cpp改成hello.c,还是用g++ hello.c -o hello,编译通过
综上所述,编译不通过的原因不是因为命名空间的问题。
因为gcc编译的是c语言,g++编译的是c++程序。
另注:
gcc assumes preprocessed (.i) files are c and assumes c
style linking.
g++ assumes preprocessed (.i) files are c++ and assumes
c++ style linking.
网友:onlymilan
#include <iostream.h> 是window下的
#include <iostream>
using namespace std; 这才是unix/linux下的
网友:fierygnu
呵呵。
老c++用.h做头文件,没有namespace std,新标准规定不要.h,有namespace。这个跟平台没关系,跟编译器实现遵循的标准有关系。
网友:onlymilan
命名空间是新的c++标准中的,新版本的c++编译器支持命名空间,unix/linux下的g++都支持
所以,在unix/linux下这样写
#include <iostream>
using namespace std;
绝对不会有警告。
而在windows vc++ 下这样写
#include <iostream>
using namespace std;
就会出错。如果使用#include <iostream.h>就没问题。
而在unix/linux下使用#include <iostream.h>就会出警告,因为这是老版本的c++标准
相关文章推荐
- 用g++编译最简单的C++程序hello.C出现可以用-Wno-deprecated屏蔽的警告,想问个究竟
- G++ 4.4.7 无法编译模板程序,Vs可以,和解?智者尾部留言,本人第一次使用vs pro,通常并且习惯在linux下写些小东西,虽然程序简单;
- 如何去除gcc编译时出现的`deprecated conversion from string constant to ‘char*’’警告
- boj 1328 简单问题 不过要考虑输入大小 long long可以 不过VC++不能编译
- 】【FPGA】quartus II 全编译出现时序警告
- 简单的数组查找算法 出现的错误:数组不可以使用引用传址
- 在VS2005下编译was declared deprecated警告
- 我在运行编译好的程序时,仿真器出现错误警告
- g++ 编译头class的文件 出现expected unqualified-id before ‘namespace’错误的原因
- 使用g++编译一个简单的cc文件
- 编译DirectShow程序时出现Link Error可以考虑的情况
- 解决g++编译出现/usr/bin/ld: cannot find -lc
- 一个简单的动态编译器,支持C#和VB.NET。当你想测试一些简单的代码的时候可以使用。
- 《转》在VS2005下编译was declared deprecated警告
- GCC4.6.1编译Linux内核kernel3.0出现的警告信息(原创)
- Keil MDK 编译 uc/OS-II 出现的警告和错误解决
- 为什么编译内核模块出现XXXfunction undefined的警告
- 解决 Eclipse 下使用 Ant 编译出现问题: 警告:编码 GBK 的不可映射字符
- 是否可以屏蔽‘警告: 聚合或其它 SET 操作消除了空值。’一类警告信息?
- (转)出现这样的警告 warning C4996: strcpy was declared deprecated