[mercury-users] Re: Compilation errors with Mercury and GTK--
Fergus Henderson
fjh at cs.mu.OZ.AU
Fri Feb 8 14:25:34 AEDT 2002
On 07-Feb-2002, Andy Coates <coates_andy at hotmail.com> wrote:
>
> 1. With a lot of tweaking, I managed to get a compiled/linked executable
> involving Mercury and C++ (lets assume for know that it actually works ;).
> But in order to achieve this, I had to introduce another Mercury file with
> a dummy main function that simply calls the original C++ main function.
> This was the only way I could get Mmake to link the object files it had
> compiled.
> Is there a way to get Mmake to link using the main function defined in my
> C++ file,
Yes, use the `--library' option to c2init.
> and without having a mercury_main function?
No. Why do you care if there is a mercury_main() function or not?
It doesn't occupy much code space ;-)
You don't actually need to *call* the mercury_main() function.
If you prefer, you can call mercury_init() at startup time,
then call the Mercury procedures that you have exported to C,
and then call mercury_terminate() at the end.
See runtime/mercury_init.h for the interfaces to these functions.
> 3. Although a compiled/linked executable does result from all the tweaking
> I've been doing with your help, it unfortunately dies horribly. I suspect
> the problem lies with the gtk-- code because of the errors. However, if you
> had any suggestions on why the following happens I'd gladly recieve them
>
>
> a) If I put the #include <gtk--.h> line in my C++ code before the
> #including of the mercury files, I receive the following compilation errors:
> bash-2.05$ mmake
> MERCURY_C_COMPILER=g++ mgnuc --high-level-code -g
> -DMR_MACHDEPS_ALPHA_REGS_H -DMR_MACHDEPS_MIPS_REGS_H
> -DMR_MACHDEPS_SPARC_REGS_H -DMR_MACHDEPS_I386_REGS_H
> -DMR_MACHDEPS_PA_REGS_H -DMR_MACHDEPS_RS6000_REGS_H
> -DMR_NO_BACKWARDS_COMPAT -g `gtkmm-config --cflags` -c cpp_main.cc
> In file included from
> /usr/lib/gcc-lib/i386-slackware-linux/2.95.3/../../../../include/g++-3/stl_alloc.h:45,
> from
> /usr/lib/gcc-lib/i386-slackware-linux/2.95.3/../../../../include/g++-3/alloc.h:21,
> from
> /usr/lib/gcc-lib/i386-slackware-linux/2.95.3/../../../../include/g++-3/std/bastring.h:39,
> from
> /usr/lib/gcc-lib/i386-slackware-linux/2.95.3/../../../../include/g++-3/string:6,
> from /opt/gnome/include/gtk--/base.h:28,
> from /opt/gnome/include/gtk--.h:70,
> from cpp_main.cc:4:
> /usr/lib/gcc-lib/i386-slackware-linux/2.95.3/../../../../include/g++-3/iostream.h:97:
> `ostream::operator <<(char)' has already been declared in `ostream'
> /usr/lib/gcc-lib/i386-slackware-linux/2.95.3/../../../../include/g++-3/iostream.h:217:
> `istream::operator >>(char &)' has already been declared in `istream'
> gmake: *** [cpp_main.o] Error 1
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This looks like a C++ problem, unrelated to the use of Mercury: it
looks like somehow both the <iostream> and <iostream.h> header files
have been included (perhaps because gtk-- uses <iostream.h>, but your
code uses <iostream>?). <iostream.h> is for backwards compatibility,
and is not compatible with <iostream>, IIRC.
> b) If I put the #include <gtk--.h> file after including the mercury files,
> things compile and link, but I get these lovely run time errors!
>
>
> bash-2.05$ ./mercury_main
> In Mercury main, about to call cpp_main...
> In cpp_main().
> foo_test(42) returns TRUE
> foo_test(43) returns FALSE
>
> GLib-CRITICAL **: file ghash.c: line 138 (g_hash_table_lookup): assertion
> `hash_table != NULL' failed.
I don't know what the problem is here.
You could try compiling the Mercury code with --c-debug --no-c-optimize
in MGNUCFLAGS, and compiling the C++ code with `-g', then using gdb...
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
The University of Melbourne | of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-users mailing list
post: mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the users
mailing list