gm2
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gm2] Calling Modula-2 from C


From: Ron Kneusel
Subject: [Gm2] Calling Modula-2 from C
Date: Fri, 29 May 2009 10:21:49 -0500

Greetings!

I am attempting to use gm2 to be able to call Modula-2 procedures from C code.  My first attempt is this, qqq.c:

#include <stdio.h>

void helloworld_hello();  // nm of helloworld.o says this is the name

int main() {
    helloworld_hello();
    return 0;
}

and:

DEFINITION MODULE helloworld;
PROCEDURE hello;
END helloworld.

and:

IMPLEMENTATION MODULE helloworld;

FROM StrIO IMPORT WriteString, WriteLn;

PROCEDURE hello;
BEGIN
    WriteString('Hello world');
    WriteLn;
END hello;

BEGIN
END helloworld.

The helloworld.mod module works just fine if I call it from a Modula-2 program.  I am compiling it as:

gm2 -c helloworld.mod

to get the .o file and then I'm compiling and linking with :

gcc qqq.c helloworld.o

and I get:

helloworld.o: In function `helloworld_hello':
helloworld.mod:(.text+0x33): undefined reference to `StrIO_WriteString'
helloworld.mod:(.text+0x38): undefined reference to `StrIO_WriteLn'
helloworld.o:(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'

so, obviously, the linker cannot find the Modula-2 pieces it needs.  My question is, since I can find no libgm2 type file, how does one link against all the Modula-2 code that is needed to produce an output file?  A follow-up question is, is the naming convention of prefixing procedure names with the module name in the object code always followed so that the C code can call the right function?

Any help appreciated.  I'm sure I'm not the first person to want to do this.

Ron





HotmailĀ® has a new way to see what's up with your friends. Check it out.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]