comp.lang.ada
 help / color / mirror / Atom feed
From: Stephen Leake <stephen_leake@acm.org>
To: lifetime n00b <anonymous@yahoo.com>
Cc: comp.lang.ada@ada-france.org
Subject: Re: load and use a ".o" file?
Date: 21 Dec 2003 08:57:03 -0500
Date: 2003-12-21T08:57:03-05:00	[thread overview]
Message-ID: <mailman.151.1072015071.31149.comp.lang.ada@ada-france.org> (raw)
In-Reply-To: <132Fb.3462$I02.2996@newssvr23.news.prodigy.com>

lifetime n00b <anonymous@yahoo.com> writes:

> Stephen Leake wrote:
> > .dll and .so files are designed to do _precisely_ what you are trying
> > to do; they are the most efficient solution!
> 
> Well, not _precisely_, since a typical program using the .dll or .so
> files needs to know about those files when it is compiled itself,
> right? 

That's one way to use dynamically linked libraries. But if you look
under the hood, you will see that is just a variant of what you are
doing.

When a program that uses dlls starts up, it dynamically links the dll.
What you want is a program that dynamically links a dll at some later
time. In either case, the dynamic linking is the key.

> Maybe I wasn't clear on exactly what I need to do. The program that
> needs to load and use the object file is *already running* before
> the object file is compiled. This "main program" has no prior
> information about the data or routines which may be in the object
> file it is being told to load.

Well, it can't have absolutely _no_ information. It has to know the
list of subroutines (and their parameter profiles) that are in the
dll. Or, in COM style, it has to have a way of finding out what
subroutines are in the dll; which means it has to know the names of
the introspection subroutines in the dll.

When you dynamically link the compiled file into the main program, you
look up the addresses of those known routines.

> The "main program" operates much like a command prompt, and when
> (compile-file "hithere") is typed at the prompt, gnat will be called
> to compile an object file. Then when (load "hithere") is typed at
> the prompt, the object file is loaded and the data and/or functions
> in "hithere" are now available to the main program. 

Yes, that is what I thought you were doing. But how does the main
program know the names of the functions in "hithere"?

> Some additional information may have to be included in a supporting
> file produced at the same time the object file is produced, and this
> supporting file would be loaded when the object file is loaded.

Ah; perhaps that's the names of the functions? In Windows, that's a
.def file, which lists the names of the functions in a dll.

> That's the idea anyway. But I'm having a difficult time trying to
> figure out how to accomplish this seemingly straightforward task.

Go read the manuals on dlls, and dynamic linking in general, and on
COM. You are re-inventing the wheel! It may seem straightforward, but
it gets quite complicated. Fortunately, it has been solved.

Most good ideas have been thought of before :).

-- 
-- Stephe




  parent reply	other threads:[~2003-12-21 13:57 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-12-18 23:31 load and use a ".o" file? lifetime n00b
2003-12-18 23:59 ` Stephen Leake
2003-12-19  1:51 ` tmoran
2003-12-19 15:28   ` lifetime n00b
2003-12-19 18:08     ` Stephen Leake
2003-12-20 20:12       ` lifetime n00b
2003-12-20 21:15         ` tmoran
2003-12-20 23:41           ` lifetime n00b
2003-12-21  7:15             ` tmoran
2003-12-21 11:46         ` Simon Wright
2003-12-21 13:57         ` Stephen Leake [this message]
2003-12-22 19:29           ` lifetime n00b
2003-12-22 20:49           ` Jon S. Anthony
2003-12-22 23:15             ` Stephen Leake
2003-12-23  1:36               ` tmoran
2003-12-27 22:55               ` Jon S. Anthony
2003-12-28  3:28                 ` Stephen Leake
2003-12-28 16:14                   ` Georg Bauhaus
2003-12-29 22:45                     ` Jon S. Anthony
2003-12-29 22:42                   ` Jon S. Anthony
2003-12-30 15:17                     ` lifetime n00b
2003-12-30 16:56                     ` Stephen Leake
2003-12-22 15:50         ` Mark H Johnson
2003-12-22 19:46           ` lifetime n00b
2003-12-22 22:58             ` Mark H Johnson
2003-12-23 17:48               ` Robert I. Eachus
2003-12-23 17:59                 ` Mark H Johnson
2003-12-23 21:53                   ` Robert I. Eachus
2003-12-19 21:28     ` Simon Wright
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox