0

I am trying to call a simple "Hello World" code from C using Fortran. When I compile using iFort, it is giving me "error LNK2019: unresolved external symbol HELLO referenced in function MAIN__"

C Code:

#include <stdio.h>

void hello_(){

    printf("Hello World :) \n");
}

Fortran Code:

       program Fortran_C_Link_Test
C
      implicit None
C
      call hello()
C
      stop
      end

How I Compiled:

cl -c c_src.c 

to generate the c_src.obj object file

ifort -c fortran_src.f 

to generate the fortran_src.obj object file

ifort -o program c_src.obj fortran_src.obj

to generate the executable

ledebb
  • 1
  • 1
  • Please show how you are linking, and be sure to read [this other question](https://stackoverflow.com/q/66855252/3157076) and its answers. – francescalus May 24 '22 at 15:51
  • Just updated with compiler options – ledebb May 24 '22 at 16:04
  • 4
    It seems your compiler expects a different name for the symbol of your external function/subroutine. Are these really the complete compiler options you are showing? Is this on MS Windows? Try `void HELLO(){` but also learn how modern C and Fortran interoperability is done using `bind(C)`. You should not need to do any assumptions about `hello` being `hello_` or `_hello` or `_hello_` or `HELLO` or `HELLO_` or whatever else the compiler is liking to use today. – Vladimir F Героям слава May 24 '22 at 16:07

0 Answers0