makefile for creating (.so) file from existing files

后端 未结 4 1454
无人及你
无人及你 2020-12-18 10:07

I have 4 files: 1.c, 1.h, 2.c, 2.h. I need a makefile, which will create a dynamic library (.so) from tho

4条回答
  •  囚心锁ツ
    2020-12-18 10:53

    I'm no gnu make expert, this seems reasonable to me

    CFLAGS+=-fPIC
    %.so: ; $(LINK.c) $(LDFLAGS) -shared $^ -o $@
    
    library.so: 1.o 2.o  # default target first
    
    # changes to `1.h` imply `1.o` needs to be rebuilt
    1.o: 1.h  
    2.o: 2.h
    

提交回复
热议问题