我写这段代码来读取 3 个文件,TM 是方阵的大小,LER 是数组的行数,从最后一个值定义一个非方阵 (ler/2)*2
然后...代码读取了一个有关系的文件,都是数字,赋值给C[ler]。
然后……C[ler]赋值给B[ler/2][2]。
B[ler/2][2] 中每行的那些坐标被分配给 a 和 b。
a和b是矩阵A[tm][tm]中加1的行和列。
我的代码崩溃了,我看不出错误是什么。
当我尝试编译它时,编译器gcc -g -o MatSim MatSim.cpp提示:
/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提示:
/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
解决方案
主要问题是库问题,使用以下代码编译代码:
g++ -g -o MatSim MatSim.cpp -lstdc
还是不行?安装库:
sudo apt-get install g++-multilib
最佳答案
您可以通过多种方式解决此问题:
- 使用
g++
代替gcc
:g++ -g -o MatSim MatSim.cpp
- 添加
-lstdc++
:gcc -g -o MatSim MatSim.cpp -lstdc++
- 替换
<string.h>
通过<string>
这是链接器问题,而不是编译器问题。问题 iostream linker error 中涵盖了同样的问题。 – 它解释了正在发生的事情。
关于c - 对 `std::ios_base::Init::Init()' 的 undefined reference ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10906275/