Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / July 2005

Tip: Looking for answers? Try searching our database.

c calling a fortran subroutine

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
RichN - 30 Jun 2005 20:01 GMT
I am developing a c program in Visual Studio .NET 2003. I also have an
Intel(R) Fortran compiler for MVS .NET

My fortran sourcecode already existed. I started a  new fortran project and
chose to create a dynamic link library. The beginning of the fortran code
looks like:

SUBROUTINE SFTCK3
!DEC$ ATTRIBUTES DLLEXPORT::SFTCK3

It compiled ok, and created both a SFTCK3.lib and SFTCK3.dll

In the C code, I've tried a variety of online suggestions, but for now it
looks like:
(from top)

#include <stdio.h>
#include <process.h>
#include <iostream.h>
#include "SelectOp.h"
#include "SelectOpGui.h"

extern void _stdcall SFTCK3 (void);

later on, in the code, i call:

case 8:

    SFTCK3();
    break;

I get the following error when trying to build:

error LNK2019: unresolved external symbol _SFTCK3@0 referenced in function
_SelectOp_OnOperation, which would be the call made above.

In the c codes' property settings, i do have, under additional dependencies:

c:\Temp\FAST_CSCI\SFTCK3\SFTCK3.lib

I'm pretty sure it's because I'm not linking the c and fortran together, but
not sure how to get  this working. Any help would be appreciated. Thanks
Carl Daniel [VC++ MVP] - 30 Jun 2005 21:25 GMT
> I am developing a c program in Visual Studio .NET 2003. I also have an
> Intel(R) Fortran compiler for MVS .NET
[quoted text clipped - 40 lines]
> together, but not sure how to get  this working. Any help would be
> appreciated. Thanks

Use dumpbin /symbols on your STFCK3.lib import library to see what the
exported symbol name is.  That'll give a clue to the solution (which
probably involves changing the name you use in the C code, or in the Fortran
code, or changing calling convention, or some such).

-cd
RichN - 01 Jul 2005 18:03 GMT
Thanks for reply Carl. I was never able to get dumpbin.exe to work on my PC,
so had colleague run it on his. After running dumpbin on my SFTCK3.lib, I got
the following:

File Type: LIBRARY

COFF SYMBOL TABLE
000   005D0C05   ABS      notype   Static       | @COMP.ID
001   00000000   SECT2   notype   External   | __IMPORT_DESCRIPTOR_SFTCK3
002   C0000040   SECT2   notype   Section    | .idata$2
003   00000000   SECT3   notype   Static       | .idata$6
004   C0000040   UNDEF   notype   Section    | .idata$4
005   C0000040   UNDEF   notype   Section    | .idata$5
006   00000000   UNDEF   notype   External   | __NULL_IMPORT_DESCRIPTOR
007   00000000   UNDEF   notype   External   | |SFTCK3_NULL_THUNK_DATA

String Table Size = 0x50 bytes

COFF SYMBOL TABLE
000   005D0C05   ABS      notype   Static      | @comp.id
001   00000000   SECT2   notype   External  | __NULL_IMPORT_DESCRIPTOR
     
String Table Size = 0x1D bytes

COFF SYMBOL TABLE
000   005D0C05   ABS      notype   Static      | @comp.id
001   00000000   SECT2   notype   External  | |SFTCK3_NULL_THUNK_DATA

String Table Size = 0x1C bytes

Summary

           C3 .debug$S
           14 .idata$2
           14 .idata$3
             4 .idata$4
             4 .idata$5
             C .idata$6

I checked out many online sites to try and understand what this is all
telling me. I generally have an idea now about the fields, but can't
translate that into how it effects my particular problem. Can you help on
that? Also, would have running dumpbin /EXPORTS helped me to know what
subroutine name the dll is showing?
Thanks again for your earlier reply.

> > I am developing a c program in Visual Studio .NET 2003. I also have an
> > Intel(R) Fortran compiler for MVS .NET
[quoted text clipped - 47 lines]
>
> -cd
Carl Daniel [VC++ MVP] - 01 Jul 2005 18:35 GMT
> Thanks for reply Carl. I was never able to get dumpbin.exe to work on
> my PC, so had colleague run it on his. After running dumpbin on my
[quoted text clipped - 42 lines]
> know what subroutine name the dll is showing?
> Thanks again for your earlier reply.

Odd - it doesn't look like your function was exported from the DLL.

Yes, try running dumpbin /exports against the DLL to see what it shows.

-cd
RichN - 01 Jul 2005 22:04 GMT
hi Carl,

I am able, now, to run dumpbin at my PC. In any case, I ran /EXPORTS, and
got the following:

Dump of file sftck3.lib
File Type: LIBRARY
     Exports
        ordinal          name
                           _SFTCK3

  Summary
                 C3 .debug$S
                 14 .idata$2
                 14 .idata$3
                  4 .idata$4
                  4 .idata$5
                  C .idata$6

I checked this against a known working DLL I previously created in C, and
the output
is similar. So now I'm thinking that the subroutine name is there, but that
the original error "unresolved external symbol _SFTCK3@0" is indicating the
function name is undefined to the function that is calling it. Normally, in
C, I would have some kind of #include "xxxxxxxx" to define SFTCK3. Do I need
some type of .h to go with my fortran dll?


> > Thanks for reply Carl. I was never able to get dumpbin.exe to work on
> > my PC, so had colleague run it on his. After running dumpbin on my
[quoted text clipped - 48 lines]
>
> -cd
Carl Daniel [VC++ MVP] - 01 Jul 2005 22:17 GMT
> hi Carl,
>
[quoted text clipped - 23 lines]
> "xxxxxxxx" to define SFTCK3. Do I need some type of .h to go with my
> fortran dll?

OK, so your C code is expecting a function with the normal __stdcall name
decorations (_name@paramSize), while your Fortran DLL exported only a simple
name.

Are you sure that the Fortran code is __stdcall?  It's named as if it's
__cdecl.  Try changing your extern declaration in the C module to use
__cdecl.  That'll probably make it link - if the Fortran function doesn't
actually __cdecl, then the mismatch will likely cause the program to crash
shortly after returning from the Fortran sub.

-cd
RichN - 06 Jul 2005 22:09 GMT
Hi Carl,

Just wanted to get back to you. cdecl worked ! I was able to compile and
link, and the program seems to be running ok. Thanks for advice !

Rich

> > hi Carl,
> >
[quoted text clipped - 35 lines]
>
> -cd

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.