PDA

View Full Version : Re: [LF] linking FORTRAN object to MS DevStudio C++ code


Lahey Support
08-15-2003, 01:33 AM
Bill,

The subroutine in this example should appear in an ML_EXTERNAL
statement. The ML_EXTERNAL and DLL_EXPORT statements make routine names
eligible for "decoration" using the "-ml xxxx" compiler switch. If the
routine name does not appear in one of these statements, the "-ml msvc"
switch at compile time will have no effect. If your subroutine does not
use any intrinsic fortran routines, this is probably all that is needed.
If the subroutine does use intrinsics, you will also need to link the
appropriate runtime library.

Regards, Tim Zeisloft

Bill Tangren wrote:

> I would like to know how one would go about, if it is possible, linking a
> FORTRAN subroutine into a Microsoft Developer Studio (C++) project.
>
>>From the manual, I was able to glean that I should compile the FORTRAN
> like so:
>
> lf95 -c -staticlink -ml msvc foo.for
>
> If I do this (and if foo.for contains SUBROUTINE FOOBAR), I get a link
> error in Developer Studio:
>
>
> Linking...
> testView.obj : error LNK2001: unresolved external symbol "void __cdecl
> FOOBAR(int)" [address removed]
> Release/test.exe : fatal error LNK1120: 1 unresolved externals
> Error executing link.exe.
>
>
> LNK2001 is long and involved. Suffice it to say that there are many
> possibilities why I am getting this error. I have tried using an 'extern'
> statement, and various calling conventions (__stdcall and __cdecl) for
> both the 'extern void FOOBAR' and the MSDev C++ project files. Nothing
> works.
>
> Could the problem be that the foo.obj file is 16 bit (by default) and the
> MSDev project is 32 bit? This is a possibility that LNK2001 mentions. I
> have tried creating .dll's and .lib's, but I still get the same problem.
>
> Bill Tangren
>
> ----------------------------------------------------------
> To unsubscribe, send to [address removed] the following
> as the first and only line of the message body:
> unsubscribe fortran
> ----------------------------------------------------------
>
> .
>
>



--
Timothy Zeisloft
Lahey Computer Systems, Inc
email: [address removed]
internet: http://www.lahey.com

----------------------------------------------------------
To unsubscribe, send to [address removed] the following
as the first and only line of the message body:
unsubscribe fortran
----------------------------------------------------------