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

Calling Fortran from C

Amir_Filipovic
Beginner
2,445 Views
Hi,

I have a C-code with calls to Fortran subroutines which doesn't work. I wonder if anybody can guess what I'm doing wrong?

The fortran code isdefined as below:

SUBROUTINE FLYCUR2(datafile,grffile)

!DEC$ ATTRIBUTES DLLEXPORT, STDCALL, REFERENCE :: FLYCUR2

!DEC$ ATTRIBUTES ALIAS: 'FLYCUR2' :: FLYCUR2

CHARACTER*(*) datafile, grffile

...

It's compiled with Intel Fortran compiler v.10 into a dll. I have tested it with a test example written in C# and it works.

The C code is defined as below:

extern int __stdcall FLYCUR2(char *,int,char *,int);

...
FLYCUR2(filename1,n1,filename2,n2);

...

Visual Studio 2008 is used to create a project with theC code. The fortran library (.lib) from the fortrancode is included in "Aditional Depencencies" with the linker.

However when I tried to build the code I get the following error:

Error50error LNK2019: unresolved external symbol __imp__FLYCUR2 referenced in function _print_pages@0GRAFDLL.objGraf_09

Any idea what I'm doing wrong?

0 Kudos
23 Replies
Jugoslav_Dujic
Valued Contributor II
410 Views
It won't work from C# anymore as now the name is wrong. If you want to use it from both C++ and C# you're going to have to use a declaration on the C++ side to set the name to something that C# can use and then go back to using ALIAS.

As far as I know, C# works in the same manner as Visual Basic -- it does not use the .lib file, but "looks" at the actual exported symbols from the dll.

You can export the same symbol from the dll under multiple aliases though. To do that, you must write a .def file. It is sufficient that you just insert it in the project and it will be automatically recognized by the linker. (I recommend that you remove the DLLEXPORT attribute from the code, because I don't know how two means interact). The contents of the file (yourlib.def) should be just:

[cpp]EXPORTS
_flycur2@16
FLYCUR2 = _flycur2@16
[/cpp]
As result, both "_flycur2@16" and "FLYCUR2" will be exported from the dll (verify it with Dependency Walker!) and refer to the same routine. The first one will be used by C++, and the second by C#.
0 Kudos
Steven_L_Intel1
Employee
410 Views
The reason I said the C# would not work is that the C# code he showed used the undecorated name. As you say, like VB, the name you give in the C# declaration is exactly what is used, with no modifications.
0 Kudos
follower545
Beginner
410 Views
Quoting - Jugoslav Dujic
Movie film phim phim online viet entertainment. Music media phim han quoc drama clips. Movie clips korean drama for entertainment. For more movies phim nguoi lon for entertainment.
As far as I know, C# works in the same manner as Visual Basic -- it does not use the .lib file, but "looks" at the actual exported symbols from the dll.TVB actors actresses for phim hong kong film model world.Fashion brand names thoi trang high quality. Top level cotton thoi trang for teen men women fashion lovers.
You can export the same symbol from the dll under multiple aliases though. To do that, you must write a .def file. It is sufficient that you just insert it in the project and it will be automatically recognized by the linker. (I recommend that you remove the DLLEXPORT attribute from the code, because I don't know how two means interact). The contents of the file (yourlib.def) should be just:clothes fashion korean wholesale fashion for model world. Asian fabrics korean wholesale fashion models garment.
[cpp]EXPORTS
_flycur2@16
FLYCUR2 = _flycur2@16
[/cpp]
As result, both "_flycur2@16" and "FLYCUR2" will be exported from the dll (verify it with Dependency Walker!) and refer to the same routine. The first one will be used by C++, and the second by C#.
nice example... a pleasure to see. thanks
0 Kudos
Reply