Re: [ooc-compiler] C interface problems
Brought to you by:
mva
|
From: Stewart G. <sgr...@ii...> - 2004-11-04 03:20:48
|
Hi August,
What you've done looks more-or-less OK to me.
One potential problem: the glut functions are defined as "APIENTRY",
which under Windows means that they use the "stdcall" calling
convention rather than "cdecl". Therefore, you should probably specify
"Pascal" rather than "C" as your interface type. That is:
MODULE Glut [INTERFACE "Pascal"; LINK LIB "glut32"; LIB "opengl32";
END];
I think the same goes for the other GL modules. Presuming that the
linker knows the procedure attributes, that may be why it is giving the
error (ie. the procedure name matches, but the attributes are wrong).
Please give this a try and let me know whether it fixes the problem.
Regarding the OpenGL interface: I didn't look at the GLUT functions,
but in principle it should not be hard to translate these as well. To
make a usable package probably requires a translation of gl.h, glu.h,
as well as glut.h. If I get some time I'll take a look at this.
Cheers,
Stewart
On Thursday, November 4, 2004, at 04:17 AM, August wrote:
> Hi everyone,
>
> I'm trying to use OOC to compile a minimal OpenGL test program with
> GLUT. I emailed the list about the subject a couple of months ago but
> I never got it to work. S. Greenhill mentioned his OpenGL interface,
> but unfortunately it lacks the GLUT definitions (moreover I prefer to
> rename the identifiers by removing the prefix).
>
> In C the code (not the generated code) is:
>
> #include <GL/glut.h>
> int w;
> void Display(void) {}
> int main(void)
> {
> w = glutCreateWindow("OpenGL Test");
> glutDisplayFunc(Display);
> glutMainLoop();
> return 0;
> }
>
> It can be compiled and linked with the command ` gcc -o test
> test.c -lopengl32 -lglut32'. When I run the program it successfully
> displays an empty window.
>
> Now to the Oberon-2 counterpart. I have a module named Glut.Mod which
> contains:
>
> MODULE Glut [INTERFACE "C"; LINK LIB "glut32"; LIB "opengl32"; END];
> IMPORT C;
> PROCEDURE ["glutCreateWindow"] CreateWindow*(title: ARRAY OF
> C.char): C.int;
> PROCEDURE ["glutDisplayFunc"] DisplayFunc*(p: PROCEDURE);
> PROCEDURE ["glutMainLoop"] MainLoop*;
> END Glut.
>
> The test program is:
>
> MODULE Test;
> IMPORT C, Glut;
> VAR w: C.int;
> PROCEDURE Display;
> END Display;
> BEGIN
> w := Glut.CreateWindow("OpenGL Test");
> Glut.DisplayFunc(Display);
> Glut.MainLoop
> END Test.
>
> When I execute `oo2c -M -v -r .. Test.Mod' I get the following output:
>
> cd e:/home/ob2/c-interface/src/
> oo2c -M -v -r .. Test.Mod
> - /usr/local/lib/oo2c/pkginfo.xml
> - /home/ob2/c-interface/sym/Test.Sym
> - /usr/local/lib/oo2c/sym/RT0.Sym
> - /usr/local/lib/oo2c/sym/Object.Sym
> - /usr/local/lib/oo2c/sym/HashCode.Sym
> - /usr/local/lib/oo2c/sym/Exception.Sym
> - /usr/local/lib/oo2c/sym/C.Sym
> - /home/ob2/c-interface/src/Glut.Mod
> - /home/ob2/c-interface/src/Glut.Mod
> + /home/ob2/c-interface/obj/Glut.d
> + /home/ob2/c-interface/obj/Glut.oh
> + /home/ob2/c-interface/sym/Glut.Doc
> + /home/ob2/c-interface/sym/Glut.Sym
> - /home/ob2/c-interface/sym/Glut.Sym
> + /home/ob2/c-interface/obj/Test_.c
> gcc -O2 -I/usr/local/include -DGC_WIN32_THREADS
> -I/usr/local/lib/oo2c/src
> -I/home/ob2/c-interface/obj -Iobj -I/usr/local/lib/oo2c/obj -c
> /home/ob2/c-interface/obj/Test_.c -o /home/ob2/c-interface/obj/Test_.o
> gcc -o /home/ob2/c-interface/bin/Test -L/usr/local/lib
> /usr/local/lib/oo2c/obj/RT0.o /usr/local/lib/oo2c/obj/HashCode.o
> /usr/local/lib/oo2c/obj/Object.o /usr/local/lib/oo2c/obj/Exception.o
> /home/ob2/c-interface/obj/Test.o
> /home/ob2/c-interface/obj/Test_.o -lopengl32 -lglut32 -L/usr/local/lib
> /home/ob2/c-interface/obj/Test.o(.text+0x5c):Test.c: undefined
> reference to `glutCreateWindow'
> /home/ob2/c-interface/obj/Test.o(.text+0x6d):Test.c: undefined
> reference to `glutDisplayFunc'
> /home/ob2/c-interface/obj/Test.o(.text+0x78):Test.c: undefined
> reference to `glutMainLoop'
>
> Compilation exited abnormally with code 1 at Tue Nov 02 03:14:32
>
> What am I doing wrong? Note that both `-lopengl32' and `-lglut32'
> appears in the output (in the correct relative order).
>
> Regards,
> August
>
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by:
> Sybase ASE Linux Express Edition - download now for FREE
> LinuxWorld Reader's Choice Award Winner for best database on Linux.
> http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click
> _______________________________________________
> ooc-compiler mailing list
> ooc...@li...
> https://lists.sourceforge.net/lists/listinfo/ooc-compiler
>
|