我无法用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()'
...
但是如果我使用g++ -o run simple.cpp
而不是gcc
进行编译,那么它就可以了!
对第一个代码执行相同操作,不起作用! (我的意思是使用g ++)
答案 0 :(得分:1)
...最后
我完全删除了gcc,g ++。 我重新安装了,我用符号链接gcc和g ++,现在它可以工作了!
答案 1 :(得分:0)
第一个错误看起来像MyTest.cpp
第11行缺少分号一样无害。在你修复之前,你可能会忽略后续的错误,因为语法错误会导致编译器的解析器找到各种虚假的其他错误。
至于链接问题,正如其他人所指出的那样,g++
会自动与libstdc++
相关联,而您必须通过gcc
指示-lstdc++
这样做。< / p>