home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / emxfaq1.zip / EMXFAQ1.TXT next >
Text File  |  1995-05-13  |  24KB  |  505 lines

  1.  
  2. The EMX Frequently Asked Questions list, file 1 revision 1.
  3.  
  4.  
  5. ******************* Questions this file tries to address ********************
  6.  
  7. 1) What the heck is "EMX"?
  8. 2) Why would I want the EMX package?
  9. 3) Where do I get the EMX package?
  10. 4) How do I install the EMX package?
  11. 5) How do I compile 32 bit OS/2 programs with the EMX package?
  12. 6) How do I compile programs to use unix emulation?
  13.  
  14.  
  15. ************************  What the heck is "EMX"? ***************************
  16.  
  17. EMX is a unix emulator for dos and OS/2.  The name EMX stands for "EMulate
  18. uniX".  You take unix source code, compile it with any compiler and link
  19. it with the EMX libraries, and it'll run under the unix emulator.
  20.  
  21. The EMX unix emulator is available for unix as a DLL, and available for
  22. dos as a dos extending .EXE.
  23.  
  24. ******************** Why would I want the EMX package? ***********************
  25.  
  26. Because it's got a free, reliable, compatible, efficient C++ compiler.
  27.  
  28. --- What you get with the EMX development package:
  29.  
  30. The EMX package contains a fully functional port of the GNU C/C++
  31. compiler, capable of producing two different kinds of .exe files.
  32.  
  33. This compiler (GCC) can produce 32 bit OS/2 native mode executables
  34. comprable to those produced by most commercial compilers currently
  35. available for the OS/2 platform.  It can produce both text mode and
  36. presentation manager apps, multi-threaded apps, and .DLL Dynamic Link
  37. Libraries.
  38.  
  39. The EMX port of GCC is also capable of compiling unix apps to use the
  40. unix emulator EMX. Since unix has been around for twenty years, and since
  41. unix was designed in such a way that almost all unix programs must come
  42. with source code to be of any use, there is a heck of a lot of unix code
  43. out there which can be easily ported to run under OS/2 (or DOS) with this
  44. unix emulator.
  45.  
  46. The compiler comes with documentation in several formats, including
  47. ascii text (.doc files) and "view" books (.inf files) containing enough
  48. information for an average C/C++ programmer with little or no OS/2
  49. experience to write multi-threaded OS/2 presentation manager applications.
  50.  
  51. The main disadvantage of this compiler is that it does not come with an
  52. Integrated Development Environment (IDE) yet.  You have to do everything
  53. from the command line, or get a "make" utility and use "make" files.  The
  54. shareware editor "boxer" is recommended as a substitute for an IDE.
  55. Although users are encouraged to register boxer, which is fairly expensive,
  56. some people prefer it to professional Integrated Development Environments
  57. (IDEs).  Perhaps an IDE for GCC will become available in the future.
  58.  
  59. --- The advantages of GCC under EMX:
  60.  
  61. 1) It produces small, efficient 32 bit OS/2 executables.
  62. 2) It can also compile unix programs to use the unix emulator EMX, which
  63.    can run under both dos and OS/2.
  64. 3) The whole package only takes up around 10 megs of hard drive space.
  65. 4) The compiler works comfortably in 8 megs of ram, with room left over.
  66. 5) It can compile all three types of 32 bit OS/2 programs (full screen,
  67.    text window, PM window).
  68. 6) It's highly debugged, and has regular updates and patches.
  69. 7) It's compatible with almost all existing standards, including
  70.    ANSI, POSIX, and dos programming conventions.
  71. 8) It's absolutely free.  No strings attatched unless you try to sell it
  72.    (the EMX package) for profit.  The .exe files you compile with it can
  73.    be sold for profit, just like any other compiler.
  74.  
  75. --- The disadvantages of GCC under EMX:
  76.  
  77. 1) It's command line only (no IDE).
  78. 2) It only makes 32 bit apps (I.E. you can't make drivers, which are 16
  79.    bit apps.)
  80. 3) The documentation, while thorough, is poorly organized.  The docs also
  81.    don't explain the difference between compiling for native OS/2 and
  82.    compiling for the unix emulator very clearly.
  83. 4) The dos version of the EMX unix emulator (EMX.EXE) uses the VCPI method
  84.    of extending dos, which will not run under either OS/2 or microsoft's
  85.    windows.  This means you can't run the compiler (gcc.exe) in a dos window
  86.    under OS/2, you must run it in an OS/2 window, where it will use emx.dll.
  87.  
  88.  
  89. ******************** How do I get the EMX package? *********************
  90.  
  91. --- Where:
  92.  
  93. EMX is available via anonymous ftp from any "hobbes" archive site in the
  94. unix/emx09a directory.  Two of the largest are ftp.cdrom.com (directory
  95. /pub/os2) and hobbes.nmsu.edu (directory /os2).  Under each of those,
  96. the EMX package is in the directory unix/emx09a.  The name of this
  97. directory changes with each major version number, so it may be different
  98. by the time you read this.
  99.  
  100. --- Don't panic:
  101.  
  102. If you look in the emx09a directory, you will see zillions of files.
  103. Rest assured that you don't need most of them, at least not to start out
  104. with.  At least half of the files in there are the source code to things
  105. you can download pre-compiled.  The source code to almost everything
  106. (emx, gcc, the libraries, the utilities, etc.) is available here.  Most
  107. professional programmers wouldn't need this stuff, although it is nice to
  108. have it available.  Some of the extra files in this directory may be useful
  109. later, especially the optional libraries (curses, BSD, graphics,
  110. "objective c", etc).
  111.  
  112. --- How it's distributed:
  113.  
  114. All of the files ending in the extension .zip are compressed archive
  115. files, which must be uncompressed before you can use them.  The utility
  116. that created them is called "zip", and the one that can undo them is
  117. called "unzip".  A version of unzip is available on the hobbes archive
  118. site, in the subdirectory "archiver", filename "unz512x2.exe".  If the
  119. version number has changed, look for something similar starting with "unz".
  120.  
  121. Run unz512x2.exe in an empty directory.  This is a specially constructed
  122. archive that will unzip itself when you run it. It will split itself apart
  123. into several files (including documentation, some utilities, and the
  124. executable itself).  Copy the file unzip.exe into your path somewhere,
  125. it's a nice thing to keep around.
  126.  
  127. To use it, type "unzip filename.zip".  Putting ".zip" on the filename is
  128. optional, if you don't have it, it'll figure it out.
  129.  
  130. // If you would like a copy of zip to create your own zip files with (they
  131. // really do save space), get the file "zip201x2.exe" (or whatever the
  132. // version number's up to by then).  It's also in the archiver directory of
  133. // each hobbes ftp site, and it should create the file zip.exe when you run
  134. // it.  To create a zip archive file, go "zip filename.zip file1 file2..."
  135. // and so on.  Yes, it'll take wildcards.  Read the docs that came with
  136. // zip and unzip for more info.
  137.  
  138. --- What you need:
  139.  
  140. You need to get the following four files to compile C and C++ programs with
  141. the EMX package.
  142.  
  143.     1)  The EMX Runtime Environment                 Filename: emxrt.zip
  144.  
  145. This is the unix emulator, needed to run the compiler.
  146.  
  147. The "EMX Runtime Environment" is the unix emulator itself.  For dos,
  148. this is EMX.EXE.  For OS/2, this is emx.dll.  Most programs compiled to
  149. use unix emulation don't actually link the emulator into the program's
  150. .exe file, because it takes up a lot of room.  Instead, they call an
  151. external emulator when they're run, the way edit.com under dos 6 calls
  152. qbasic.exe.  This is why the same file can run under both dos and OS/2,
  153. it's the emulator doing the running, and that's what's specific to the
  154. platform.
  155.  
  156. Since GCC is a unix program which has been compiled to use the external
  157. unix emulator (emx.exe under dos, emx.dll under OS/2), you need to have
  158. the emulator available on the system to run gcc.exe, even if you only
  159. intend to create 32 bit OS/2 native programs with it, which do not require
  160. unix emulation.
  161.  
  162.     2)  The EMX Development package                 Filename: emxdev.zip
  163.  
  164. You need this to compile EMX programs.
  165.  
  166. These are the libraries and header files that you link with to compile
  167. programs that are going to use the EMX unix emulator.  There are also
  168. some libraries here to compile 32 bit OS/2 programs (most notably
  169. sys.lib), and a REXX file (omflibs.cmd) to convert most of the rest of
  170. the unix "*.a" libraries to 32 bit OS/2 "*.lib" format.  Don't worry
  171. about that now, just get it.
  172.  
  173.     3)  The GNU development package                 Filename: gnudev.zip
  174.  
  175. This contains the GNU C compiler itself.
  176.  
  177. This is a copy of the GNU C Compiler (GCC), ported to run under the EMX
  178. unix emulator.  GCC is one of the most popular ANSI C compilers for
  179. unix.  By default it creates unix style executables (for the intel 386 CPU
  180. (or higher) platform), which will be run by the EMX unix emulator, versions
  181. of which are available for both DOS and OS/2.  In addition, this version
  182. of GCC has been modified and supplemented to create 32 bit OS/2 native mode
  183. executables, including full screen text mode, windowed text mode, and
  184. presentation manager applications.  These do not need EMX to run, they
  185. are pure OS/2 executables.  The command line options to do this are
  186. -Zomf -Zsys.  See the "how do I compile" section for details.
  187.  
  188.     4)  The C++ preprocessor and libraries          Filename: gppdev.zip
  189.  
  190. This turns the C compiler into a C++ compiler.
  191.  
  192. Without this, GCC will only compile ANSI C.  This contains the
  193. libraries, header files, and compiler add-on executable to compile C++
  194. source code.  If you're only compiling ANSI C programs, and no C++, you
  195. can save some hard drive space space by not installing this, but I'd
  196. recommend getting it anyway.
  197.  
  198. --- Additional interesting files (optional):
  199.  
  200. The file "00index.txt" lists all the files available in each directory
  201. of the hobbes archive, with a one line description for each file.  The
  202. monolithic one is in the root directory of the hobbes archive (for
  203. ftp.cdrom.com this is /pub/os2), and a smaller one is in each
  204. subdirectory.  The copy of 00index.txt in the emx09a directory explains
  205. (briefly) what all the other EMX related files are.
  206.  
  207. You'll probably want to look at "bsddev.zip", which contains some extra
  208. libraries and functions, including the curses package and the random()
  209. function, to name a couple.  All of the extra library packages include
  210. the header files for those libraries.
  211.  
  212. Another compiler add-on similar to the C++ extensions is something
  213. called "Objective C".  This allows gcc to compile Objective C programs.
  214. If you don't know what it is, don't worry about it, but it's available.
  215.  
  216. Some of the files with "view" in their name might come in handy too.
  217. They're extra documentation in OS/2's ".inf" online book format.  This
  218. documentation is also avilable in "texinfo" format (the files with "doc"
  219. in their name), which can be viewed if you get "gnuinfo.zip" and install
  220. it.
  221.  
  222. Down near the bottom there's a graphics package for doing full screen
  223. SVGA graphics, but you're on your own figuring out how to use it.  The
  224. mandatory file "emxdev.zip" includes its own MCGA graphics package
  225. (320x200x256 colors full screen,) so you can do some low resolution
  226. graphics without this SVGA package.
  227.  
  228. --- Updates:
  229.  
  230. If EMX has been updated since you got your copy, there will be a file
  231. in the emx directory on hobbes called "emxfix??.zip" where the ?? is a
  232. two digit patch level number (at the time of this writing, 03).  If you
  233. get this and unzip it in the root directory of the drive that has EMX,
  234. and allow it to overwrite the existing files, it will update your copy of
  235. the EMX package.  These patches are mostly minor bug fixes; when any major
  236. changes are made the version number of EMX will change, in which case you
  237. should probably just get a whole new copy.  Expect patches every few
  238. months, with complete new versions perhaps once a year.  If you're happy
  239. with your copy of EMX, of course, you can just stick with it.
  240.  
  241. You don't need to worry about an emxfix??.zip file in the directory when
  242. you get a complete copy of EMX.  The files in the FTP site will already
  243. have been updated to include the patches.  If you miss a patch number,
  244. just install the newest patch: it will automatically include all older
  245. patches since the last change major revision where the version number
  246. changed.
  247.  
  248.  
  249. ******************* How do I install the EMX package? *********************
  250.  
  251. You unzip it, then meddle with config.sys a bit, reboot, then run omflibs.
  252.  
  253. --- Unzipping everything:
  254.  
  255. Once you have the ".zip" files and a copy of unzip.exe, pick a drive you
  256. want to put it on.  Go to the root directory of that drive and type:
  257.  
  258. "unzip c:\path\*.zip" where c:\path is whatever drive and directory the .zip
  259. files are on currently on.  If you're short of space, you don't have to
  260. have the .zip files on the drive where you're installing EMX.
  261.  
  262. This unzipping will create the directory "emx" from the root directory,
  263. and also a lot of subdirectories under it, where it will put all the
  264. various files.  Some files are duplicated in each archive (such as the
  265. GNU general public license in the file "COPYING" that basically gives
  266. you the legal right to use GNU programs as long as you don't try to sell
  267. them for profit.)  During the course of this unzipping, it will ask you
  268. if you want to overwrite these duplicate files.  Since they're
  269. identical, it really doesn't matter if you answer N or Y, a fast way to
  270. do it is to type capital A for all, which tells it to always overwrite
  271. and stop pestering you about it.
  272.  
  273. The useful directories under "\emx" are:
  274.  
  275. "bin"     All the .exe files go here, including gcc.exe.  You'll want this
  276.           in your path.
  277.  
  278. "dll"     The dynamic link libraries are here.  You'll want this in your
  279.           dll path.  This directory contains emx.dll for unix emulation,
  280.           several additional .dll files for gcc, and dll versions of the C
  281.           runtime library (optional, but keep it anyway.  You may want it
  282.           later).
  283.  
  284. "doc"     The plain text documentation files.  The three most interesting
  285.           files are (in order of interest) LIBREF.DOC, GNUDEV.DOC, and
  286.           EMXDEV.DOC.
  287.  
  288. "include" All the header files.  You need this to compile anything.
  289.  
  290. "lib"     All the library files.  You need this to link anything.
  291.  
  292. "book"    Duplicates of some of the files in "doc", in OS/2's ".inf"
  293.           online book format.  Not exactly vital, but nice to have.
  294.  
  295. Most other directories you find in there can probably be deleted,
  296. unless they're from an additional file you unzipped like bsddev.zip
  297. or emxdoc.zip.  I'd recommend unzipping the first three "vital" files,
  298. investigating and cleaning up everything you don't need, and only then
  299. unzipping additional optional files.  Otherwise it's too easy to get
  300. lost in a sea of unfamiliar files.
  301.  
  302. --- Meddling with config.sys:
  303.  
  304. The emx package wants to be in the path, and it also likes to have a
  305. couple of environment variables set.  This means you have to mess with
  306. config.sys and then reboot so the changes will take effect.  Yes, it is
  307. a pain, but you only have to do it once.
  308.  
  309. First, we need to add c:\emx\bin to the PATH statmement, and c:\emx\dll
  310. to the LIBPATH statement.  These two lines already exist, we're just
  311. appending a bit onto the end of each one.  Something like this...
  312.  
  313.     SET PATH=blah;blah;blah;blah;c:\emx\dll;
  314.     SET LIBPATH=blah;blah;blah;blah;c:\emx\lib;
  315.  
  316. Next, add the following new lines to the end of your config.sys file
  317. (modifying it for whatever drive you installed emx on, of course):
  318.  
  319.      set C_INCLUDE_PATH=c:/emx/include
  320.      set C_PLUS_INCLUDE_PATH=c:/emx/include/cpp;c:/emx/include
  321.      set LIBRARY_PATH=c:/emx/lib
  322.      set PROTODIR=c:/emx/include/cpp/gen
  323.  
  324. NOTICE!!!!!  Those are foreward slashes.  GCC is running under the unix
  325. emulator, remember?  Unix uses foreward slashes "/" instead of back
  326. slashes "\" to seperate directories.
  327.  
  328. // If you want to use "objective C" (It's a variant of C that's neither C
  329. // nor C++, if you don't know what it is, you probably don't need it),
  330. // you'll need to add one more line to the end config.sys:
  331. //
  332. //     set OBJC_INCLUDE_PATH=c:/emx/include
  333. //
  334. // And you'd probably want to get gobjcdev.zip, too.
  335.  
  336. --- Rebooting:
  337.  
  338. Select "shutdown" from the launch pad, or click with the right mouse
  339. button on the background of the presentation manager and select
  340. "shutdown now" from the little pop-up menu.  You'll have to confirm it a
  341. couple of times.  Once a message comes up telling you that OS/2 has
  342. written all its buffers to disk and is ready to shutdown now, you can
  343. either press the "reset" button on your computer or give it the standard
  344. three-finger salute (ctrl-alt-delete).  When OS/2 finishes rebooting,
  345. the EMX package should have all the paths it needs set up just fine,
  346. assuming there were no typos in config.sys.
  347.  
  348. --- Converting the libraries:
  349.  
  350. Finally, you'll want to go into the lib directory under the emx
  351. directory and run a file called omflibs, which is a REXX file that will
  352. convert all your unix style .a libraries into OS/2 style .lib libraries.
  353. This is the last step.  EMX and the GNU C/C++ compiler should now be
  354. installed and working.
  355.  
  356.  
  357.  
  358. *****  How do I compile 32 bit OS/2 programs with the EMX package? *****
  359.  
  360. To make 32 bit OS/2 native programs, you do this:
  361.  
  362. gcc -Zsys -Zomf -s -o filename.exe *.cpp
  363.  
  364. --- What that means:
  365.  
  366. The default activity for GCC is to compile programs to use the unix
  367. emulator "EMX".  To compile 32 bit OS/2 programs that use OS/2 system
  368. calls instead of the EMX unix emulator, you must add the command line
  369. switch -Zomf to the compiling phase, and -Zomf -Zsys to the linking
  370. phase. The above line combines the two activities into one command line.
  371. Yes, upper and lower case matters.
  372.  
  373. "-Zomf" tells the compiler to use .obj style object modules and .lib
  374. style libraries.  By default it uses the unix .o object modules and .a
  375. libraries, which can only be linked into a unix executable, needing EMX
  376. to run.
  377.  
  378. "-Zsys" tells the compiler to link with the OS/2 system call library
  379. "sys.lib" instead of the EMX unix emulation library "emx.a".  Since the
  380. system call library is only available in .lib format, you must use the
  381. -Zomf option to make -Zsys work.
  382.  
  383. "-s" tells the compiler not to include the symbol table (it's debugging
  384. information you really don't need) into the .exe file.  This makes the
  385. .exe smaller, and doesn't affect the way it runs at all.
  386.  
  387. "-o" tells it you're about to name the .exe file.  Be sure to include
  388. the extension .exe on the filename, which must be the next thing on the
  389. command line right after the -o switch.  If you don't do this, it'll
  390. name the .exe file after the first source code file on the command line.
  391.  
  392. The rest of the command lists all of the source files to create the
  393. program out of, in this case all files in the current directory ending
  394. with the extension ".cpp".  Files with the extensions .cpp, .cxx, .cc,
  395. or .C (capital C) will be compiled as C++.  Files with the extension .c
  396. (lower case) will be compiled as origional C.  Files with the extension
  397. .def will be used as module definition files, and files with the extension
  398. .res will be used as resource files.  Both of those are explained later.
  399.  
  400. Also, if you want to link with any extra libraries, you use the "-lname"
  401. parameter, where "name" is the name of the library (which must be in the
  402. /emx/lib directory when you compile.)  To link in the curses library, use
  403. the command line option "-lcurses".  Remember that upper/lower case matters.
  404.  
  405. --- If you've just moved up from DOS:
  406.  
  407. If your structures don't save to disk the way they did under dos, try
  408. putting the line "#pragma pack(1)" into the source code, before your
  409. structure definitions.  GCC defaults to aligning things on 4 byte
  410. boundaries for faster access, which can screw up binary structures that
  411. expect data items of fixed size with no gaps in them.  The #pragma tells
  412. it to stop that.
  413.  
  414. Temember that an "int" in OS/2 defaults to "long" (4 bytes), while an int
  415. under dos defaulted to "short" (2 bytes).  It's a good idea to always say
  416. "short" or "long" when you declare any int in a structure you're going to
  417. write to disk.
  418.  
  419. Direct screen writes don't work the same way under OS/2, use the "curses"
  420. library (in "bsddev.zip") instead.  It's for advanced cursor control.
  421.  
  422.  
  423. *********** How do I compile programs to use unix emulation? *************
  424.  
  425. This is the default.  Just go "gcc -o filename.exe *.cc"
  426.  
  427. --- What unix emulation does:
  428.  
  429. EMX can emulate many aspects of the unix operating system, including the
  430. way unix handles files, pipes, child processes, signals, and even core
  431. dump files.  Even complex apps like internet MUDs, or the GNU C compiler
  432. can be (and have been) compiled and run under EMX with little or no
  433. modification.  Currently X-windows is not supported by EMX, but only
  434. because nobody's ported it yet.
  435.  
  436. --- How you use unix emulation:
  437.                    
  438. Compiling for unix emulation is the default for the version of GCC that
  439. comes with the EMX package.  If you don't include the -Zsys switch on the
  440. command line when you link the program, it will be linked to use the EMX
  441. unix emulator.
  442.  
  443. By default, the compiler will generate unix style .o object files and link
  444. with unix style .a library files.  This is not particularly efficient under
  445. EMX, because the emulator has to do a lot more work and the .exe file is a
  446. great deal bigger.  However, this provides the highest level of unix
  447. compatability, and the files created can be run under dos with the dos
  448. program "EMX.EXE".
  449.  
  450. --- How to optimize it for OS/2:
  451.  
  452. If you include the switch -Zomf, the compiler will generate OS/2 style .obj
  453. object files and link with OS/2 style .lib library files.  This creates a
  454. smaller, faster executable, which still uses unix emulation to run.  However,
  455. this does sacrifice a small degree of unix compatability. For example,
  456. executables created with -Zomf cannot create core dump files.
  457.  
  458. Files created with -Zomf will only run under OS/2.  They will not run
  459. under dos.
  460.  
  461.  
  462. ****************************** Now What ? ********************************
  463.  
  464. At this point, a book on programming for OS/2 would probably come in handy.
  465.  
  466. --- Read the docs:
  467.  
  468. There are several good documentation files in the "doc" directory under
  469. the "emx" directory.
  470.  
  471. Read the file "libref.doc" through from beginning to end.  Print it out
  472. if you can, although you're going to have trouble stapling it as it's
  473. about 200 pages.  It lists and describes every single function,
  474. variable, and structure in the default libraries for the EMX compiler.
  475. There are hundreds of functions available to you, if you don't know what
  476. they are you can't use them.
  477.  
  478. Skim the files "gccdev.doc" and "emxdev.doc".  They explain additional
  479. things that GCC and EMX can do, including generating .DLL's,
  480. multi-threaded apps, and dynamically linking the C runtime library so it
  481. creates a very small .exe and calls a .DLL at runtime instead of the
  482. library code it didn't link in.
  483.  
  484. --- Whatever:
  485.  
  486. This is the end of EMXFAQ1.TXT.  If I get time, I may write an EMXFAQ2.txt
  487. explaining make files, .DEF files, .RES files, simple Presentation Manager
  488. programming, making multi-threaded apps with EMX, using .DLL's, making your
  489. own .DLL's, the -Zcrtdll option, and why #pragma pack(1) is a good idea.
  490.  
  491. This FAQ was written by Rob Landley (landley@clam.rutgers.edu, although
  492. I just graduated so that address is going away, and fidonet 1:266/30
  493. although I'm moving soon, so THAT address is going away).  I got bored
  494. one day and decided to write up what I knew about EMX after a rather
  495. frustrating learning process where I had to figure most of this out on
  496. my own.
  497.  
  498. Like all written works, this FAQ is copyright the author (me), may 1995.
  499. Permission to reproduce and transmit this thing in unmodified form is
  500. hereby granted.  But if you even want to correct my spelling mistakes, you
  501. have to get my permission.
  502.  
  503.                                                    Rob Landley
  504.  
  505.