Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

C and CVF compatibility

gcunha
Beginner
1,015 Views
Hi
My name is Guilherme and I am a Telecommunications Engineer in Brazil. I am working on a CVF project which has to be updated with some C functions. The problem is that Ive already read the CVF Help sometimes but it is still returning link erros. Believe it or not, Ive tried the exact example described in the CVF Help and it is still not working.Can anybodygive me a hint???
Thank you,
Guilherme Cunha
0 Kudos
7 Replies
Jugoslav_Dujic
Valued Contributor II
1,015 Views

Certainly, but it would help if you say which example,exact text oflink error, and few lines of code (Fortran INTERFACE, C prototype, calling code) wouldn't hurt as well.

Jugoslav

0 Kudos
gcunha
Beginner
1,015 Views
Sure...The following code (extracted from the CVF Help) and the error messages are displayed below:
C file
---------------------------------
#include
double pythag( double *a, double *b)
{
double c;
c = sqrt( *a * *a + *b * *b );
return c;
}
Fortran File
--------------------------------------
PROGRAM FORMAIN
INTERFACE
SUBROUTINE pythag(a,b)
!DEC$ ATTRIBUTES C, ALIAS:'_pythag' :: pythag
REAL*4 a
REAL*4 b
END SUBROUTINE pythag
END INTERFACE
CALL pythag (3,4)
END
Error Messages
-------------------------------------
Compiling...
pythag.c
Linking...
LINK : warning LNK4075: ignoring /EDITANDCONTINUE due to /INCREMENTAL:NO specification
formain.obj : error LNK2001: unresolved external symbol _for_check_flawed_pentium@0
formain.obj : error LNK2001: unresolved external symbol _for_set_reentrancy@4
pythag.obj : error LNK2001: unresolved external symbol _sqrt
pythag.obj : error LNK2001: unresolved external symbol __fltused
pythag.obj : error LNK2001: unresolved external symbol __chkesp
LINK : error LNK2001: unresolved external symbol _mainCRTStartup
Debug/fortranc.exe : fatal error LNK1120: 6 unresolved externals
Error executing link.exe.
I hope this can help you...
Guilherme Cunha
0 Kudos
Jugoslav_Dujic
Valued Contributor II
1,015 Views
OK. The C and Fortran codes are all OK, but your project settings aren't -- the linker doesn't seem to find any default Fortran and C library. Do youby any chance you have Project/Settings/Link/Ignore all default libraries checked? Note also that you have to have the same setting for Project/Settings/Fortran/Libraries/Use run-time library and .../C/C++/Use run-time library (typically "Single threaded" or "Debug Single-threaded").
Another cause might be a bad installation -- do you see ...DF98Lib and ...VC98Lib as first entries of Tools/Options/Directories/Library files?
If you still can't solve it, please attach your .dsp file so that someone can look at it.
Jugoslav
0 Kudos
gcunha
Beginner
1,015 Views
Well, everything you said in the last reply was OK... So, Im attaching the project file so that you can take a better look at it.
Thank you,
Guilherme
0 Kudos
Jugoslav_Dujic
Valued Contributor II
1,015 Views
The initial problem was that you had extra libraries listed in Project/Settings/Link, namely msvcrt.lib (VC++ static non-debug single-threaded run time), while compiler settings said (static debug single threaded) (by the way, in Release configuration it's OK).
I don't know how it occurred, but I guess you selected "Win32 console application" in Project Wizard, which generates a console app based on C++ entry point (main); there's, however, "Fortran console application", which assumes Fortran entry point (PROGRAM). I'm not sure about it, though.
I admit I looked at the code superficially first time, but it's also all screwed up; C arguments are pointers to double's (REAL*4), while Fortran interface specifies non-pointers to float's (REAL*8). I fixed it onboth sides (attached). Alternatively, you could leave C++ code untouched, but the correct call is:
INTERFACE
REAL*8 FUNCTION pythag(a,b)
!DEC$ ATTRIBUTES C, ALIAS:'_pythag' :: pythag
REAL*8 a
REAL*8 b
END FUNCTION pythag
END INTERFACE
0 Kudos
Jugoslav_Dujic
Valued Contributor II
1,015 Views
The initial problem was that you had extra libraries listed in Project/Settings/Link, namely msvcrt.lib (VC++ static non-debug single-threaded run time), while compiler settings said (static debug single threaded) (by the way, in Release configuration it's OK).
I don't know how it occurred, but I guess you selected "Win32 console application" in Project Wizard, which generates a console app based on C++ entry point (main); there's, however, "Fortran console application", which assumes Fortran entry point (PROGRAM). I'm not sure about it, though.
I admit I looked at the code superficially first time, but it's also all screwed up; C arguments are pointers to double's (REAL*4), while Fortran interface specifies non-pointers to float's (REAL*8). I fixed it onboth sides (attached). Alternatively, you could leave C++ code untouched, but the correct call is:
INTERFACE
REAL*8 FUNCTION pythag(a,b)
!DEC$ ATTRIBUTES C, ALIAS:'_pythag' :: pythag
REAL*8 a
REAL*8 b
END FUNCTION pythag
END INTERFACE
0 Kudos
Jugoslav_Dujic
Valued Contributor II
1,015 Views
The initial problem was that you had extra libraries listed in Project/Settings/Link, namely msvcrt.lib (VC++ static non-debug single-threaded run time), while compiler settings said (static debug single threaded) (by the way, in Release configuration it's OK).
I don't know how it occurred, but I guess you selected "Win32 console application" in Project Wizard, which generates a console app based on C++ entry point (main); there's, however, "Fortran console application", which assumes Fortran entry point (PROGRAM). I'm not sure about it, though.
I admit I looked at the code superficially first time, but it's also all screwed up; C arguments are pointers to double's (REAL*4), while Fortran interface specifies non-pointers to float's (REAL*8). I fixed it onboth sides (attached). Alternatively, you could leave C++ code untouched, but the correct call is then:
INTERFACE
REAL*8 FUNCTION pythag(a,b)
!DEC$ ATTRIBUTES C, ALIAS:'_pythag' :: pythag
!DEC$ ATTRIBUTES REFERENCE: a, b
REAL*8 a
REAL*8 b
END FUNCTION pythag
END INTERFACE
Could you please refer to help page you picked it up from?
Jugoslav
0 Kudos
Reply