aaaaa007 发表于 2006-6-23 09:44:45

怀疑我电脑上gcc出了问题!老是编译出错(已解决)

+++++++++++++++++++++++++++++++++++
$ cd '/home/mao/练习文挡Qt/C++练习/string'
$ gcc -v
Reading specs from /usr/lib/gcc/i686-magic-linux/3.4.4/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-java-awt=gtk --host=i686-magic-linux
Thread model: posix
gcc version 3.4.4 20050721 (Red Hat 3.4.4-1mgc)
$ make
g++ -c -pipe -Wall -W -O2 -g -pipe -D_FORTIFY_SOURCE=2 -m32 -march=i686 -mcpu=i686 -mtune=i686-DQT_NO_DEBUG -DQT_SHARED -DQT_THREAD_SUPPORT -I/usr/lib/qt-3.3/mkspecs/default -I. -I. -I/usr/lib/qt-3.3/include -o main.o main.cpp
In file included from /usr/lib/gcc/i686-magic-linux/3.4.4/../../../../include/c++/3.4.4/bits/locale_classes.h:47,
               from /usr/lib/gcc/i686-magic-linux/3.4.4/../../../../include/c++/3.4.4/bits/ios_base.h:47,
               from /usr/lib/gcc/i686-magic-linux/3.4.4/../../../../include/c++/3.4.4/ios:49,
               from /usr/lib/gcc/i686-magic-linux/3.4.4/../../../../include/c++/3.4.4/ostream:45,
               from /usr/lib/gcc/i686-magic-linux/3.4.4/../../../../include/c++/3.4.4/iostream:45,
               from main.cpp:1:
./string:1: error: stray '\127' in program
./string:1: error: stray '\1' in program
./string:1: error: stray '\1' in program
./string:1: error: stray '\1' in program
./string:1: error: stray '\2' in program
./string:1: error: stray '\3' in program
./string:1: error: stray '\1' in program
./string:1: error: stray '\137' in program
./string:1: error: stray '\4' in program
./string:1: error: stray '\8' in program
./string:1: error: expected constructor, destructor, or type conversion before numeric constant
./string:1: error: expected `,' or `;' before numeric constant
./string:1: error: stray '\20' in program
./string:1: error: stray '\213' in program
./string:1: error: stray '\8' in program
./string:1: error: missing terminating ' character
./string:3: error: stray '\5' in program
./string:3: error: stray '\16' in program
./string:3: error: stray '\1' in program
./string:4: error: stray '\157' in program
./string:4: error: stray '\4' in program
./string:4: error: stray '\8' in program
./string:4: error: stray '\157' in program
./string:4: error: stray '\4' in program
./string:4: error: stray '\8' in program
./string:4: error: stray '\1' in program
./string:4: error: stray '\16' in program
./string:4: error: stray '\2' in program
./string:4: error: stray '\6' in program
./string:4: error: stray '\16' in program
./string:4: error: stray '\2' in program
./string:5: error: stray '\157' in program
./string:5: error: stray '\4' in program
./string:5: error: stray '\8' in program
./string:5: error: stray '\157' in program
./string:5: error: stray '\4' in program
./string:5: error: stray '\8' in program
./string:5: error: stray '\248' in program
./string:5: error: stray '\248' in program
./string:5: error: stray '\6' in program
./string:5: error: stray '\4' in program
./string:5: error: stray '\4' in program
./string:5: error: stray '\1' in program
./string:5: error: stray '\129' in program
./string:5: error: stray '\4' in program
./string:5: error: stray '\8' in program
./string:5: error: stray '\129' in program
./string:5: error: stray '\4' in program
./string:5: error: stray '\8' in program
./string:5: error: stray '\4' in program
./string:5: error: stray '\4' in program
./string:5: error: stray '\229' in program
./string:5: error: stray '\160' in program
./string:5: error: stray '\160' in program
./string:5: error: stray '\140' in program
./string:5: error: stray '\4' in program
./string:5: error: stray '\8' in program
./string:5: error: stray '\160' in program
./string:5: error: stray '\140' in program
./string:5: error: stray '\4' in program
./string:5: error: stray '\8' in program
./string:5: error: stray '\28' in program
./string:5: error: stray '\28' in program
./string:5: error: stray '\4' in program
./string:5: error: stray '\4' in program
./string:5: error: stray '\229' in program
./string:5: error: stray '\6' in program
./string:5: error: stray '\4' in program
./string:5: error: stray '\4' in program
./string:5: error: stray '\16' in program
./string:5: error: stray '\1' in program
./string:5: error: stray '\2' in program
./string:5: error: stray '\2' in program
./string:5: error: stray '\5' in program
./string:5: error: stray '\17' in program
./string:5: error: stray '\27' in program
./string:5: error: stray '\4' in program
./string:5: error: stray '\16' in program
./string:5: error: stray '\18' in program
./string:5: error: stray '\23' in program
./string:5: error: stray '\24' in program
./string:5: error: stray '\20' in program
./string:6: error: stray '\14' in program
./string:6: error: stray '\1' in program
./string:6: error: stray '\25' in program
./string:6: error: stray '\19' in program
./string:6: error: stray '\26' in program
./string:6: error: stray '\22' in program
./string:6: error: stray '\2' in program
./string:6: error: stray '\8' in program
./string:6: error: stray '\6' in program
./string:7: error: stray '\3' in program
./string:7: error: stray '\7' in program
./string:7: error: stray '\15' in program
./string:7: error: stray '\17' in program
./string:7: error: stray '\5' in program
./string:7: error: stray '\21' in program
./string:7: error: stray '\1' in program
./string:7: error: stray '\172' in program
./string:7: error: stray '\5' in program
./string:7: error: stray '\18' in program
./string:7: error: stray '\1' in program
./string:7: error: stray '\192' in program
./string:7: error: stray '\158' in program
./string:7: error: stray '\4' in program
./string:7: error: stray '\8' in program
./string:7: error: stray '\16' in program
./string:7: error: stray '\25' in program
./string:7: error: stray '\18' in program
./string:7: error: stray '\245' in program
./string:7: error: stray '\1' in program
./string:7: error: stray '\208' in program
./string:7: error: stray '\158' in program
./string:7: error: stray '\4' in program
./string:7: error: stray '\8' in program
./string:7: error: stray '\140' in program
./string:7: error: stray '\17' in program
./string:7: error: stray '\25' in program
./string:7: error: stray '\15' in program
./string:7: error: stray '\157' in program
./string:7: error: stray '\4' in program
./string:7: error: stray '\8' in program
./string:7: error: stray '\17' in program
./string:7: error: stray '\241' in program
./string:7: error: stray '\255' in program
./string:7: error: stray '\1' in program
./string:7: error: stray '\247' in program
./string:7: error: stray '\1' in program
./string:7: error: stray '\18' in program
./string:7: error: stray '\139' in program
./string:7: error: expected declaration before '}' tokenIn file included from /usr/lib/gcc/i686-magic-linux/3.4.4/../../../../include/c++/3.4.4/bits/ios_base.h:47,
               from /usr/lib/gcc/i686-magic-linux/3.4.4/../../../../include/c++/3.4.4/ios:49,
               from /usr/lib/gcc/i686-magic-linux/3.4.4/../../../../include/c++/3.4.4/ostream:45,
               from /usr/lib/gcc/i686-magic-linux/3.4.4/../../../../include/c++/3.4.4/iostream:45,
               from main.cpp:1:
