So I'm trying to create my first ever Makefile and have run into some issues. My program is broken down like this:

filter.c - contains main()
includes.h - #defines
io/file_io.c - contains some functions that main() uses
io/file_io.h - included in filter.c and file_io.c

Hopefully that is clear enough. Now here is my make file:

# This makefile compiles and links the 3D filter program
# 
# Generated by: Ryan Forbes
# Last Modified: 28-JAN09

# ******************************************************************************
# These parameters control the Makefile Operation

CC = gcc
CFLAGS = -g
CFLAGSPOST = -lm
IO = io/
# ******************************************************************************
# These entries bring the 3Dfilter executable up to date

3DFilter: filter.o $(IO)file_io.o
        $(CC) $(CFLAGS) -o 3Dfilter filter.o $(IO)file_io.o

filter.o: filter.c $(IO)file_io.h includes.h
        $(CC) $(CFLAGS) filter.c $(CFLAGSPOST)

file_io.o: $(IO)file_io.c $(IO)file_io.h includes.h
        $(CC) $(CFLAGS) $(IO)file_io.c

However, when I try to run make, I get the following:

make
gcc -g filter.c -lm
/tmp/ccf326YC.o: In function `main':
/home/ctnetap1/de042465/3d_scic/music/src/cxx/filter.c:133: undefined reference to `getImageFiles'
/home/ctnetap1/de042465/3d_scic/music/src/cxx/filter.c:140: undefined reference to `getImageVolume'
/home/ctnetap1/de042465/3d_scic/music/src/cxx/filter.c:145: undefined reference to `getImageVolumeSwap'
collect2: ld returned 1 exit status

The functions its not finding are in the file_io files. Any ideas on what I am doing wrong? Thanks ahead of time.

3DFilter: filter.o $(IO)file_io.o
        $(CC) $(CFLAGS) -o 3Dfilter filter.o $(IO)file_io.o  $(CFLAGSPOST)

filter.o: filter.c $(IO)file_io.h includes.h
        $(CC) -c $(CFLAGS) filter.c

file_io.o: $(IO)file_io.c $(IO)file_io.h includes.h
        $(CC) -c $(CFLAGS) $(IO)file_io.c

Everything except the executable needs -c (compile only)
The executable needs all the libraries.

Everything except the executable needs -c (compile only)
The executable needs all the libraries.

Right, the executable doesn't have the -c flag though now.

So does it work?
Post your latest if not.

If you look at the original Makefile I posted, it never had the '-c' in the executable line. So I was getting the error without -c in the executable line. I haven't changed anything as of now.

> $(CC) $(CFLAGS) -o 3Dfilter filter.o $(IO)file_io.o $(CFLAGSPOST)
This does NOT have -c

All the other ones need -c

Post a log.

I'm so sorry, I thought I had included the -c in the other ones. Again, my apologies. All works fine! I guess I should read my own posts better in the future. Thanks again for your help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.