- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
hi,
--------------------------------
Tool being used:
- Intel Fortran compiler 7.1
- Intel c++ compiler
- MS VS .NET 2002 (Academic version)
----------------------------------
I have a mixed programming application (C++ and Fortran), I want to access varibales defined in the common block
of Fortran, in C++ and vice versa.
I tried the example given in this forum http://intel.forums.liveworld.com/thread.jsp?forum=144&thread=2901&message=6579&q=Calling+common+blcok+in+C#6579, but I am getting the link time errors, Which says
- test1.obj: error LNK 2019: the external refernced symbol _TESTCOMMON referenced in function main is not found.
- Testcommon.obj: error LNK 2019 Unresolved external symbol _PI, in refernced function _TESTCOMMON@4"
The Fortran codes are in a DLL, whereas the CPP project is a console type.
The codes are following:
Fortran (test1.f90)
-------------------
PROGRAM test1
IMPLICIT NONE
INTEGER*4 I
INTEGER*4 J
REAL*8 PI
COMMON/ PI /PI
INTERFACE
INTEGER*4 FUNCTION TESTCOMMON(N)
!DEC$ ATTRIBUTES DLLEXPORT :: TESTCOMMON
INTEGER*4 N
END FUNCTION TESTCOMMON
END INTERFACE
PI = DATAN(1.0D0)*4.0D0
WRITE(*,*)' PI IN FORTRAN = ',PI
J = 5
I = TESTCOMMON(J)
WRITE(*,*)' I = ',I
END
---------------
C++
---------------
Testcommon.cpp
#include
#include
#include
#include "Testcommon.h"
/** "cdecl" calling conventions are selected (by default), within the MS IDE, the function call is appended with a underscore (_), as described in the IF compilers guide's documentation under the "common block"
**/
extern "C" { int _declspec(dllimport) TESTCOMMON_(int*);}
int TESTCOMMON_(int *n) {
int result_count = 1;
cout << endl;
cout << " n =" << *n << endl;
cout << " PI = " << PI << endl;
return(result_count);
}
-------
Testcommon.h
-----
#ifndef TESTCOMMON_H
#define TESTCOMMON_H
extern "C" double PI;
#endif
Could any body help me, what am I doing wrong?
regards,
Ayaz
--------------------------------
Tool being used:
- Intel Fortran compiler 7.1
- Intel c++ compiler
- MS VS .NET 2002 (Academic version)
----------------------------------
I have a mixed programming application (C++ and Fortran), I want to access varibales defined in the common block
of Fortran, in C++ and vice versa.
I tried the example given in this forum http://intel.forums.liveworld.com/thread.jsp?forum=144&thread=2901&message=6579&q=Calling+common+blcok+in+C#6579, but I am getting the link time errors, Which says
- test1.obj: error LNK 2019: the external refernced symbol _TESTCOMMON referenced in function main is not found.
- Testcommon.obj: error LNK 2019 Unresolved external symbol _PI, in refernced function _TESTCOMMON@4"
The Fortran codes are in a DLL, whereas the CPP project is a console type.
The codes are following:
Fortran (test1.f90)
-------------------
PROGRAM test1
IMPLICIT NONE
INTEGER*4 I
INTEGER*4 J
REAL*8 PI
COMMON/ PI /PI
INTERFACE
INTEGER*4 FUNCTION TESTCOMMON(N)
!DEC$ ATTRIBUTES DLLEXPORT :: TESTCOMMON
INTEGER*4 N
END FUNCTION TESTCOMMON
END INTERFACE
PI = DATAN(1.0D0)*4.0D0
WRITE(*,*)' PI IN FORTRAN = ',PI
J = 5
I = TESTCOMMON(J)
WRITE(*,*)' I = ',I
END
---------------
C++
---------------
Testcommon.cpp
#include
#include
#include
#include "Testcommon.h"
/** "cdecl" calling conventions are selected (by default), within the MS IDE, the function call is appended with a underscore (_), as described in the IF compilers guide's documentation under the "common block"
**/
extern "C" { int _declspec(dllimport) TESTCOMMON_(int*);}
int TESTCOMMON_(int *n) {
int result_count = 1;
cout << endl;
cout << " n =" << *n << endl;
cout << " PI = " << PI << endl;
return(result_count);
}
-------
Testcommon.h
-----
#ifndef TESTCOMMON_H
#define TESTCOMMON_H
extern "C" double PI;
#endif
Could any body help me, what am I doing wrong?
regards,
Ayaz
Link Copied
0 Replies
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page