[mercury-users] Problem with linking bigger project (Mercury and C++)

Fergus Henderson fjh at cs.mu.OZ.AU
Mon Jan 7 07:35:23 AEDT 2002


On 05-Jan-2002, Ondrej Bojar <oboj7042 at ss1000.ms.mff.cuni.cz> wrote:
> On Sun, 6 Jan 2002, Simon Taylor wrote:
> > If you define a Mercury main/2 predicate (it won't be used),
> > this problem will go away. I'm not sure why this is needed.
> 
> Yes. It helped. I linked the program successfully, but I got segmetation
> fault from somewhere within mercury_init() and I don't know how to fix
> this...

> TLinMem komplexne_inicializuj(int DBSTATE) {
>     /* Inicializuje Mercury a pak Lingvistickou cast enta. */
>     char dummy;
>     TLinMem linmem;
> 
>     printf("komplexne_inicializuj: spoustim Mercury\n");
> 
>     /* Inicializace enginu Mercury */
>     mercury_init(0, NULL, &dummy);

Declaring `char dummy' here is wrong.  `char dummy', whose address
indicates the top-of-the-stack, should not be declared in a function
which returns before the Mercury procedures are called.

`char dummy' should be declared in main() [or some other function whose
stack frame sticks around while the Mercury procedures are being called]
and should be passed down to komplexne_inicializuj(), perhaps via a global
variable.

That may solve your segmentation violation problem.

If not, I suggest you start by using the "where" command in gdb to figure
out exactly where the segmentation fault is occurring.  (Put --c-debug
in MGNUCFLAGS and MLFLAGS.)

-- 
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