Gcc 奇怪的错误——链接错误?与海湾合作委员会

Gcc 奇怪的错误——链接错误?与海湾合作委员会,gcc,g++,Gcc,G++,我不能再用gcc编译了 使用gcc-o run mytest.cpp,给出: mytest.cpp:12:9: error: expected ‘;’ at end of member declaration mytest.cpp:12:14: error: expected unqualified-id before ‘;’ token mytest.cpp: In constructor ‘matrix::matrix()’: mytest.cpp:23:26: error: invalid

我不能再用gcc编译了

使用
gcc-o run mytest.cpp
,给出:

mytest.cpp:12:9: error: expected ‘;’ at end of member declaration
mytest.cpp:12:14: error: expected unqualified-id before ‘;’ token
mytest.cpp: In constructor ‘matrix::matrix()’:
mytest.cpp:23:26: error: invalid conversion from ‘int**’ to ‘int’ [-fpermissive]
mytest.cpp:24:24: error: expected ‘;’ before ‘)’ token
mytest.cpp:25:22: error: invalid types ‘int[int]’ for array subscript
mytest.cpp:28:13: error: no match for ‘operator~’ in ‘~matrix()’
mytest.cpp:28:13: note: candidates are:
In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ios:43:0,
                 from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/ostream:40,
                 from /usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/iostream:40,
                 from mytest.cpp:1:
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/bits/ios_base.h:89:3: note: std::_Ios_Fmtflags std::operator~(std::_Ios_Fmtflags)
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/bits/ios_base.h:89:3: note:   no known conversion for argument 1 from ‘matrix’ to ‘std::_Ios_Fmtflags’
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/bits/ios_base.h:129:3: note: std::_Ios_Openmode std::operator~(std::_Ios_Openmode)
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/bits/ios_base.h:129:3: note:   no known conversion for argument 1 from ‘matrix’ to ‘std::_Ios_Openmode’
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/bits/ios_base.h:167:3: note: std::_Ios_Iostate std::operator~(std::_Ios_Iostate)
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.3/include/g++-v4/bits/ios_base.h:167:3: note:   no known conversion for argument 1 from ‘matrix’ to ‘std::_Ios_Iostate’
mytest.cpp:28:14: error: expected ‘;’ before ‘{’ token
mytest.cpp: In function ‘int main()’:
mytest.cpp:45:3: error: ‘class matrix’ has no member named ‘add’
mytest.cpp: At global scope:
mytest.cpp:52:28: error: no ‘matrix matrix::add(matrix)’ member function declared in class ‘matrix’
该守则使用:

#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#包括
#包括
#包括
#包括
如果我只使用iostream编译一个简单的hello-world代码,它会给出:

/tmp/ccGrqvwo.o: In function `main':
simple.cpp:(.text+0x21): undefined reference to `std::cout'
simple.cpp:(.text+0x29): 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*)'
/tmp/ccGrqvwo.o: In function `__static_initialization_and_destruction_0(int, int)':
simple.cpp:(.text+0x7c): undefined reference to `std::ios_base::Init::Init()'
simple.cpp:(.text+0x91): undefined reference to `std::ios_base::Init::~Init()'
...
/tmp/ccGrqvwo.o:在函数'main'中:
simple.cpp:(.text+0x21):对“std::cout”的未定义引用

simple.cpp:(.text+0x29):未定义对“std::basic_ostream&std::operator”的引用第一个错误看起来与MyTest.cpp的第11行缺少分号一样无害。在修复该错误之前,您可能会忽略后续错误,因为语法错误可能会导致编译器的解析器查找各种虚假的其他错误

至于链接问题,正如其他人所指出的,
g++
将自动链接到
libstdc++
,而您必须通过
-lstdc++
指示
gcc
这样做,最后

我再次完全删除了gcc,g++。
我重新安装,我符号链接gcc和g++现在它可以工作了

对于gcc,错误消息告诉您忘记链接到
libstdc++
。g++自动链接到
libstdc++
。至于上半部分,它不清楚,没有代码,很难说。
gcc
用于编译C代码<代码> G++< /COD>用于编译C++代码。“重复的话,直到不同的地方变得明显……”Ali:代码运行良好(测试)。我不知道我用GCC做了什么,现在它不起作用。@ TalAlb:Cube是C++(我用C++编译GC+没有问题),我用GCC做了一些事情,现在它不起作用。不幸的是,它不是分号。代码运行良好。它只使用了“cmath,cstdlib,cstdio”。这些代码中有些地方出现了问题。