c - create makefile for static library and executable simultaniously -
i have 3 files should included in static library (file1.c,file2.c,file3.c) , 1 file should include main function (main.c file) , linked static library.
i create 1 makefile create library , create executable.
my base makefile is:
cc=gcc cflags=-c -wall ldflags= sources=file1.c file2.c file3.c objects=$(sources:.c=.o) out=libctest.a executable=hello ldflags = -static .c.o: $(cc) $(cflags) -c $< -o $@ $(out): $(objects) ar rcs $(out) $(objects) all: (cc) -o $(executable) main.c $(out) clean: rm -f $(objects) $(out)
the library created executable doesn't created (all: (cc) -o $(executable) main.c $(out)) idea needed?
make default process first target in makefile
. in case .c.o
target. make all
default target move top. many people prefer style all
won't rather depend on others. along lines:
all: $(executable) $(out): $(objects) ar rcs $(out) $(objects) $(executable): main.c $(out) (cc) -o $(executable) main.c $(out)
Comments
Post a Comment