|
楼主 |
发表于 2006-9-18 11:39:31
|
显示全部楼层
还有一个奇怪的问题
如果程序源文件是.c文件的话,那gcc会报错
gcc hel.c -o hel
hel.c:1:22: error: iostream.h: No such file or directory
hel.c: 在函数 ‘main’ 中:
hel.c:4: 错误: ‘cout’ 未声明 (在此函数内第一次使用)
hel.c:4: 错误: (即使在一个函数内多次出现,每个未声明的标识符在其
hel.c:4: 错误: 所在的函数内只报告一次。)
如果我把文件名改成.cpp文件之后,gcc输出
gcc hel.cpp -o hel
In file included from /usr/lib/gcc/i486-linux-gnu/4.0.3/../../../../include/c++/4.0.3/backward/iostream.h:31,
from hel.cpp:1:
/usr/lib/gcc/i486-linux-gnu/4.0.3/../../../../include/c++/4.0.3/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 <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.
/tmp/cct44fVH.o: In function `main':hel.cpp.text+0x27):对‘std::cout’未定义的 引用
:hel.cpp.text+0x2c):对‘std::basic_ostream<char, std::char_traits<char> >& std:perator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)’未定义的引用
:hel.cpp.text+0x3c):对‘std::basic_ostream<char, std::char_traits<char> >& std:perator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char)’未定义的引用
/tmp/cct44fVH.o: In function `__tcf_0':hel.cpp.text+0x56):对‘std::ios_base::Init::~Init()’未定义的引用
/tmp/cct44fVH.o: In function `__static_initialization_and_destruction_0(int, int)':hel.cpp.text+0x7f):对‘std::ios_base::Init::Init()’未定义的引用
/tmp/cct44fVH.o.eh_frame+0x11):对‘__gxx_personality_v0’未定义的引用
collect2: ld 返回 1
如果用g++的话
g++ hel.cpp -o hel
In file included from /usr/lib/gcc/i486-linux-gnu/4.0.3/../../../../include/c++/4.0.3/backward/iostream.h:31,
from hel.cpp:1:
/usr/lib/gcc/i486-linux-gnu/4.0.3/../../../../include/c++/4.0.3/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 <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.
从这个看来,gcc跟g++的输出最前面的一段是相同的。gcc应该是可以根据文件名的扩展名部分来识别源文件的,但为什么用G++可以编译成功,用gcc就不行呢?
另外,如果按照提示用<iostream>代替<iostream.h>结果连g++都出错,除了用-Wno-deprecated之外,有什么其他办法? |
|