From: j DOT aldrich6 AT genie DOT com Message-Id: <199607211646.AA144917577@relay1.geis.com> Date: Sun, 21 Jul 96 16:36:00 UTC 0000 To: breezy AT dali DOT math DOT swt DOT edu Cc: djgpp AT delorie DOT com Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii Subject: Re: Problem Compiling via Make Reply to message 2469259 from BREEZY AT DALI DOT M on 07/16/96 7:40PM Warning: Another long, dry post coming up from yours truly. :) >I also forgot to mention that when linking for the main program, it complains >about undefined items. I have my DJGPP environment variable set, and I also >have tried the makefile below with -LC:\DJGPP\LIB. > >Also I am trying to use the libxlib.a file. I have placed the header files in >the include and the current directory (after it did not seem to find it in >the include directory). You're still making the same mistake as before. Also, it doesn't look like you've properly set your DJGPP environment variable in your autoexec.bat. This is REQUIRED for DJGPP programs to be able to find their files! According to what you have below, I think this is what you need: set DJGPP=C:/C/djgpp/djgpp.env That variable must point to the exact location of the 'djgpp.env' file, and must be typed EXACTLY like you see here (no extra spaces anywhere). Also, you must not move or alter your djgpp.env file. Read section 8.1 of the FAQ for additional suggestions on finding libraries. Now, on to the makefile... > # constants > ALL = main.o init.o inputq.o ALL is a bad name for your .o files. Most people prefer the name OFILES to represent this (or something similar). ALL could be confused with the standard target 'all' which is generally used to perform all the functions of a given makefile at once. > LIB_FLAGS = -L/C/djgpp/LIB -lxlib The -L should not be necessary if you've set your environment correctly. > CFLAGS = $(LIB_FLAGS -O2) This is WRONG. First, to be syntactically correct it should look like this: CFLAGS = $(LIB_FLAGS) -O2 (Note that in the first case, you were asking for a variable called "LIB_FLAGS -O2", which doesn't exist.) Second, you should always place your link flags as the LAST things on the compilation command line. See section 8.9 of the FAQ for why. (In fact, I'd recommend that you read section 8 in its entirety.) I'd also recommend adding -Wall, -O, and -g to your CFLAGS, to catch all possible errors and make debugging easier. > RM = del > CC = gcc $(CFLAGS) Again, try not to do this. CC should only specify the name of the compiler - your command line should have CFLAGS and LIB_FLAGS as separate entities. > # main program > main.exe: $(ALL) > $(CC) $(ALL) -o main.exe Instead of using main.exe on your command line, you should use the automatic variable $@, to represent the target of the rule. > main.o: main.c main.h consts.h init.h defines.h xlib.h inputq.h > $(CC) -c main.c Here you should use the automatic variable $< to represent the first dependency of the rule. It is also useful to define a pattern rule for all .c files, unless some files have different compilation requirements than others. Individual dependencies can be specified as separate lines in the makefile. > init.o: init.c consts.h > $(CC) -c init.c > > inputq.o: inputq.c inputq.h > $(CC) -c inputq.c > > clean: > $(RM) *.o I would write the above makefile like so: # constants CC = gcc RM = del CFLAGS = -Wall -g -O -c LFLAGS = -Wall -g -O LIBS = -lxlib OFILES = main.o init.o inputq.o # dependencies (Specified without commands, a rule is treated as a # list of dependencies for the specified target. This is particularly useful # for pattern rules like those below.) main.o : main.h consts.h init.h defines.h xlib.h inputq.h init.o : consts.h inputq.o : inputq.h # main program main.exe : $(OFILES) $(CC) $(LFLAGS) -o $@ $(OFILES) $(LIBS) # This pattern rule states that for each target file with the .o extension, its # dependency is the matching file with a .c extension. The $< in the # command is replaced with the name of that dependency. %.o : %.c $(CC) $(CFLAGS) -c $< clean : $(RM) *.o