/usr/lib/gcc/i686-magic-linux/3.4.4/../../../../include/c++/3.4.4/bits/locale_classes.h:40:1: unterminated #ifndef
In file included from /usr/lib/gcc/i686-magic-linux/3.4.4/../../../../include/c++/3.4.4/ios:49,
               from /usr/lib/gcc/i686-magic-linux/3.4.4/../../../../include/c++/3.4.4/ostream:45,
               from /usr/lib/gcc/i686-magic-linux/3.4.4/../../../../include/c++/3.4.4/iostream:45,
               from main.cpp:1:
/usr/lib/gcc/i686-magic-linux/3.4.4/../../../../include/c++/3.4.4/bits/ios_base.h:40:1: unterminated #ifndef
In file included from /usr/lib/gcc/i686-magic-linux/3.4.4/../../../../include/c++/3.4.4/ostream:45,
               from /usr/lib/gcc/i686-magic-linux/3.4.4/../../../../include/c++/3.4.4/iostream:45,
               from main.cpp:1:
/usr/lib/gcc/i686-magic-linux/3.4.4/../../../../include/c++/3.4.4/ios:39:1: unterminated #ifndef
In file included from /usr/lib/gcc/i686-magic-linux/3.4.4/../../../../include/c++/3.4.4/iostream:45,
               from main.cpp:1:
/usr/lib/gcc/i686-magic-linux/3.4.4/../../../../include/c++/3.4.4/ostream:40:1: unterminated #ifndef
In file included from main.cpp:1:
/usr/lib/gcc/i686-magic-linux/3.4.4/../../../../include/c++/3.4.4/iostream:39:1: unterminated #ifndef
make: *** 错误 1
$


