藍森林首頁 | 返回主頁 | 本站地圖 | 站內搜索 | 聯繫信箱 |
 您目前的位置:首頁 > 自由軟件 > 技術交流 > 系統管理


    

藍森林 http://www.lslnet.com 2006年8月18日 15:18


在linux下c ++的編譯的問題?

c++程序windows下運行沒問題的,在linux下用g c c 卻不能通過??
是什麼原因????        請教大家...

應該是你編的c++程序不符合c++標準

具體的編譯錯誤有麼?

-->
很奇怪,在windows 下vc6.0成功運行的程序,
在f c 3 下卻有錯???如下 ???           不知是什麼原因???
[root@localhost ~]# gcc 1.cpp
In file included from /usr/lib/gcc/i386-redhat-linux/3.4.2/../../../../include/c++/3.4.2/backward/iostream.h:31,
                 from 1.cpp:1:
/usr/lib/gcc/i386-redhat-linux/3.4.2/../../../../include/c++/3.4.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.
1.cpp:5: error: `main' must return `int'

-->
我又試了另一個程序。。。。也有錯。 如下。。。

[root@localhost ~]# gcc 2.cpp
In file included from /usr/lib/gcc/i386-redhat-linux/3.4.2/../../../../include/c ++/3.4.2/backward/iostream.h:31,
                 from 1.cpp:1:
/usr/lib/gcc/i386-redhat-linux/3.4.2/../../../../include/c++/3.4.2/backward/back ward_warning.h:32:2: warning: #warning This file includes at least one deprecate d or antiquated header. Please consider using one of the 32 headers found in sec tion 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 h eader <iostream.h>. To disable this warning use -Wno-deprecated.
1.cpp:5: error: `main' must return `int'
[root@localhost ~]# gcc 1.cpp
In file included from /usr/lib/gcc/i386-redhat-linux/3.4.2/../../../../include/c ++/3.4.2/backward/iostream.h:31,
                 from 1.cpp:1:
/usr/lib/gcc/i386-redhat-linux/3.4.2/../../../../include/c++/3.4.2/backward/back ward_warning.h:32:2: warning: #warning This file includes at least one deprecate d or antiquated header. Please consider using one of the 32 headers found in sec tion 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 h eader <iostream.h>. To disable this warning use -Wno-deprecated.
1.cpp:3: error: `main' must return `int'
[root@localhost ~]# gcc 1.cpp
/tmp/ccf02Jjx.o(.text+0xd): In function `std::__verify_grouping(char const*, uns igned int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&':
: undefined reference to `std::basic_string<char, std::char_traits<char>, std::a llocator<char> >::size() const'
/tmp/ccf02Jjx.o(.text+0x60): In function `std::__verify_grouping(char const*, un signed int, std::basic_string<char, std::char_traits<char>, std::allocator<char>  > const&':
: undefined reference to `std::basic_string<char, std::char_traits<char>, std::a llocator<char> >:perator[](unsigned int) const'
/tmp/ccf02Jjx.o(.text+0x9d): In function `std::__verify_grouping(char const*, un signed int, std::basic_string<char, std::char_traits<char>, std::allocator<char>  > const&':
: undefined reference to `std::basic_string<char, std::char_traits<char>, std::a llocator<char> >:perator[](unsigned int) const'
/tmp/ccf02Jjx.o(.text+0xc: In function `std::__verify_grouping(char const*, un signed int, std::basic_string<char, std::char_traits<char>, std::allocator<char>  > const&':
: undefined reference to `std::basic_string<char, std::char_traits<char>, std::a llocator<char> >:perator[](unsigned int) const'
/tmp/ccf02Jjx.o(.text+0x13c): In function `main':
: undefined reference to `std::basic_ofstream<char, std::char_traits<char> >::ba sic_ofstream(char const*, std::_Ios_Openmode)'
/tmp/ccf02Jjx.o(.text+0x170): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >:pe rator<<(int)'
/tmp/ccf02Jjx.o(.text+0x179): In function `main':
: 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*)'
/tmp/ccf02Jjx.o(.text+0x182): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >:pe rator<<(int)'
/tmp/ccf02Jjx.o(.text+0x18b): In function `main':
: 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*)'
/tmp/ccf02Jjx.o(.text+0x194): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >:pe rator<<(int)'
/tmp/ccf02Jjx.o(.text+0x1a6): In function `main':
: undefined reference to `std::basic_ofstream<char, std::char_traits<char> >::~b asic_ofstream()'
/tmp/ccf02Jjx.o(.text+0x1d0): In function `main':
: undefined reference to `std::basic_ofstream<char, std::char_traits<char> >::~b asic_ofstream()'
/tmp/ccf02Jjx.o(.eh_frame+0x12): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status

貼出你的程序看一下(包含的頭文件部分)

[1] main函數需要返回一個int
[2] include <iostream.h>這種寫法已經過時了。寫:
include <iostream>

-->
但是兩個文件在windows下都可以運行?
想問問這是什麼原因??
是不是linux下的gcc 和 windows下的vc 編程方法格式不同?

gcc和vc都不是嚴格遵守c++標準的。對C++的標準的理解也不一樣

-->
那在vc 可以運行的程序在 linux 下不能運行了??
斑竹,你能找個可以在linux下運行的gcc程序嗎?  謝謝

你用g++編譯程序
#include <iostream>

using namespace std ;
.....
你自己試試

-->
好。我去試試。。。。

void main是不行的,要改成
int main  +  return

-->
我試過了,也不行??
你能舉個具體的例子嗎??
貼出來,或給個地址?

vc 好像不是符合gnu標準的說~~~

不同的編譯器的標準不同,一般都不兼容
你找個C++ builder下的sample放在vc++和gcc一樣編譯不了

寫個最簡單的吧,不過這不是C++版面,討論這些。。。
#vi HelloWorld.C                  <==擴展名為大寫C

#include <iostream>
using std::cout;
using std::endl;

int main(){
        cout << "Hello World" << endl;
        return 0;
}

#g++ HelloWorld.C -o HelloWorld    <==此時會有HelloWorld可執行文件產生
# ./HelloWorld
Hello World
#
好了,好長時間沒寫過C++程 序,快忘光了。呵呵。



Copyright © 1999-2000 LSLNET.COM. All rights reserved. 藍森林網站 版權所有。 E-mail : webmaster@lslnet.com