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
INTEGER FUNCTION MULTAB(A, B)
IMPLICIT NONE
INTEGER, INTENT(IN) :: A,B
MULTAB = A*B
END FUNCTION MULTAB
//============================================================================
// Name : CPP_Calls_GF.cpp
// Author :
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
using namespace std;
extern "C" int MULTAB_(int &a, int &b);
int main() {
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
int a=3, b=8;
cout << MULTAB_(a, b) << endl;
return 0;
}