[plt-scheme] Re: stand-alone app
Matthew Flatt wrote:
> [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).
This works. I put in some startup code to find and load the extension
before I start my REPL, and it works fine. Our app will eventually
allow users to add their own C/C++ extensions, so I'll have to do
something like this anyway.
>
> 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.
Okay, I see now. Our program is going to be distributed in source form
(on sourceforge), I dunno whether we want to have to include the whole
PLT source tree inside ours. I'd rather not if I can help it.
> 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.
It would be nice to be able to include an extension as a module, but for
now, the solution above will work. Our program is probably going to
have a large app directory full of associated scripts and things, so
it's not a problem to have to load a "core extension" ... oxymoron
though it may be. ;-)
J.