[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Gm2] Linking, initialization, ..
From: |
Gaius Mulley |
Subject: |
Re: [Gm2] Linking, initialization, .. |
Date: |
Sat, 14 Jan 2012 12:52:35 +0000 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) |
Dragiša Durić <address@hidden> writes:
> Trying to figure some gm2 operation details out… Need help :)
>
> Code structure is most ordinary, I have directories where each
> directory (library root) and sometimes it's subdirectories contain
> source files of corresponding library. Compile process will compile
> all Modula-2 and C objects to object files in library roots.
Hi Dragiša,
> case 1:
>
> I make a shared library from my code. My issue with this are
> initializations (shared library constructor). If I understood this
> correctly, *all* my modules in (library root) will be topologically
> sorted and initialized in that order on library load?
true
> (Also finalized in reverse order on library unload?)
true
> Are all library modules initialized/finalized or just ones I import
> from my (client) program?
all library modules necessary to satisfy the module being linked.
So in this case:
http://www.nongnu.org/gm2/building_a_shared_library.html
all the modules necessary to satisfy library c.mod.
> case 2:
>
> I compile my sources and leave object files in (library root). What
> would be command syntax, equivalent of web site example for shared
> libs for such a case? I am not too intimate with GCC development other
> than gm2 so please help me here even if this is obvious for GCC
> environment.
http://www.nongnu.org/gm2/building_a_shared_library.html
yes so this allows you to only use the modules absolutely necessary in
your final program module.
compile with:
gm2 -fiso -g -c -fPIC a.mod
gm2 -fiso -g -c -fPIC b.mod
gm2 -fiso -g -c -fPIC c.mod
link with:
gm2 -fonlylink -fobject-path=/home/path/my/build:. -I/home/path/my/source:.
-fiso -shared -fshared -fPIC -g myprog.mod -o myprog.so
this should build a shared library with only those modules required by myprog
> case 3:
>
> Same as case 2, except for object files being archived in .a files.
>
> Most important for me, for all three cases is not to initialize
> modules I do not use, modules that just happen to be in said library.
ok so in this case the .o files have not been created by the -fPIC
option. You should be able to create .o files using:
gm2 -g -c a.mod
gm2 -g -c b.mod
gm2 -g -c c.mod
ar cr mylib.a a.o b.o c.o
and link your application using:
gm2 -g -fonlylink -I/home/path/my/source myprog.mod mylib.a
which will only initialise modules necessary to satisfying all
dependants of myprog.mod
hope this helps,
regards,
Gaius