Search code examples
unixmakefileobject-files

Fatal Error when executing a Makefile


I am currently working on an assignment that requires me to build a Makefile that

  • creates an include directory
  • copies math330.h file into the include directory
  • create a lib directory
  • compile the .c files in trig and exp as object files
  • make a library
  • install the library to the lib directory
  • compile the cli program against the include and library directory

So I have most of the coding down for this, but I keep getting errors for when i try to put the .o's for the trig functions in the include folder. The error is

trig/cos330.c:1:10: fatal error: 'math330.h' file not found

This is just the last part i need help with! Can someone give me hints about what I can do? Thanks!

all:
    mkdir -p ./include
    mkdir -p ./lib
    cp math330.h ./include
    gcc -l ./include/ -c trig/*.c
    gcc -l ./include/ -c exp/*.c
    mv *.o ./lib/
    ar r libmath.a lib/*
    mv libmath.a lib/
    gcc -l ./include/ cli/cli.c -L ./lib -lmath -lm

clean:
    rm -rf include
    rm -rf lib
    rm a.out

Solution

  • The option to specify an include directory is capital-I (I), not lower-case L (l).

    gcc -I ./include …
    

    The lower-case ell indicates a library name. Given -l ./include, the poor linker would have a schizophrenic time looking for a library lib./include.a or lib./include.so to link with (possibly in the ./lib directory), and it probably wouldn't find it. But it doesn't get that far.