cmakefile

C: How do I make a makefile that allows linking to an external library?


Like, I think I'm close... just not sure what I'm doing wrong,

cfann : main.o
    main.o -l libfann

main.o : main.c
    gcc -c main.c

clean: 
    rm -rf *o cfann

I get this error:

main.o -l libfann
make: main.o: No such file or directory
make: *** [cfann] Error 1

Solution

  • Change:

    cfann : main.o
        main.o -l libfann
    

    to:

    cfann : main.o
        gcc main.o -lfann -L/usr/local/lib -o cfann
    

    This assumes that libfann.o is in /usr/local/lib - change the -L path above if it's actually somewhere else.