A Makefile with Multiple Executables

前端 未结 4 1299
独厮守ぢ
独厮守ぢ 2020-11-22 13:48

I am trying to write a makefile which uses macros to create multiple executables from multiple files at once. I tried searching through previously answered questions but, be

4条回答
  •  时光说笑
    2020-11-22 14:07

    The following answer includes multiple executable such as initiate, process1, process2, ..., process4.

    LOCAL_INCLUDE=./
    
    all: clean process_first process_second init
    
    process_first:
        gcc -g -o process1  -I$(LOCAL_INCLUDE) process1.c  -lzmq  -L. -L./.
        gcc -g -o process2  -I$(LOCAL_INCLUDE) process2.c  -lzmq  -L. -L./.
    
    process_second:
        gcc -g -o process3  -I$(LOCAL_INCLUDE) process3.c  -lzmq  -L. -L./.
        gcc -g -o process4  -I$(LOCAL_INCLUDE) process4.c  -lzmq  -L. -L./.
    
    init:
        gcc -g -o initiate -I$(LOCAL_INCLUDE) initiate.c -lzmq -lconfig -lpthread -L. -L./. -ldl -lrt
    
    clean:
        rm -rf init_manager.o init_manager
        rm -rf process1 process2 process3 process4
    

    NOTE: It is a good practice to clean and touch all the executable files before making them again.

提交回复
热议问题