Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
23 Views

C interoperability, passing constants

Hi all!

I am having trouble compiling the following code:

C code:

#include <stdlib.h>

extern const int foo = -1;


Fortran code:

module cnst_m

  use, intrinsic :: iso_c_binding, only: c_int

  implicit none

  private

  public :: &
    FOO

  integer(kind=c_int), bind(c), protected :: FOO

end module cnst_m

program cnst_p

  use cnst_m, only: FOO

  implicit none

  print *, FOO
  stop
end program cnst_p

When using the "-init=(minus_)huge" flag, the compiler returns:

/tmp/ifortSUJ720.o:(.data+0x0): multiple definition of `foo'
./cnst.o:(.rodata+0x0): first defined here

The problem is also present with real initialization.

I would wager this has something to do with the way default initialization is defined.

Thank you very much.

Best regards,

José Rui

0 Kudos
3 Replies
Highlighted
Valued Contributor III
23 Views

Try with 'name=' option with bind(C,):

integer(kind=c_int), bind(C, name="foo"), protected :: FOO !<-- Note name= option

 

0 Kudos
Highlighted
23 Views

Makes no difference here.

Thank you very much.

Best regards,

José Rui

 

0 Kudos
Highlighted
Valued Contributor III
23 Views

What happens if you do not define it in your C code:

extern const int foo;

but do so in Fortran:

integer(c_int), bind(C, name="foo"), protected :: FOO = 1

If this doesn't work, see if you can get help from Intel support.

0 Kudos