iostream - linker error (using g++)
Question
I need help!
I am getting following linker errors using g++:
`__static_initialization_and_destruction_0(int, int)':
undefined reference to `std::ios_base::Init::Init()'
undefined reference to `std::ios_base::Init::~Init()'
I need to call c++ function from FORTRAN program. Simple example: C++ function (func_c.cpp) is
#include <iostream>
extern "C"
{
void cppfunction_(void);
}
void cppfunction_(void)
{
}
FORTRAN function (programm.f90) is
PROGRAM fprogram
call cppfunction()
END PROGRAM fprogram
To compile I used
gfortran –c -c programm.f90 -o programm.o
g++ -c func_c.cpp -o func_c.o
gfortran programm.o func_c.o -o main
I'm using Ubuntu (Linux ubuntu 3.0.0-13-generic x86_64 x86_64 x86_64 GNU/Linux) and gnu - 4.6.1
Solution
You probably need to link with g++
or to explicitly add the -lstdc++
at the end of your linking command.
So either
gfortran programm.o func_c.o -o main -lstdc++
or
g++ programm.o func_c.o -o main -lgfortran -lstdc++
BTW, you should use a makefile
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow