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

Compilation error while using iso_c_binding in Mix-language code.

D_Q__Y_
Beginner
1,245 Views
I am trying to use the c_ptr and c_loc of the iso_c_binding module, but a compilation errer is reported: "undefined reference to `iso_c_binding_mp_c_loc_'"

The compile commands I ues are:
ifort -c sub.f90
icc -c main.c
icc main.o sub.o 
And here follows my code.
 module try_ptr
 contains
    subroutine test() bind(c)
    use iso_c_binding,only : c_loc,c_ptr,c_int
    implicit none
    type(c_ptr) :: mptr
    integer(c_int) :: mj(10)
    mptr=c_loc(mj(1))
    return
    end subroutine test
end module try_ptr
#include <stdio.h>
int main()
 {
   printf("test\n");
 }

 

0 Kudos
1 Solution
Heinz_B_Intel
Employee
1,245 Views

Try:

icc -c main.c

ifort -nofor_main sub.f90 main.o

See description of option '-nofor_main' in compiler guide: It will make sure, the Fortran run time libraries are linked in while expecting  the main program not being  implemented in your Fortran code. This is the structure of your application

 

View solution in original post

0 Kudos
2 Replies
Heinz_B_Intel
Employee
1,246 Views

Try:

icc -c main.c

ifort -nofor_main sub.f90 main.o

See description of option '-nofor_main' in compiler guide: It will make sure, the Fortran run time libraries are linked in while expecting  the main program not being  implemented in your Fortran code. This is the structure of your application

 

0 Kudos
D_Q__Y_
Beginner
1,245 Views

This works out, thanks.

HeinzB (Intel) wrote:

Try:

icc -c main.c

ifort -nofor_main sub.f90 main.o

See description of option '-nofor_main' in compiler guide: It will make sure, the Fortran run time libraries are linked in while expecting  the main program not being  implemented in your Fortran code. This is the structure of your application


 

0 Kudos
Reply