Undefined reference to `std :: ios_base :: Init :: Init () '

I am writing this code to read 3 files, TM - the size of the square matrix, LER - the number of rows in the array, and from the last value - the non-square matrix (ler / 2) * 2

Then ... the code reads the file with some relationships, all are numbers and are assigned to C [ler].

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

These coordinates for each line in B [ler / 2] [2] are assigned a and b.

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

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

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

/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 f77 -o MatSim compiler MatSim.cpp compiler requested:

 /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 

Decision

The main problem was the problem with the library. Compile your code using:

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

Still not working? Libraries Installation:

 sudo apt-get install g++-multilib 
+45
c matrix coredump
Jun 05 '12 at 23:15
source share
2 answers

You can solve this problem in several ways:

  • Use g++ instead of gcc : g++ -g -o MatSim MatSim.cpp
  • Add -lstdc++ : gcc -g -o MatSim MatSim.cpp -lstdc++
  • Replace <string.h> with <string>

This is a linker problem, not a compiler problem. The same issue is addressed in the iostream linker error issue - it explains what happens.

+84
Jun 06 2018-12-06T00:
source share

Most of these linker errors are due to missing libraries.

I added libstdC ++. 6.dylib to your Project-> Targetets-> Build Phases-> Link Binary with libraries.

This solved it for me on Xcode 6.3.2 for iOS 8.3

Hurrah!

+6
Jun 30 '15 at 14:57
source share



All Articles