exporting C symbols

6 views
Skip to first unread message

holst

unread,
Jul 23, 2007, 12:26:23 AM7/23/07
to gg95, ho...@nada.kth.se
Hi G95 users and developers!

When I compile the following dummy module I cannot address the symbol
"X" in the compiled object file.

MODULE EXPORT
USE ISO_C_BINDING
INTEGER, BIND(C) :: X
CONTAINS
SUBROUTINE DOSTUFF
END SUBROUTINE DOSTUFF
END MODULE EXPORT

Is the symbol "X" optimized away in some way? The function "DOSTUFF"
is
still addressable. I'm using G95 version "gcc version 4.0.3 (g95
0.91!)
Jul 17 2007"

Thank you for clarifications.

Cheers,
--
Henrik Holst
http://www.nada.kth.se/~holst/contact.shtml

RBader

unread,
Jul 23, 2007, 10:26:13 AM7/23/07
to gg95
If you link in the binary compiled from the single source line

int x=5;

you can then add a main program which references X:

program f
use export
write(6, *) ' X is ',x
end program

The bind(c) on objects relies on storage being defined within
C. It works much like an "external" statement in C.

Regards

highegg

unread,
Jul 24, 2007, 3:07:18 AM7/24/07
to gg95

On Jul 23, 6:26 am, holst <henrikhols...@gmail.com> wrote:

to clarify further on RBader's comment: the bind(c) attribute on
variables can be
used to import C's external variables, not to export Fortran's.

Reply all
Reply to author
Forward
0 new messages