对 `std::ios_base::Init::Init()' 的未定义引用 [英] undefined reference to `std::ios_base::Init::Init()'

查看:89
本文介绍了对 `std::ios_base::Init::Init()' 的未定义引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写这段代码是为了读取3个文件,TM是方阵的大小,LER是数组的行数,从最后一个值定义一个非方阵(ler/2)*2

I write this code to read 3 files, TM is the size of square matrix, LER the No. of rows of an array and from last value define a non-square matrix of (ler/2)*2

然后……代码读取一个有关系的文件,都是数字,并赋值给C[ler].

Then... the code read a file with some relations, all are numbers and are assign to C[ler].

然后... C[ler] 被分配给 B[ler/2][2].

Then ... C[ler] is assigned to B[ler/2][2].

B[ler/2][2] 中每行的那些坐标分配给 a 和 b.

Those coordinates, per row, in B[ler/2][2] are assign to a and b.

a 和 b 是矩阵 A[tm][tm] 中要加 1 的行和列.

a and b are the row and the column of the matrix A[tm][tm] where to add 1.

我的代码崩溃了,我看不出是什么错误.

My code crashes and I don't see what the error is.

当我尝试编译它时,编译器gcc -g -o MatSim MatSim.cpp 提示:

When I try to compile it, the compiler gcc -g -o MatSim MatSim.cpp prompted:

/usr/include/c++/4.6/iostream:75: undefined reference to `std::ios_base::Init::Init()'
/usr/include/c++/4.6/iostream:75: undefined reference to `std::ios_base::Init::~Init()'
collect2: ld returned 1 exit status

另外,当我尝试编译它时,编译器f77 -o MatSim MatSim.cpp 提示:

Also, when I try to compile it, the compiler f77 -o MatSim MatSim.cpp prompted:

/tmp/cc6ewlkf.o: In function `__static_initialization_and_destruction_0(int, int)':
MatSim.cpp:(.text+0x17ad4a): undefined reference to `std::ios_base::Init::Init()'
MatSim.cpp:(.text+0x17ad4f): undefined reference to `std::ios_base::Init::~Init()'
collect2: ld returned 1 exit status

解决方案

主要问题是库问题,编译代码使用:

The main problem was a library problem, Compile your code using:

 g++ -g -o MatSim MatSim.cpp -lstdc

还是不行?安装库:

sudo apt-get install g++-multilib

推荐答案

您可以通过多种方式解决此问题:

You can resolve this in several ways:

  • 使用g++代替gcc:g++ -g -o MatSim MatSim.cpp
  • 添加-lstdc++:gcc -g -o MatSim MatSim.cpp -lstdc++
  • 替换

这是链接器问题,而不是编译器问题.问题 iostream 链接器错误 中涵盖了相同的问题 –它解释了正在发生的事情.

This is a linker problem, not a compiler issue. The same problem is covered in the question iostream linker error – it explains what is going on.

这篇关于对 `std::ios_base::Init::Init()' 的未定义引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