编译程序的时候无缘无故就出现这个问题。起先还以为是自己程序的问题,后来又编译以前正确的代码,同样出现类似上面红色字体的问题。
我是:
qmake -project
qmake -makefile
make
这样来的。之前的代码都没有出现问题过,所以我怀疑是自己电脑上的gcc的问题。有解决办法吗?
附用来调试的代码段:

#include <iostream>
#include <string>
using namespace std;

int main () {
        string numerics("0123456789");
        string name("r2d2");
        string::size_type pos =name.find_first_of( numerics);
        cout <<pos<<"----"<<name[pos]<<endl;
        return 0;

}

haulm 发表于 2006-6-23 10:08:21

qmake是qt程序的编译器,你写的又不是qt程序,只是一般的c++代码,请你直接执行g++ source.cpp

cjacker 发表于 2006-6-23 10:11:39

Re: 怀疑我电脑上gcc出了问题!老是编译出错.烦请看一下

+++++++++++++++++++++++++++++++++++
$ cd '/home/mao/练习文挡Qt/C++练习/string'
$ gcc -v
Reading specs from /usr/lib/gcc/i686-magic-linux/3.4.4/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-java-awt=gtk --host=i686-magic-linux
Thread model: posix
gcc version 3.4.4 20050721 (Red Hat 3.4.4-1mgc)
$ make
g++ -c -pipe -Wall -W -O2 -g -pipe -D_FORTIFY_SOURCE=2 -m32 -march=i686 -mcpu=i686 -mtune=i686-DQT_NO_DEBUG -DQT_SHARED -DQT_THREAD_SUPPORT -I/usr/lib/qt-3.3/mkspecs/default -I. -I. -I/usr/lib/qt-3.3/include -o main.o main.cpp
In file included from /usr/lib/gcc/i686-magic-linux/3.4.4/../../../../include/c++/3.4.4/bits/locale_classes.h:47,
               from /usr/lib/gcc/i686-magic-linux/3.4.4/../../../../include/c++/3.4.4/bits/ios_base.h:47,
               from /usr/lib/gcc/i686-magic-linux/3.4.4/../../../../include/c++/3.4.4/ios:49,
               from /usr/lib/gcc/i686-magic-linux/3.4.4/../../../../include/c++/3.4.4/ostream:45,
               from /usr/lib/gcc/i686-magic-linux/3.4.4/../../../../include/c++/3.4.4/iostream:45,
               from main.cpp:1:
