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

Ondrej Bojar oboj7042 at ss1000.ms.mff.cuni.cz
Sun Dec 16 09:02:09 AEDT 2001


Hi.

When trying to link together a bigger project, I get lots of `undefined
reference' errors for functions/data objects such as:
MR_ticket_counter_var, MR_trail_ptr_var, MR_ticket_high_water_var,
MR_untrail_to...

The project consists of:

module1.m
module2.m
...
modulen.m
merc_interface.m

cpp_code1.cc
cpp_code2.cc
...
cpp_coden.cc
cpp_main.cc

Where mercury modules highly depend on each other, cpp_interface.m is a
wrapper for all the modules and exports several predicates for C++ code.

cpp_modules again depend on each other (via cpp_codex.h header files) and
some of them depend on the merc_interface.h -- they use the exported
predicates from mercury.

cpp_main.cc is the only module to contain function main. (This function
main also calls mercury_init.)

I compile the Mercury moduleX.m this way:

1. mmake moduleX.depend
2. mmake moduleX.o

(I also have a separate module test_just_mercury.m, which contains pred
main(io::in, io::out) and test all the predicates in modules_x.m. I use
1. mmake test_just_mercury.depend
2. mmake test_just_mercury
to build the executable.)

I use mgnuc to compile cpp_codex.c into cpp_codex.o. (Based on
cplusplus_calls_mercury/Mmakefile sample.)

When I compile all the .o files, I use c2init and mgnuc to make init.o:

c2init --library --grade asm_fast.gc module*.c -o init.c
mgnuc --grade asm_fast.gc -c init.c

And finally, I use ml to link it:

ml -o project module*.o cpp_code*.o merc_inteface.o


To be honest, the explained process works fine, when done manually on a
smaller sample.
Since my project contains 42 modules.m and I use mmake to call c2init and
the following mgnuc.

Part of my Mmakefile is:

C2INITFLAGS=--library
init.o: merc_interface_init.o
	mv merc_interace_init.o init.o

...and there is not a line about merc_interface_init.c, mmake knows by
itself, how to make merc_interface_init.o from merc_interface.m

But then, there comes the problem with linking.

My questions:

1. Is the above "ml -o project ..." line correct? Do I miss anything?
2. Or can mmake do this for me *by itself*? (If I just specify c_code*.o
files somewhere.)
3. Is there a better scheme to do all the compilations?
4. Can anything save me the work of looking up all the necessary module*.o
files for linking? (The files are of course well known from
merc_interface.dep...)

Thanks for help and sorry for such a long question, Andrew.

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