[Top][All Lists]

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

Re: [Gm2] Compiling files in different folders.

From: Giorgio
Subject: Re: [Gm2] Compiling files in different folders.
Date: Thu, 12 Apr 2012 19:56:54 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv: Gecko/20120313 Thunderbird/3.1.20


it works! If I understand correctly, even if I want to link only,
I have to pass a .mod file to the compiler.

Thanks a lot for the hint!


I am trying to compile a small Modula-2 project, using gm2.
I am on Ubuntu 10.04, and my version of the compiler is 'GNU Modula-2  1.0.3  

My source files are in different folders:


All source files are in common, mergesort, quicksort, bin is the target 
The main module is contained in


My Makefile is in the root directory, and looks like this:

INC=-I../common -I../mergesort -I../quicksort
M2C=gm2 -flibs=iso,pim,logitech -fpim4

   @cd src ; \
   cd common ; \
   ${M2C} -c ${INC}<filename>.mod ; \    # One line for each .mod file
   cd ../mergesort ; \
   ${M2C} -c ${INC}<filename>.mod ; \    # One line for each .mod file
   cd ../quicksort ; \
   ${M2C} -c ${INC}<filename>.mod ; \    # One line for each .mod file
   cd ../common ; \
   ${M2C} -o ../../bin/myapp *.o ../mergesort/*.o ../quicksort/*.o


the link looks incorrect.  You need to ask gm2 to use the main module to
resolve the module dependencies and build the link command.  So

${M2C} -o ../../bin/myapp -fonlylink \
        -fobject-path=.:../mergesort:../quicksort \
        ${INC} mainmodule.mod

should do the trick.

hope this helps,

Everything runs fine (all the .mod files are compiled producing a .o file) until
the last line, where I want to link all the object files into an executable.
At this step, the linker complains that it cannot find certain symbols 
names) that are defined in some of the modules. However, by inspecting
the .o files, I have verified that the missing symbols are indeed contained
in the object files I passed on the command line.

As an alternative, I have tried using -fmakeall, but this works fine only if I 
put all source
files in the same directory. If the source files are not in the same directory,
-fmakeall does not work. Here is the command line I used:

gm2 -fmakeall -o ../../bin/sort_runner -g -flibs=iso,pim,logitech -I. 
-I../mergesort -I../quicksort SortRunner.mod

I get several error messages like
     .../src/common/SortRunner_m2.cpp:181: undefined reference to 
/tmp/ccGH2cB3.a(SortManager.o): In function `_M2_SortManager_init':


     ...src/common/SortManager.mod:88: undefined reference to 

Note that module SortManager is in folder src/common, and has an undefined 
reference to module QuickSortList,
which is in folder src/mergesort.
On the other hand, Module SortRunner is also in src/common, and has an 
undefined reference to module
StringArray, which is in the same directory src/common.

At the moment I do not know how to continue. I wanted to ask if I am doing 
something wrong (using the
wrong compiler options) or if this could be a compiler bug (as far as I 
understand from the documentation,
-fmakeall should find and compile all the module using the paths specified with 

Thank you in advance for any useful hints.

gm2 mailing list

reply via email to

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