Link fortran, c++ and a library

I have a C++ module that I have build as a library (myLib.a) and use this module from another C++-program. So far, so good.

Now, I whant to use this module from a fortran code...

I tried to wirte a c++ wrapper that called the module and a fortran wrapper that called the c++ wrapper:

Cpp-wrapper (c_wrapper.cpp) is something like this:
1
2
3
4
5
6
7
8
9
#includes..

void wrapper_c_(float *ins, float *outs)
{
   int aInt;
   int bInt;

   myClass* ptr = myClass::create(...);
}



The fortran-wrapper (wrapper_f.f):
1
2
3
4
5
6
7
8
9
10
11
12
program wrapper_f
real aNumber
real bNumber
real ins(10), outs(10)

ins(1) = 1
ins(2) = 3
...

call wrapper_c(ins, outs)

return end



I build the Cpp file with
gcc -c wrapper_c.cpp

the fortran file with
gfortran -c wrapper_f.f

And I try to link all toghether with:

gfortran -o testProg wrapper_f.o wrapper_c.o -Wl myLib.a


But this just results in hundred of lines with errors. (Seems like the lib-file is not linked and found..)


I also tried to use extern C instead of Cpp, but did not get it to work this way either..

Do anyone have a clue how I can do this??
Last edited on
I now get it to compile by adding -lstdc++.. BUT now I get

main: /usr/lib64/libstdc++.s0.6: version GLIBCXX_3.4.11' not found..

I also get the same message with version 3.4.14 and 3.4.9..
I'm using Debian Linux here.

fwrapper.f:
1
2
3
4
5
6
7
8
9
10
11
12
      program wrapper_f
      real aNumber
      real bNumber
      real ins(10), outs(10)

      ins(1) = 1
      ins(2) = 3

      call wrapper_c(ins, outs)
      print *, 'Fortran wrapper'

      end program

cppwrapper:
1
2
3
4
5
6
7
#include <iostream>

extern "C"
void wrapper_c_(float *ins, float *outs)
{
	std::cout << "C++ wrapper" << std::endl;
}


compile with:
 
g++ -c cppwrapper.cpp && gfortran-4.4 -o test cppwrapper.o fwrapper.f -lc -lstdc++


output:
1
2
C++ wrapper
 Fortran wrapper
Last edited on
Topic archived. No new replies allowed.