From: "John M. Aldrich" Newsgroups: comp.os.msdos.djgpp Subject: Re: DJGPP standalone executable question Date: Wed, 04 Dec 1996 20:36:00 -0800 Organization: Three pounds of chaos and a pinch of salt Lines: 106 Message-ID: <32A65130.5FE7@cs.com> References: <199612042150 DOT AA17922 AT interlock DOT amoco DOT com> Reply-To: fighteer AT cs DOT com NNTP-Posting-Host: ppp222.cs.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: camorgan AT amoco DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp camorgan AT amoco DOT com wrote: > > Hi! > > I have the DJGPP C compiler and like it very much. However, I am trying > to compile a standalone executable in DOS 6.21 for someone else who does > not have the DPMI server. From the FAQ documentation, it appears there > is a way to do this. I refer to the following FAQ section: Before embarking on an attempt to help you with PMODE/DJ, I want to say that the easiest, simplest, and most efficient way to ensure that any distributed program will have DPMI is simply to package it with CWSDPMI.EXE. If your program doesn't find a resident DPMI host, it will look for CWSDPMI in its own directory or in the PATH. Many commercial programs include DOS4GW.EXE, which serves an identical function, so doing it for DJGPP packages can't be that terrible. Moreover, CWSDPMI is more than twelve (!!) times smaller than DOS4GW, so its meager 20K isn't going to hurt the size of your distribution. That said... > I do not understand these instructions! First of all, I am given a > method (under "How to Use" above using the "copy /B" command), then > later on a pitfall says this won't work and to "relink the image" (what > is an "image"?) Object code?) using the CRT1.o file that is included. > How is this done? I thought you could only relink "*.o" files; in other > words, how do I specify my *.EXE file as input along with the CRT1.O > file? > > What is a "coff image"? Re the TSR method: What is "stubedit"? How > would I "change the filename of the DPMI provider to PMODETSR.EXE"? > > I would appreciate a further explanation of the above in layman's > terms! The reason the instructions are the way they are is that the method they recommend SHOULD work, but don't because of a minor incompatibility problem. In layman's terms, here's what you need to do to work around the problem: 1) Put the included file "crt1.o" in the same directory as your program. 2) Recompile the program, including crt1.o on the command line. Thus, gcc -Wall -g -O -o myprog.exe main.c stuff.c morestuf.c becomes: gcc -Wall -g -O -o myprog.exe main.c stuff.c morestuf.c crt1.o This method should work, but I should warn you in advance that I haven't tested it. :) If you use RHIDE, you can specify additional files to link using the menus, but I'm not familiar enough with the interface to tell you how. Okay, on to the terms: "image" - The actual compiled code of your program, not including any of the extra stuff it needs to run, like the stub loader. If you don't tell gcc what file to output, i.e., omit the '-o' parameter, it generates "a.out", and "a.exe". "a.out" is the image; it's a complete program, but it can't run yet. "a.exe" is the image that has been prepended with a 2K stub which handles invoking DPMI and loading your program. "object code" - The actual machine language instructions generated by the compiler. Object code is stored in two forms: an intermediate form called an "object file" that only includes the code that you yourself have written, stored with the extension '.o'; and a form that has been linked with the code for all the functions you call in your program but don't actually write (like printf, etc., called "library code"). This final form is known as the "image". "coff" - One of many formats for storing object code in files. DJGPP uses the COFF format, so its images and object files are called "COFF images". A TSR is a program that remains in your computer's memory after it is run. Examples: DOSKEY, MSCDEX, all mouse drivers, COMMAND.COM, virus software, network drivers, CWSDPMI, etc. The "PMODETSR" program is a memory resident version of the PMODE extender. "stubedit" is a DJGPP utility that lets you modify the runtime parameters of your programs, including what they call themselves, what actual program they run, the amount of stack space and transfer buffer space they are allocated (if you don't understand this, don't worry), and the default DPMI host they use. To change the DPMI host of your program to PMODETSR, just type the following command: stubedit myprog.exe dpmi=PMODETSR.EXE This is somewhat silly however, because if you are going to use a resident DPMI host, you may as well use CWSDPMI, because it does a better job. Many of these concepts are covered in various C references and courses, and a basic grounding in them as they apply to DJGPP can be found by reading the DJGPP Frequently Asked Questions list (v2/faq202b.zip). The first 4-6 chapters can be particularly enlightening for those who are inexperienced with DJGPP concepts. :) -- --------------------------------------------------------------------- | John M. Aldrich, aka Fighteer I | fighteer AT cs DOT com | | Proud owner of what might one | http://www.cs.com/fighteer | | day be a spectacular MUD... | Plan: To make Bill Gates suffer | ---------------------------------------------------------------------