This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: need help on gfortran and C++



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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]