need help on gfortran and C++
Tobias Burnus
burnus@net-b.de
Wed Jan 11 08:57:00 GMT 2012
On 01/11/2012 08:33 AM, Mojtaba Seifi wrote:
> But I get the following error:
> main.cpp:(.text+0x41): undefined reference to `MULTAB_'
>
> extern "C" int MULTAB_(int&a, int&b);
>
> INTEGER FUNCTION MULTAB(A, B)
In gfortran, the "function multab" translates into "multab_" and not
"MULTAB_". You have to change the 'extern "C"' declaration to lower case.
(It depends on the Fortran compiler and the used options whether the
symbol becomes lower or upper case and whether it has one, two or no
trailing underscores.)
I assume that it is sufficient for you to change the name in the C++
file. However, I want to point out that Fortran also provides means for
better interoperability with C ["bind(C)"] - and thus with C++'s 'extern
"C"', cf.
http://gcc.gnu.org/onlinedocs/gfortran/Mixed_002dLanguage-Programming.html
Additionally, I want to point out that without using Bind(C) there might
be additional issues - and differences between compilers; in particular,
the way, "float"/"REAL" values and complex-number-returning functions
are implemented, differs among compilers.
Tobias
More information about the Gcc-help
mailing list