Composite problem when calling Fortran from C/C++



  • I'm trying to call a function written on Fortran from the C code. But I'm getting a "undefined reference"

    Example of function on Fortran in the file fort. f90:

    FUNCTION CULC(A,B) RESULT(SUM) BIND(C,name='CULC99')
    REAL A,B,SUM
    SUM = A + B
    RETURN
    END
    

    Basic code C, hello.c

    #include <stdio.h>
    extern float CULC99(float *a, float *b);
    

    int main() {
    float a = 10; float b = 10;
    float c;
    c = CULC99(&a,&b);
    printf("%f", a);
    return 0;
    }

    Windows computer gfortran and g++ Cygwin64 (resolving problems with missing libraries)

    undefined reference

    Checking the name of the function in an objective file with objdump, the name matches:

    введите сюда описание изображения

    I don't understand what's missing.

    I've been trying to do the same thing (because of another objective file) for pure C, everything's gonna be perfect.



  • How did you notice @user7860670?

    C and C+ should not be confused

    The problem is, I've confused the gcc and g++ compilers.

    After addition extern "C" The g+++ compiler found the functions to be performed.

    Maybe the gcc can handle the subset when used. externbut I couldn't check it out, because I had to connect the missing libraries, and I don't have the strength to do it after 3 days of war with the companion.



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2