Dear Mojtaba, Please note that this list is devoted to the development of gfortran; go to the likes of comp.lang.fortran for help with the language itself. Better still read the book or google "C fortran interoperability". That said, this works: (Note well the arguments in the prototype for 'multab' and the provision of a C binding name in the fortran. Also, uppercase is traditional for fortran but is by no means obligatory - ) it is simply ignored.) #include <iostream> using namespace std; extern "C" int multab(int *a, int *b); int main() { int a=3, b=8; while (a > 0 && b > 0) { cout << "please input a and b" << endl; cin >> a >> b; cout << "a * b = " << multab(&a, &b) << endl; } return 0; } function multab(a, b) bind(c, name = "multab") use iso_c_binding implicit none integer(c_int), intent(in), bind(c) :: a, b integer(c_int) :: multab multab = a * b end function multab pault@paul-laptop:/tmp# g++ main.cpp FSub.f90 pault@paul-laptop:/tmp# ./a.out please input a and b 2 2 a * b = 4 please input a and b Good luck Paul On Wed, Jan 11, 2012 at 8:33 AM, Mojtaba Seifi <mojtaba.seifi@xxxxxxxxx> wrote: > Dear Sir/Madam, > > I'm trying to compile a simple fortran code using gfortran and then using > this library in a C++ code (compiling by g++). The simple codes for fortran > and C++ are attached. I use the following commands in terminal (ubuntu) for > this purpose: > > gfortran -c FSub.f90 > ar -rcs libFsub.a FSub.o > g++ -c main.cpp > g++ -o main.exe main.o -L/`pwd` -lFsub > > > But I get the following error: > -------------- > main.o: In function `main': > main.cpp:(.text+0x41): undefined reference to `MULTAB_' > collect2: ld returned 1 exit status > -------------- > I couldn't find any solution on the Internet for this issue. > Would you please help me on this. I'm new in linux and have no idea how to > fix this. > > Thank you. > > -- > Mojtaba > -- The knack of flying is learning how to throw yourself at the ground and miss. --Hitchhikers Guide to the Galaxy