[plt-scheme] Re: stand-alone app
[Slightly extended reply. The first one didn't make it to the list, anyway.]
At Tue, 24 Sep 2002 19:28:38 -0500 (CDT), Jefferson Provost wrote:
> I'm trying to figure out the best way to build a stand-alone application
> that uses both MrEd and my own foreign (C/C++) code. Right now, what I
> have uses (make-embedding-executable) to build an executable with my
> scheme modules in it, one of which calls (load-extension) to load my
> foreign functions. This works as long as my pwd is the same as the
> directory where the compiled app is, but I can't figure out how to make it
> always find the extension regardless of the users pwd.
You can use the result of
(find-system-path 'exec-file)
to compute the right directory. The result from `find-system-path' can
be a relative path that is resolved via the user's PATH environment
variable, so use something like this to get an absolute path:
(let ([p (find-system-path 'exec-file)])
(if (absolute-path? p)
p
(find-executable-path p #f)))
This works only if you have a chance to find the directory before any
other code changes the current directory (which seems likely in your
case).
> I'd really rather have the native code linked directly into the app, but I
> can't seem to figure out how to do this, either. I've tried using mzc,
> and though I've been able to duplicate much of the function of
> make-embedding-executable with mzc, I haven't been able to get it to link
> in my foreign functions. Can it be done?
The mzc manual contains instructions for building a stand-alone
executable for native code. The specific instructions are for building
from Scheme source, but the same idea will work with extension code, I
think.
The makefile support for this is broken in the 202 distribution. I
recently fixed the MzScheme makefile, but not MrEd. Now the MrEd
makefile is fixed, too, in CVS.
The underlying problem, I think, is that extensions aren't tied into
the module system well enough. In particular, `make-embedding-executable'
should be able to embed extensions as well as bytecodes. I think I see
a way to make it work, but getting it right will take time.
Matthew