[英]undefined reference to `std::ios_base::Init::Init()'
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我写这段代码来读取 3 个文件,TM 是方阵的大小,LER 是数组的行数,从最后一个值定义一个非方阵 (ler/2)*2
Then... the code read a file with some relations, all are numbers and are assign to C[ler].然后...代码读取一个有一些关系的文件,都是数字并分配给C[ler]。
Then ... C[ler] is assigned to B[ler/2][2].然后... C[ler] 被分配给 B[ler/2][2]。
Those coordinates, per row, in B[ler/2][2] are assign to a and b. B[ler/2][2] 中每行的那些坐标分配给 a 和 b。
a and b are the row and the column of the matrix A[tm][tm] where to add 1. a 和 b 是矩阵 A[tm][tm] 中要加 1 的行和列。
My code crashes and I don't see what the error is.我的代码崩溃了,我没有看到错误是什么。
When I try to compile it, the compiler gcc -g -o MatSim MatSim.cpp prompted:当我尝试编译它时,编译器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
Also, when I try to compile it, the compiler f77 -o MatSim MatSim.cpp prompted:另外,当我尝试编译它时,编译器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
Solution解决方案
The main problem was a library problem, Compile your code using:主要问题是库问题,使用以下方法编译代码:
g++ -g -o MatSim MatSim.cpp -lstdc
Still not working?还是行不通? Install libraries:
安装库:
sudo apt-get install g++-multilib
You can resolve this in several ways:您可以通过多种方式解决此问题:
g++
in stead of gcc
: g++ -g -o MatSim MatSim.cpp
g++
代替gcc
: g++ -g -o MatSim MatSim.cpp
-lstdc++
: gcc -g -o MatSim MatSim.cpp -lstdc++
-lstdc++
: gcc -g -o MatSim MatSim.cpp -lstdc++
<string.h>
by <string>
<string.h>
替换为<string>
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.
问题iostream 链接器错误中涵盖了相同的问题 - 它解释了正在发生的事情。
Most of these linker errors occur because of missing libraries.大多数这些链接器错误是由于缺少库而发生的。
I added the libstdc++.6.dylib in my Project->Targets->Build Phases-> Link Binary With Libraries.我在 Project->Targets->Build Phases->Link Binary With Libraries 中添加了libstdc++.6.dylib 。
That solved it for me on Xcode 6.3.2 for iOS 8.3这在 Xcode 6.3.2 for iOS 8.3 上为我解决了
Cheers!干杯!
g++ is equivalent to gcc -xc++ -lstdc++ -shared-libgcc g++ 等价于 gcc -xc++ -lstdc++ -shared-libgcc
I was getting a similar error while using sizeof() method.我在使用 sizeof() 方法时遇到了类似的错误。 By using g++ or above tags with gcc, the code got compiled.
通过在 gcc 中使用 g++ 或以上标签,代码被编译。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.