./string:1: error: stray '\127' in program
./string:1: error: stray '\1' in program
./string:1: error: stray '\1' in program
./string:1: error: stray '\1' in program
./string:1: error: stray '\2' in program
./string:1: error: stray '\3' in program
./string:1: error: stray '\1' in program
./string:1: error: stray '\137' in program
./string:1: error: stray '\4' in program
./string:1: error: stray '\8' in program
./string:1: error: expected constructor, destructor, or type conversion before numeric constant
./string:1: error: expected `,' or `;' before numeric constant
./string:1: error: stray '\20' in program
./string:1: error: stray '\213' in program
./string:1: error: stray '\8' in program
./string:1: error: missing terminating ' character
./string:3: error: stray '\5' in program
./string:3: error: stray '\16' in program
./string:3: error: stray '\1' in program
./string:4: error: stray '\157' in program
./string:4: error: stray '\4' in program
./string:4: error: stray '\8' in program
./string:4: error: stray '\157' in program
./string:4: error: stray '\4' in program
./string:4: error: stray '\8' in program
./string:4: error: stray '\1' in program
./string:4: error: stray '\16' in program
./string:4: error: stray '\2' in program
./string:4: error: stray '\6' in program
./string:4: error: stray '\16' in program
./string:4: error: stray '\2' in program
./string:5: error: stray '\157' in program
./string:5: error: stray '\4' in program
./string:5: error: stray '\8' in program
./string:5: error: stray '\157' in program
./string:5: error: stray '\4' in program
./string:5: error: stray '\8' in program
./string:5: error: stray '\248' in program
./string:5: error: stray '\248' in program
./string:5: error: stray '\6' in program
./string:5: error: stray '\4' in program
./string:5: error: stray '\4' in program
./string:5: error: stray '\1' in program
./string:5: error: stray '\129' in program
./string:5: error: stray '\4' in program
./string:5: error: stray '\8' in program
./string:5: error: stray '\129' in program
./string:5: error: stray '\4' in program
./string:5: error: stray '\8' in program
./string:5: error: stray '\4' in program
./string:5: error: stray '\4' in program
./string:5: error: stray '\229' in program
./string:5: error: stray '\160' in program
./string:5: error: stray '\160' in program
./string:5: error: stray '\140' in program
./string:5: error: stray '\4' in program
./string:5: error: stray '\8' in program
./string:5: error: stray '\160' in program
./string:5: error: stray '\140' in program
./string:5: error: stray '\4' in program
./string:5: error: stray '\8' in program
./string:5: error: stray '\28' in program
./string:5: error: stray '\28' in program
./string:5: error: stray '\4' in program
./string:5: error: stray '\4' in program
./string:5: error: stray '\229' in program
./string:5: error: stray '\6' in program
./string:5: error: stray '\4' in program
./string:5: error: stray '\4' in program
./string:5: error: stray '\16' in program
./string:5: error: stray '\1' in program
./string:5: error: stray '\2' in program
./string:5: error: stray '\2' in program
./string:5: error: stray '\5' in program
./string:5: error: stray '\17' in program
./string:5: error: stray '\27' in program
./string:5: error: stray '\4' in program
./string:5: error: stray '\16' in program
./string:5: error: stray '\18' in program
./string:5: error: stray '\23' in program
./string:5: error: stray '\24' in program
./string:5: error: stray '\20' in program
./string:6: error: stray '\14' in program
./string:6: error: stray '\1' in program
./string:6: error: stray '\25' in program
./string:6: error: stray '\19' in program
./string:6: error: stray '\26' in program
./string:6: error: stray '\22' in program
./string:6: error: stray '\2' in program
./string:6: error: stray '\8' in program
./string:6: error: stray '\6' in program
./string:7: error: stray '\3' in program
./string:7: error: stray '\7' in program
./string:7: error: stray '\15' in program
./string:7: error: stray '\17' in program
./string:7: error: stray '\5' in program
./string:7: error: stray '\21' in program
./string:7: error: stray '\1' in program
./string:7: error: stray '\172' in program
./string:7: error: stray '\5' in program
./string:7: error: stray '\18' in program
./string:7: error: stray '\1' in program
./string:7: error: stray '\192' in program
./string:7: error: stray '\158' in program
./string:7: error: stray '\4' in program
./string:7: error: stray '\8' in program
./string:7: error: stray '\16' in program
./string:7: error: stray '\25' in program
./string:7: error: stray '\18' in program
./string:7: error: stray '\245' in program
./string:7: error: stray '\1' in program
./string:7: error: stray '\208' in program
./string:7: error: stray '\158' in program
./string:7: error: stray '\4' in program
./string:7: error: stray '\8' in program
./string:7: error: stray '\140' in program
./string:7: error: stray '\17' in program
./string:7: error: stray '\25' in program
./string:7: error: stray '\15' in program
./string:7: error: stray '\157' in program
./string:7: error: stray '\4' in program
./string:7: error: stray '\8' in program
./string:7: error: stray '\17' in program
./string:7: error: stray '\241' in program
./string:7: error: stray '\255' in program
./string:7: error: stray '\1' in program
./string:7: error: stray '\247' in program
./string:7: error: stray '\1' in program
./string:7: error: stray '\18' in program
./string:7: error: stray '\139' in program
./string:7: error: expected declaration before '}' tokenIn file included from /usr/lib/gcc/i686-magic-linux/3.4.4/../../../../include/c++/3.4.4/bits/ios_base.h:47,
               from /usr/lib/gcc/i686-magic-linux/3.4.4/../../../../include/c++/3.4.4/ios:49,
               from /usr/lib/gcc/i686-magic-linux/3.4.4/../../../../include/c++/3.4.4/ostream:45,
               from /usr/lib/gcc/i686-magic-linux/3.4.4/../../../../include/c++/3.4.4/iostream:45,
               from main.cpp:1:
/usr/lib/gcc/i686-magic-linux/3.4.4/../../../../include/c++/3.4.4/bits/locale_classes.h:40:1: unterminated #ifndef
In file included from /usr/lib/gcc/i686-magic-linux/3.4.4/../../../../include/c++/3.4.4/ios:49,
               from /usr/lib/gcc/i686-magic-linux/3.4.4/../../../../include/c++/3.4.4/ostream:45,
               from /usr/lib/gcc/i686-magic-linux/3.4.4/../../../../include/c++/3.4.4/iostream:45,
               from main.cpp:1:
/usr/lib/gcc/i686-magic-linux/3.4.4/../../../../include/c++/3.4.4/bits/ios_base.h:40:1: unterminated #ifndef
In file included from /usr/lib/gcc/i686-magic-linux/3.4.4/../../../../include/c++/3.4.4/ostream:45,
               from /usr/lib/gcc/i686-magic-linux/3.4.4/../../../../include/c++/3.4.4/iostream:45,
               from main.cpp:1:
