- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi , I am been trying to compile a code in intel fortran compiler which call a C function. Both these are integrated in Microsoft Visual Studio.net 2003. the C compiler is defuat visual C++ compiler.
My code is given below
PROGRAM f_calls_c
IMPLICIT NONE
REAL R
REAL :: p1_x, p1_y, p2_x, p2_y
EXTERNAL CALC_DIST
p1_x = 0.0
p1_y = 0.0
p2_x = 3.0
p2_y = 4.0
CALL CALC_DIST(p1_x,p1_y,p2_x,p2_y)
READ(*,*)R
WRITE(*,*)R
END PROGRAM f_calls_c
#include
#include
#include
extern "C" void calc_dist_(float *x1, float *y1, float *x2, float *y2)
{
float dxsq, dysq, distance, read;
dxsq = (*x2-*x1)*(*x2-*x1);
dysq = (*y2-*y1)*(*y2-*y1);
distance = sqrt( dxsq + dysq );
printf("The distance between the points is %13.5e ",
distance);
}
The error i get is
callC.obj : error LNK2019: unresolved external symbol _CALC_DIST referenced in function _MAIN__
Debug/callC.exe : fatal error LNK1120: 1 unresolved externals
PLEASE suggest some solution..I have to get started with my project.Not able to figure out from the forum previous messages!!!!
My code is given below
PROGRAM f_calls_c
IMPLICIT NONE
REAL R
REAL :: p1_x, p1_y, p2_x, p2_y
EXTERNAL CALC_DIST
p1_x = 0.0
p1_y = 0.0
p2_x = 3.0
p2_y = 4.0
CALL CALC_DIST(p1_x,p1_y,p2_x,p2_y)
READ(*,*)R
WRITE(*,*)R
END PROGRAM f_calls_c
#include
#include
#include
extern "C" void calc_dist_(float *x1, float *y1, float *x2, float *y2)
{
float dxsq, dysq, distance, read;
dxsq = (*x2-*x1)*(*x2-*x1);
dysq = (*y2-*y1)*(*y2-*y1);
distance = sqrt( dxsq + dysq );
printf("The distance between the points is %13.5e ",
distance);
}
The error i get is
callC.obj : error LNK2019: unresolved external symbol _CALC_DIST referenced in function _MAIN__
Debug/callC.exe : fatal error LNK1120: 1 unresolved externals
PLEASE suggest some solution..I have to get started with my project.Not able to figure out from the forum previous messages!!!!
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Solution 1: Rename the C function to be CALC_DIST.
Solution 2: Add to the Fortran code:
!DEC$ ATTRIBUTES ALIAS:"_calc_dist" :: CALC_DIST
You can (and should) remove the EXTERNAL statement, since CALC_DIST is not a function.
Solution 2: Add to the Fortran code:
!DEC$ ATTRIBUTES ALIAS:"_calc_dist" :: CALC_DIST
You can (and should) remove the EXTERNAL statement, since CALC_DIST is not a function.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
sblionel wrote:
Solution 1: Rename the C function to be CALC_DIST.
Solution 2: Add to the Fortran code:
!DEC$ ATTRIBUTES ALIAS:"_calc_dist" :: CALC_DIST
You can (and should) remove the EXTERNAL statement, since CALC_DIST is not a function.
Hi,
I tried using both solution but still I get the same error..I think I need to change some settings in Microsoft Visual Studio .net Could you suggest some solutions .which is the best way.
I have intel fortran compiler 9 which is installed in Microsoft Visual studio net 2003. I tired using the command
CL -c filename.C
ifort filename.obj fortran_filename.f90
Still the same error!!!
Thanks a ton in advance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks a ton Sblionel for the solution..The program runs through command promt...Now I can proceed further to pass various arguments..
Finally I can kick start on my project...
rampy
" If you have Dreams, Don't Sleep!!!.."
Finally I can kick start on my project...
rampy
" If you have Dreams, Don't Sleep!!!.."
Message Edited by rampy on 10-16-2005 07:02 AM
Message Edited by rampy on 10-16-2005 07:02 AM
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