Linux下GCC 编译器有关问题
Linux下GCC 编译器问题C/C++ code#include iostream#include stringusing namespace stdvoid main(){
Linux下GCC 编译器问题
C/C++ code#include <iostream>#include <string>using namespace std;void main(){ string s = "Hello world"; cout << s << endl;}
初次使用GCC 编程。。
首先用 vi la.cpp 建立.cpp文件,编辑之,代码如上所示。
然后 gcc -c la.cpp ,生成la.o
然后 gcc -o la la.cpp
就悲剧了,一大堆 错误。。
其中有这一行
undef ined reference to 'std::out'
[解决办法]楼主,你写的是C++的,不能用GCC来编译啊。
自己装上g++,就好了
[解决办法]g++编译。
[解决办法][解决办法]下面时源代码的运行结果:
[root@localhost only_for_testing]# g++ test.cpp -o ts
test.cpp:4: 错误:‘::main’必须返回‘int’
下面是把main函数的返回值改为int并return 0之后的结果,其他代码没任何改动。
[root@localhost only_for_testing]# g++ test.cpp -o ts
[root@localhost only_for_testing]# ./ts
Hello world
PS:用的是sentos系统下的G++。