Makefile include header

前端 未结 3 730
野趣味
野趣味 2020-12-18 20:22

I am new to Linux programming I tried to compile a simple test construction. But I\'m getting an error when compiling. Adding inc.c as well (in the app: line) doesn\'t work.

3条回答
  •  甜味超标
    2020-12-18 20:59

    You need to compile inc.c as well. A suitable approach (better scalable to larger applications) would be to split the Makefile up into different targets. The idea is: one target for every object file, then one target for the final binary. For compiling the object files, use the -c argument.

    app: main.o inc.o
        cc -o app main.o inc.o
    
    main.o: main.c inc.h
        cc -c main.c
    
    inc.o: inc.c inc.h
        cc -c inc.c
    

提交回复
热议问题