LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1303|回复: 6

openSUSE 10.2 C/C++(gcc)问题???????

[复制链接]
发表于 2006-12-27 21:20:57 | 显示全部楼层 |阅读模式
C语言的Hello.c如下:
#include<stdio>
int main()
{
printf("Hello!\n");
return 0;
}
编译出现下面的错误:
gnome@openSUSE:~> gcc Hello.c
Hello.c:1:16: error: stdio: 没有那个文件或目录
Hello.c: In function ‘main’:
Hello.c:4: warning: incompatible implicit declaration of built-in function ‘printf’

C++语言的Hello.cpp如下:
#include<iostream>
using namespace std;
int main()
{
cout<<"Hello!"<<endl;
return 0;
}
编译出现如下错误:
gnome@openSUSE:~> gcc Hello.cpp
/tmp/cczvMwjg.o: In function `__static_initialization_and_destruction_0(int, int)':
Hello.cpp.text+0x23): undefined reference to `std::ios_base::Init::Init()'
/tmp/cczvMwjg.o: In function `__tcf_0':
Hello.cpp.text+0x6c): undefined reference to `std::ios_base::Init::~Init()'
/tmp/cczvMwjg.o: In function `main':
Hello.cpp.text+0x8e): undefined reference to `std::cout'
Hello.cpp.text+0x93): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std:perator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
Hello.cpp.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> >&)'
Hello.cpp.text+0xa3): undefined reference to `std::basic_ostream<char, std::char_traits<char> >:perator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))'
/tmp/cczvMwjg.o.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status

程序应该没有错误,应该是库出了问题,没重装的时候只装了KDE都是没有出现这种情况,重装了以后GNOME和KDE全部装了,就出错了!!!
对库不是很了解,麻烦高手指点一下!!!
发表于 2006-12-27 22:31:00 | 显示全部楼层
#include<stdio.h>
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-12-27 23:20:46 | 显示全部楼层
Post by netman網中人
#include<stdio.h>

试过了,还是不的行哈!
回复 支持 反对

使用道具 举报

发表于 2006-12-27 23:35:41 | 显示全部楼层
在SLED下
gcc -p -g Hello.c
是正常的
回复 支持 反对

使用道具 举报

发表于 2006-12-28 09:09:26 | 显示全部楼层
#include<cstdio>

g++ file.cpp -o filename
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-12-28 10:31:59 | 显示全部楼层
感谢各位了哈,按照楼上两位兄弟的方法分别解决了C与C++的问题!!
我还想问一下,为什么在openSUSE下面使用gcc上好像和标准的有点区别,比如在fedora下面就完全可以通过的,那里有在openSUSE下面关于编程方面的书籍??谢谢!!!!
回复 支持 反对

使用道具 举报

发表于 2006-12-29 17:50:44 | 显示全部楼层
标准C++的写法:
#include<iostream>
using namespace std;
int main()
{
    std::cout<<"Hello!"<<endl;
    return 0;
}

用这个命令:g++来编译,不知道怎么用的话用man g++
回复 支持 反对

使用道具 举报

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

本版积分规则

快速回复 返回顶部 返回列表