Compiling

Mark Read mread@ozemail.com.au
Sat Feb 28 23:38:00 GMT 1998


Vicky, a simple project can be compiled like so:


SINGLE FILE COMPILE
gcc test.c -o test.exe

Notice that no dependancy checking is going on. Simply type "test" from the
DOS prompt to run your app. Note the -o flag is optional, if missed, the
resulting binary file will be called a.out. Note also gcc has many other
command line flags that control the behaviour of the compiler. The Cygnus
web page is an excellent starting point for more info on gcc, make, bash,
etc (explore the web site to find this info).

Eg: "gcc test.c" produces a.out

Consider this real simple test:

// hello.c
// test prog for gnu-win32 complier
#include <stdio.h>
int main(void)
{
    printf("\nHello, World!!");
}

>From the DOS prompt, compile and execute like so:

C:\gnu> gcc -o hello.exe hello.c
C:\gnu> hello
Hello World!!
C:\gnu>

>From Unix bash, compile and execute like so:

$ gcc -o hello hello.c
$ hello
Hello World!!
$


To reduce the compile time for more complex projects (ie. multi-file
projects), use "make". This utility simply determines which files have
changed since the last compile, and only compiles those files which have
changed, therefore (potentially) reducing the time required to compile a
large project which has many files. Make also does a lot of other smart
things too - beyond the scope of this reply.

When you type "make" at the bash or DOS prompt, it expects to find a file in
the current directory called "makefile". This file (a script) tell make what
to do.



A SIMPLE MAKE FILE

# -------------------------------------------------------------
# a simple DOS make file script for hello world test
# -------------------------------------------------------------

hello.exe : hello.o
    gcc -o hello.exe hello.o       # note, 1st char on this line *must* be a
TAB char

hello.o : hello.c
    gcc -c hello.c                     # note, 1st char on this line *must*
be a TAB char



Then, from a DOS prompt, simply type "make" to compile and link your file to
produce a binary (executable), like so:

C:\gnu> make
C:\gnu> hello
Hello World!!
C:\gnu>

Similarly, run "make" from bash, then run "hello.exe" (exe extensions are
really only used in the DOS/Windows world, Unix binaries don't normally have
an extension to their filename).




A MORE COMPLEX MAKE FILE

# ------------------------------------------------------------------
# sample Unix makefile (can be used for DOS too)
# this script produces the binary (executable) file "edit"
# ------------------------------------------------------------------

# produce binary "edit"
edit : main.o kbd.o command.o display.o \
       insert.o search.o files.o utils.o
        gcc -o edit main.o kbd.o command.o display.o \
                   insert.o search.o files.o utils.o

# all dependancies for "edit" appear below
main.o : main.c defs.h
        gcc -c main.c
kbd.o : kbd.c defs.h command.h
        gcc -c kbd.c
command.o : command.c defs.h command.h
        gcc -c command.c
display.o : display.c defs.h buffer.h
        gcc -c display.c
insert.o : insert.c defs.h buffer.h
        gcc -c insert.c
search.o : search.c defs.h buffer.h
        gcc -c search.c
files.o : files.c defs.h buffer.h command.h
        gcc -c files.c
utils.o : utils.c defs.h
        gcc -c utils.c

# cleanup code
clean :
        rm edit main.o kbd.o command.o display.o \
           insert.o search.o files.o utils.o



NOTES:
# is used to preceed a comment
\ is used to split long lines
use "make clean" to execute the code at the phony 'clean' label
(eg. remove edit binary and all object files created)


Under Unix, use "man <topic>" for more info.
eg $ man make will give you several pages all about the make utility.

Under DOS, use the excellent manhelp.hlp files (download from
http://www.itribe.net/virtunix/winhelp-man-pages/ ).

Hope this helps, Mark.



This excellent list is appended to some gnu email msgs.
You'd do well to save a ref to this list, and to check these links out.

ftp://ftp.cygnus.com/pub/gnu-win32/latest/                  (ftp site)
http://www.cygnus.com/pubs/gnupro/                    (Comercial Page)
http://www.cygnus.com/misc/gnu-win32/                   (Project Page)
http://www.cygnus.com/ml/gnu-win32                     (Mail Archives)
http://www.itribe.net/virtunix/winhelp-man-pages/     (HTML Man Pages)
http://www.lexa.ru/sos                               (Sergey Okhapkin)
ftp://www.lexa.ru/pub/domestic/sos/                (Sergey's ftp site)
http://www.fu.is.saga-u.ac.jp/~colin/gcc.html           (Colin Peters)
http://www.xraylith.wisc.edu/~khan/software/gnu-win32/    (Mumit Khan)
http://gnu-win32.paranoia.ru                   (Chuck Bogorad's ports)
ftp://ftp.deninc.com/pub (Den Internet Services - US mirror and ports)
http://www.bestweb.net/~aka/gnu-win32/  (GNU-Win32 Bash Configuration)
http://rcw.home.ml.org/                  (Rob Warner - software ports)
http://www.wenet.net/~garbanzo/gnuwin32/     (more - software portals)
http://www.wenet.net/~garbanzo/gnuwin32/rpm   (Redhat Package Manager)
http://www.parallax.co.uk/~andyp/index_text.html  (Andy Piper - ports)
http://www.tiac.net/users/cgf     (Christopher Faylor - package ports)

SEARCH ENGINES WITH gnu-win32 mail archive RELATED INDICIES:
http://www.findmail.com
http://www.search.com
add gnu-win32 or gnuwin32 to the search criteria.

Help for Win32 Beginners: http://www.relisoft.com





-----Original Message-----
From: Vicki <star5932@advnet.net>
To: gnu-win32@cygnus.com <gnu-win32@cygnus.com>
Date: Wednesday, 11 March 1998 23:21
Subject: Compiling


>How do i compile a file once its done?
>-
>For help on using this list (especially unsubscribing), send a message to
>"gnu-win32-request@cygnus.com" with one line of text: "help".
>


-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".



More information about the Cygwin mailing list