/usr/lib/gcc/i686-magic-linux/3.4.4/../../../../include/c++/3.4.4/ios:39:1: unterminated #ifndef
In file included from /usr/lib/gcc/i686-magic-linux/3.4.4/../../../../include/c++/3.4.4/iostream:45,
               from main.cpp:1:
/usr/lib/gcc/i686-magic-linux/3.4.4/../../../../include/c++/3.4.4/ostream:40:1: unterminated #ifndef
In file included from main.cpp:1:
/usr/lib/gcc/i686-magic-linux/3.4.4/../../../../include/c++/3.4.4/iostream:39:1: unterminated #ifndef
make: *** 错误 1
$


编译程序的时候无缘无故就出现这个问题。起先还以为是自己程序的问题,后来又编译以前正确的代码,同样出现类似上面红色字体的问题。
我是:
qmake -project
qmake -makefile
make
这样来的。之前的代码都没有出现问题过,所以我怀疑是自己电脑上的gcc的问题。有解决办法吗?
附用来调试的代码段:

#include <iostream>
#include <string>
using namespace std;

int main () {
        string numerics("0123456789");
        string name("r2d2");
        string::size_type pos =name.find_first_of( numerics);
        cout <<pos<<"----"<<name[pos]<<endl;
        return 0;

}

你的代码不够干净,

告诉你个办法,用kedit打开,粘贴拷贝到另外一个文件。

aaaaa007 发表于 2006-6-23 10:21:31

用qmake照样可以,不是吗?我也试过用g++ main.cpp,同样出现类似上面红色字体得错误。而且这段程序原本是可以用的。后来做了些修改,就编译出错。我一般会留个备份的,所以原先正确的代码还在,但是同样调试出错。错误如上红色部分。

同样谢谢cjacker,我下次贴帖子的时候会注意的。

aaaaa007 发表于 2006-6-23 10:24:24

qmake其实本质上用的好像还是gcc,所以我觉得用qmake 还是直接g++应该没有问题的。

haulm 发表于 2006-6-23 10:32:09

qmake是qt的一个指令程序,位置在/usr/lib/qt-3.3/bin,/usr/bin/qmake是它的链接。

使用qmake会告诉gcc编译器现在编译的是qt的GUI程序,而不是你现在写的终端对话程序,所以你的代码就一定是错误连连。

aaaaa007 发表于 2006-6-23 10:36:22

版主可以试一下:
qmake -project
qmake -makefile
make
用了就知道他也完全可以用来调试纯的C++代码的。
至少我是。
似乎偏离主题了哦,还是不知道g++出了什么问题。

haulm 发表于 2006-6-23 11:16:00

Sorry,我现在才知道qmake也可以用来编译console程序。

aaaaa007 发表于 2006-6-23 11:26:42

g++ main.cpp 现在又可以了,就刚才在qmake上的纠扯向版主道歉。
但是以前用qmake可以编译的代码 现在用qmake就出错,错误如帖子红色部分。
既然g++没有错误,那应该就是qmake的问题了,难道Qt出错了?

haulm 发表于 2006-6-23 11:35:05

因为以前我用qmake曾经不能编译console程序,所以可能和qmake的版本有关吧。

cjacker 发表于 2006-6-23 11:40:15

我说你的代码不干净不是说你的帖子不干净。

而是说你出错的那个cpp里面确实存在看不到的特殊字符,比如特殊的blank之类的。

所以,用gedit,kedit之类的可以过滤一下子。

尤其粘贴拷贝容易出现这种问题。

yunfan 发表于 2006-6-23 12:09:14

不要直接从网页上复制代码下来, gcc报的就是有不可读字符的错误.

:twisted:

cjacker 发表于 2006-6-23 12:37:33

不要直接从网页上复制代码下来, gcc报的就是有不可读字符的错误.

:twisted:

总算找到一个知音了。

yunfan 发表于 2006-6-23 13:11:33

:mrgreen:嘿嘿, 我以前也犯过这种错误,因为记性差, 还不只犯一次.:neutral:

aaaaa007 发表于 2006-6-23 14:47:58

我的代码都是纯手工录入的。
不过现在qmake又可以了,我什么都没有做,或许真的是特殊字符的错误。
就到这里了 ,在此谢谢各位。
页: [1] 2
查看完整版本: 怀疑我电脑上gcc出了问题!老是编译出错(已解决)