Makefile include header

前端 未结 3 739
野趣味
野趣味 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:54

    You must link against the compilation unit inc.o which you obtain by compiling inc.c.

    In general that means that you must supply all object files that contain functions that are used in main.c (transitively). You can compile these with implicit rules of make, no need to specify extra rules.

    You could say:

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

    And make will know on its own how to compile inc.o from inc.c although it will not take inc.h into account when determining whether inc.o must be rebuilt. For that you would have to specify your own rules.

提交回复
热议问题