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

Fortran and C name mangling issue with intel compilers

Kunal_Rao
Novice
1,560 Views
Hi
I am having a huge application with lots of Fortran files and C files. I am using Intel Compiler Suite Professional Edition for Windows and working in the cygwin environment.
icl is:
------
Intel C++ Intel 64 Compiler Professional for applications running on Intel 64, Version 11.1 Build 20100806 Package ID: w_cproc_p_11.1.067
Copyright (C) 1985-2010 Intel Corporation. All rights reserved.
------
ifort is:
------
Intel Visual Fortran Intel 64 Compiler Professional for applications running on Intel 64, Version 11.1 Build 20100806 Package ID: w_cprof_p_11.1.067
Copyright (C) 1985-2010 Intel Corporation. All rights reserved.
------
The C routines are being called from fortran files.
After compiling with intel compilers, Fortran object files have symbols without the trailing underscore while the C files have the object files with the symbols with a trailing underscore.
e.g. C object file has dummy_symbol_
Fortran object file has dummy_symbol
Due to this I am getting unresolved external symbol errors.
This works with other compilers, but with intel compilers, this C and Fortran interoperability issue I am facing.Is there some easy way to fix this, without going into the code and making changes for each routine ?
May be by adding some flag while compiling C/Fortran files or having some environment variable set which can take care of that trailing underscore or some other alternative.. ?
I was looking in the user guide but could not find the reqd. information properly. Can you please let me know how do I resolve this issue ?
Thanks & Regards,
Kunal
0 Kudos
8 Replies
mecej4
Honored Contributor III
1,560 Views
It is worthwhile for you to read the guides provided and become familiar with the options available. Simply typing "ifort /?" will display a short summary of the options.

Look into the /assume:nounderscore and /names:lower options.

Options that you use most of the time can be placed in the file ifort.cfg in the compiler's BIN directory.

You can, as an alternative, use the F2003 C-interoperability facilities. While requiring more lines of code to be added for the declarations for the C-bindings, this approach makes the code compiler independent.
0 Kudos
Kunal_Rao
Novice
1,560 Views
Thanks for your quick reply. I have checked these 2 options but that does not help. The trailing underscore is with the symbol in the C object file. And the intel C compiler does not have the /assume:nounderscore option.
It is available with ifort but not with icl.
The C routine is called from Fortran file.
icl compiled C object file has symbol as: dummy_symbol_
ifort compiled Fortran object file has symbol as: dummy_symbol
I will look more into the options available. But let me know if you are aware of some option with icl which can prevent the trailing underscore with the symbol.
Thanks & Regards,
Kunal
0 Kudos
abhimodak
New Contributor I
1,560 Views
I am not 100% sure; just a suggestion -- will !DEC$ ATTRIBUTES DECORATE, ALIAS help?

Abhi
0 Kudos
Kunal_Rao
Novice
1,560 Views
This issue is with many symbols in several files in my application. Since it works with other compilers, I am trying to avoid making changes in the code. My first preference will be to check if using some compiler options or env. variables it can be fixed. If nothing works, then I can go ahead and start adding directives or make changes in the code.
Thanks & Regards,
Kunal
0 Kudos
IanH
Honored Contributor III
1,560 Views
Why don't you just put /assume:underscore on the fortran command line and leave the C one as is? /assume:nounderscore is already the default for ifort on windows - that's why you've got the problem!

The C interoperability feature of Fortran 2003 avoids all this and more, so consider using this (BIND(C) etc) to explicitly make the link between the Fortran and C entities. It then becomes the compiler's problem to generate the right symbol, and not yours. Compilers that support C interop are common enough these days.

Given F2003 C-interop achieves what you need in a robust, compiler independent and standard conforming way I don't recommend the compiler specific !DEC$ ATTRIBUTES type of solution.
0 Kudos
TimP
Honored Contributor III
1,560 Views
While the options -Qlowercase /assume:underscore change the ifort mangling convention to match usual linux practice (inherited from 4.3BSD), and I use it myself, the experts don't recommend it. Among other things, it might break legacy usage of the ifport library, if you failed to include USE IFPORT. Certainly, if you intend portability, bind(c) is the best solution.
0 Kudos
abhimodak
New Contributor I
1,560 Views
Using F2003 standard is my first choice as well...

mecej4 has already suggested that in his response. The usage of attributes is just another option; I admit, I would say think again before using it.

Abhi
0 Kudos
Kunal_Rao
Novice
1,560 Views
Thanks IanH for your reply. Adding /assume:underscore on fortran command line worked and all those unresolved symbol errors are now gone. If reqd., I will check (BIND(C)) otherwise atleast for now my problem is solved.
Thanks & Regards,
Kunal
0 Kudos
Reply