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

fortran main calls c function

fkaisermnb
Beginner
514 Views
I have a similar problem as Camille (Compilers: Compaq Visual Fortran6.6.0, Microsoft Visual C++6.0).
Fortran:
0 Kudos
5 Replies
fkaisermnb
Beginner
514 Views

Fortran: external input

ns=input(t,s,j,sp,spr)

C: int input_(double t[], doubles[],.....)

I get the following link error:

main.obj: error LNK 2001: unresolved external symbol _INPUT@20

I know that this program runs on another machine, therefore I guess the code should be ok (maybe it's just a problem with wrong settings in teh compaq-compiler).

Nevertheless I added some new code to the main (which I found on the compaq and microsoft FAQ-pages). Unfortunately both versions didn't work.

I also added the code suggested by Jugoslav for Camille's problem, it didn't work either:

INTERFACE
integer function input(a,b,c,d,e)
!DEC$ATTRIBUTES STDCALL,DECORATE,ALIAS:"input"::input => turned green
!DEC$ATTRIBUTES REFERENCE:input=>turned green

double precisiona
double precision b
double precision c
double precision d
double precision e
END function
end interface

c:

int __stdcall input_(double t[],double s[],double j[],
double sp[],double spr[]).....

Info: Syntax error, found IDENTIFIER 'INPUT' when expecting one of:
!DEC$ATTRIBUTES REFERENCE:input
and still the same lnk error.
Does anyone know how to resolve this problem?
Thank's in advance
Christian
0 Kudos
camille_dannunzio
514 Views

try

!DEC$ATTRIBUTES REFERENCE::

needs double quote (see reply to my replay)

Camille

0 Kudos
fkaisermnb
Beginner
514 Views

thank's, I tried the double quote (no syntax error),but the LNK2001 erroris stillremaining.

Christian

0 Kudos
Jugoslav_Dujic
Valued Contributor II
514 Views

Few side notes: REFERENCE matters for character strings and for scalar variables of any kind. Arrays are always passed by reference in both C and Fortran so REFERENCE in this particular case is unnecessary (but doesn't do harm either).

!DEC$ syntax is Compaq's extension for stating attributes and other metacommands, mostly related with mixed-language programming. Although it appears as a comment, it isn't quite so. Note that they're analysed by syntax (as you can see by the error) but errors within them are flagged as "Info", i.e. "not really fatal, but you should fix it".

CVF is somewhat peculiarcompared to other compilers (especially UNIX ones) in the sense of compiler defaults.For most other compilers, default calling convention,hidden CHARACTER(*)length parameter etc. are equivalent to default settings of a typical C compiler (as C is Unix's "native language"). That means:

- __cdecl calling convention (CVF has __stdcall)
- hidden string length passedat the end of argument-list (CVF has "immediately after string argument")

That can be changed by /iface:cref and /assume:nomixed_str_len_arg respectively, so if you compile Fortran with that, you could manage without INTERFACE and !DEC$, provided that C arguments are by-reference (by-pointer). Also, note that in Intel Visual Fortran, these settings are default (__cdecl+nomixed_str_len_arg).

Jugoslav

0 Kudos
Jugoslav_Dujic
Valued Contributor II
514 Views

Christian, I suspect you're getting "unresolved external _input@20" -- but you have an extra trailing underscore in C code, i.e. it is exported as _input_@20. Get rid of it (I bet it was a workaround for a quirk another compiler).

Jugoslav

0 Kudos
Reply