免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 4409 | 回复: 12
打印 上一主题 下一主题

初在linux编译C [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-03-10 21:53 |只看该作者 |倒序浏览
hello.C文件:

  1. #include <iostream.h>
  2. void main (void)
  3. {
  4. cout << "Hello ,world!" <<endl;
  5. }
复制代码


  1. [m@localhost C]$ g++ -o hello hello.C
  2. In file included from /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/backward/iostream.h:31,
  3.                  from hello.C:1:
  4. /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.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 <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.
  5. hello.C:2: error: ‘::main’ must return ‘int’
  6. [m@localhost C]$
复制代码


根据提示用  -Wno-deprecated.,上面的话到底指的什么意思呀?????


  1. [m@localhost C]$ g++  -Wno-deprecated -o hello hello.C
  2. hello.C:2: error: ‘::main’ must return ‘int’
  3. [m@localhost C]$
复制代码


不有错,返回类型已经是void了,为什么还要 must return ‘int’

论坛徽章:
1
天蝎座
日期:2013-08-25 10:27:22
2 [报告]
发表于 2009-03-10 21:58 |只看该作者

回复 #1 zengmao 的帖子

要遵循标准

  1. #include <iostream>
  2. using namespace std;

  3. int main()
  4. {
  5.     //写你的代码
  6.     return 0;
  7. }
复制代码

[ 本帖最后由 yangsf5 于 2009-3-10 22:02 编辑 ]

论坛徽章:
0
3 [报告]
发表于 2009-03-10 22:15 |只看该作者
  1. [m@localhost C]$ cat hello.C
  2. #include <iostream>
  3. using namespace std;
  4. int main ()
  5. {
  6. cout << "Hello ,world!" <<endl;
  7. return 0;
  8. }
  9. [m@localhost C]$ gcc -o hello hello.C
  10. /tmp/ccjdqBUO.o: In function `__static_initialization_and_destruction_0(int, int)':
  11. hello.C:(.text+0x23): undefined reference to `std::ios_base::Init::Init()'
  12. /tmp/ccjdqBUO.o: In function `__tcf_0':
  13. hello.C:(.text+0x6c): undefined reference to `std::ios_base::Init::~Init()'
  14. /tmp/ccjdqBUO.o: In function `main':
  15. hello.C:(.text+0x8e): undefined reference to `std::cout'
  16. hello.C:(.text+0x93): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
  17. hello.C:(.text+0x9b): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
  18. hello.C:(.text+0xa3): undefined reference to `std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))'
  19. /tmp/ccjdqBUO.o:(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
  20. collect2: ld returned 1 exit status
  21. [m@localhost C]$
复制代码


这又是怎么回事???????

论坛徽章:
95
程序设计版块每日发帖之星
日期:2015-09-05 06:20:00程序设计版块每日发帖之星
日期:2015-09-17 06:20:00程序设计版块每日发帖之星
日期:2015-09-18 06:20:002015亚冠之阿尔艾因
日期:2015-09-18 10:35:08月度论坛发贴之星
日期:2015-09-30 22:25:002015亚冠之阿尔沙巴布
日期:2015-10-03 08:57:39程序设计版块每日发帖之星
日期:2015-10-05 06:20:00每日论坛发贴之星
日期:2015-10-05 06:20:002015年亚冠纪念徽章
日期:2015-10-06 10:06:482015亚冠之塔什干棉农
日期:2015-10-19 19:43:35程序设计版块每日发帖之星
日期:2015-10-21 06:20:00每日论坛发贴之星
日期:2015-09-14 06:20:00
4 [报告]
发表于 2009-03-10 22:23 |只看该作者
C++ 代码用 g++ 编译

论坛徽章:
0
5 [报告]
发表于 2009-03-10 22:29 |只看该作者
TKS!!!

论坛徽章:
1
天蝎座
日期:2013-08-25 10:27:22
6 [报告]
发表于 2009-03-10 22:45 |只看该作者
补充:
hello.c
---> hello.cpp

论坛徽章:
0
7 [报告]
发表于 2009-03-10 22:57 |只看该作者
C是大写的

和cpp一样也能代表C++吧

论坛徽章:
0
8 [报告]
发表于 2009-03-10 23:28 |只看该作者
同学,赶紧换本新的C++教材吧。你用的这本又老又不标准。

论坛徽章:
1
天蝎座
日期:2013-08-25 10:27:22
9 [报告]
发表于 2009-03-11 09:01 |只看该作者

回复 #7 zengmao 的帖子

恩。。
sorry.
我业务不熟练。。

论坛徽章:
0
10 [报告]
发表于 2009-03-11 10:17 |只看该作者
原帖由 langue 于 2009-3-10 23:28 发表
同学,赶紧换本新的C++教材吧。你用的这本又老又不标准。


Nod.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP