public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* need help on gfortran and C++
@ 2012-01-11  8:40 Mojtaba Seifi
  2012-01-11  8:57 ` Tobias Burnus
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Mojtaba Seifi @ 2012-01-11  8:40 UTC (permalink / raw)
  To: fortran, gcc-help

[-- Attachment #1: Type: text/plain, Size: 718 bytes --]

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


[-- Attachment #2: FSub.f90 --]
[-- Type: text/x-fortran, Size: 123 bytes --]



INTEGER FUNCTION MULTAB(A, B)
    IMPLICIT NONE

    INTEGER, INTENT(IN) :: A,B

    MULTAB = A*B

END FUNCTION MULTAB



[-- Attachment #3: main.cpp --]
[-- Type: text/x-c++src, Size: 541 bytes --]

//============================================================================
// 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;
}

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-01-11  9:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-11  8:40 need help on gfortran and C++ Mojtaba Seifi
2012-01-11  8:57 ` Tobias Burnus
2012-01-11 12:53   ` N.M. Maclaren
2012-01-11  9:37 ` Paul Richard Thomas
2012-01-11 12:20 ` Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).