gm2
[Top][All Lists]
Advanced

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

Re: [Gm2] Confused about shared libraries


From: Gaius Mulley
Subject: Re: [Gm2] Confused about shared libraries
Date: Fri, 02 Oct 2009 15:45:56 +0100
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux)

Martin Kalbfuß <address@hidden> writes:

> Hi,
>
> I still don't understand the linking process completely.
>
> If I want to create a static library, I have to do
>
> gm2 -c *.mod.

Hi,

well, probably safer to:

  for i in *.mod ; do
     gm2 -g -c $i
  done

> I get the object files.
> These object files together with the definition modules give me a fully
> functional static library.
>
> ut I'm still not sure how to create a shared library. I assumed
>
> gm2 -c -fPIC *.mod

  for i in *.mod ; do
     gm2 -fshared -fPIC -g -c $i
  done

> to get position independent  objects. IS this the way to go, or do I
> miss something here?
>
> When I want to link with a static library I simply set GM2IPATH to the
> libraries directory.
>
> export GM2IPATH="path_to_library_objects_and_definitions"
> gm2 -I. -fmakeall -o program program.mod
>
> Right?

true

> But how to tell gm2 to link dynamically?

gm2 -g -fPIC -fshared -shared program.mod -o _program.so

  (you may need to tell gm2 where your shared library module exist,
   so be prepared to add -I$(GM2IPATH)/SO)


> I miss an option. Maybe -L and -l like gcc uses it?

you can add -L like gcc.  For example here is a way of producing a
shared library version of StrLib.mod which can be tested from Python
(taken from gm2/examples/swig/full-strlib):

gm2 -fshared -I. -c -fPIC -g -fswig -I../../../gm2-libs 
../../../gm2-libs/StrLib.mod
swig -c++ -python StrLib.i
gcc -c -fPIC StrLib_wrap.cxx -I/usr/include/python$(PYTHON_VERSION)
gm2 -fPIC -fshared -shared ../../../gm2-libs/StrLib.mod StrLib_wrap.o -o 
_StrLib.so


> It's a bit confusing because gm2 doesn't has libraries like I know from
> C.

the shared modules object code created will be very similar to C, but
the linking glue is specific to GNU Modula-2.  Although the linking
glue is pretty straight forward - have a look at program_m2.cpp after
you have performed the initial link above.  If you are prepared to
type in a very long command line you could link all the shared
libraries using gcc (ld) provided include every dependent module and
program_m2.o

Hope this helps

regards,
Gaius




reply via email to

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