- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I am a FORTRAN user who has a need to make calls and extract data from a C routine. I am not familiar with C (the C routine I need to make calls to is a "C" routine, not C++), nor am I very familiar with mixed language programming in general. The biggest stumbling block I have is trying to get the two codes to "see" and "like" each other if you will.
Here is what I'm using:
Intel Fortran Compiler Integration for Microsoft Visual Studio 2005, Version 9.1.3192.2005
Microsoft Visual Studio 2005 Standard Edition - ENU Service Pack 1 (KB926601)
I'm using the Visual Studio IDE
(I have some experience calling FORTRAN DLLs from Exel VBA and passing arrays and strings back and forth from Excel and the FORTRAN DLL, sacrificing some brain cells in the process. And I am aware that there are differences in how C and FORTRAN handle arrays and data and such; when I get that far..but for now I just need to figure out how to get the two to see each other. I've googled and googled and I get a lot of bits and pieces but can't quite put it together).
I'm not sure if this is the right place to ask this since I think the problem may lie on the C side but this is where I'm going to start.
I'm going to start out with baby steps first. Below is a C program I got from "C Primer Plus" by Stephen Prata. I am able to build and run it from it's own Project as a WIN32 Console Application.
[cpp][/cpp]
[cpp]#includeint testCdll(void) /* a simple program */ { int num; /* define a variable called num */ num = 1; /* assign a value to num */ printf("I am a simple "); /* use the printf() function */ printf("computer.n"); printf("My favorite number is %d because it is first.n",num); return 0; }[/cpp]
I then created another Project where I created a DLL version of the C code above.
I simply want to call this from a simple FORTRAN rountine such as
program Forcall
implicit none
call testCdll
end program Forcall
I created this program in its own Project.
1) What do I need to do to the C code to make it visible to the FORTRAN? I've played a little with an "extern" command but don't know exactly how to implement it.
2) What settings do I need to set in the IDE of the FORTRAN Project to so that the FORTRAN code knows where to look? So far under Project Properties\Link\General I've put the path of the C DLL in "Additional library directories". This doesn't quite sound right but I can't find anything for "DLL" directories.
I've also put the name of the C dll in the "Additional Dependencies" box in the INPUT dialog box under "Linker".
Note: I did manage to somehow build the C DLL using the extern command/directive or whatever without any complaints and when I tried to build the FORTRAN code I got a "cannot open DLL" (with the name I gave the DLL) message. So I think I was able to get the FORTRAN to "see" the dll but it could not open it. Unfortunately in copying and pasting for this e-mail I lost that "extern" addition to the code that I made.
Mike
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The compiler ships with sample C / FORTRAN mixed projects, exploring those has been a big help for me.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I then added a couple of #define...declspec... lines and a DLLExport line and got the Fortran code to compile, linking to the C code without any errors. Maybe it's not quite right yet, but it's progress.
Mike

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page