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

Linking error while compiling C+Fortran from a converted CVF project

Bernard_D_
Beginner
837 Views
Hello,

I am using Intel Visual studio 2010 to compile a program that we develop in my lab. There are both C (for embedding, lecture of licence file, parsing of data files, etc.) and Fortran (for computation part) subroutines. The main program is written in C and calls a fortran subroutine which manages the computation.
I compiled this code with CVF before, and have converted the dsw file with IVF as specified.
I choose C as the main program, and the fortran subroutines make thus a library.

Everything is almost fine while compiling, but at link, I obtain the classical :
error LNK2019: unresolved external symbol _simple referenced in function _main

The main function is mainly:

main (argc,argv)
int argc;
char **argv;
{ ...
simple();}

while the simple subroutine (fortran one) begins with:

subroutine simple
!#ifdef WIN32
!MS$ATTRIBUTES C,ALIAS:'_simple' :: simple
!#endif

I understand that in some way, the main does not find the simple subroutine. I asked Intel support about this, and I was advised to use !DEC$ATTRIBUTES C,ALIAS:'_simple' :: simple in the fortran subroutine. This was working fine for support, but when I use this, the problem remains. I suppose thus that there is also smthing in the project.
I have drstically simplified the program with the original CVF project to keep the problem. I can provide you with it if you will.

Thank you in advance,
Dr. B. Dussoubs
0 Kudos
7 Replies
anthonyrichards
New Contributor III
837 Views
If your library is A DLL, you must EXPORT the symbol _simple (lower case).
Otherwise, if it is a static library, use DUMPBIN on the library to get a list of symbols and see what the symbol is for the 'simple' routine.
Remember also that IVF uses a different default calling (and naming) convention than CVF.
0 Kudos
mecej4
Honored Contributor III
837 Views
The exclamation marks in these lines
[fortran]!#ifdef WIN32
     !MS$ATTRIBUTES C,ALIAS:'_simple' :: simple
!#endif
[/fortran]
suggest that the person who put them in was trying to coerce the name decoration to work even when WIN32 was not set. If so, you are compiling for WIN64, and the name decoration conventions for C and Fortran are not the same as for WIN32.

Please clarify. I doubt that the device that you are trying to control will work with 32-bit instructions as well as 64 bit instructions (unless it contains an X64 processor itself!).
0 Kudos
Wendy_Doerner__Intel
Valued Contributor I
837 Views
Bernard,

More information on the differences between CVF and Intel Visual Fortran here. Also you might check the documentation on DLLs and Mixed Language programming to flesh out some of the suggestions made here about the cause or even take a look at the Mixed Language Programming sample for ideas on how to implment this in Intel Visual Fortran.

It is installed by default on your system at: C:\Program Files (x86)\Intel\Composer XE 2011 SP1\Samples\en_US\Fortran\Mixed_Language.zip

Wendy
0 Kudos
Bernard_D_
Beginner
837 Views
Thank you everybody for your advices.
In fact, the problem comes (quite logically) from the fact that the fortran library must be added as an additional dependency in the Linker/Input section of the properties for the C++ project.

I do not think (I may be wrong) that this is explicitely precised in the white paper describing CVF to IVF project migration. I think that, whatever obvious (not enough for me I am affraid), this could be added. Unless this does not apply systematically ?


Best Regards,

Dr. B. Dussoubs
0 Kudos
anthonyrichards
New Contributor III
837 Views
Yes, if you create MYDLL.DLL and EXPORT symbols from it, then the list and location of the exported symbols will be created in file MYDLL.LIB at the same time. That is the file that must be included in any project that needs to link to the DLL in order to supply the required external reference symbols for the main program.

If you examine the Linker...Input Aditional dependencies entry in a project's property pages, you will see whole load of .LIB files listed. You could add MYDLL.LIB there, if you want, but the file would have to be located in a folder that is included in the list of folders in the PATH environment variable that the linker will follow to try and locate the file. Best just to add it to the project.
0 Kudos
Wendy_Doerner__Intel
Valued Contributor I
837 Views
Thanks for the suggestion. I have forwarded it on to Steve Lionel the author of the migration paper.

------

Wendy

Attaching or including files in a post

0 Kudos
Steven_L_Intel1
Employee
837 Views
This really has little to do with CVF migration and everything to do with VS2010. You would encounter the same problem migrating a pre-VS2010 mixed-language application to VS2010. This is covered in the Intel Fortran release notes and in the Configuring Visual Studio for Mixed-Language Applications article. But I can see that the "Extract Compaq Visual Fortran project items" wizard needs to be adjusted to take into account VC2010's refusal to deal with project dependencies.
0 Kudos
Reply