初次用makefile
总体过程是在libtest文件在建立include src lib
libtest/include/hello.h下
#ifndef _HELLO_H_
#define _HELLO_H_
void hello();
#endif
libtest/lib/hello.c
#include "hello.h"
#include<stdio.h>
void hello()
{
printf("hello world!\n");
}
libtest/src/main.c
#include "hello.h"
int main()
{
hello();
}
lib文件下makefile生成libhello.a libhello.so都是成功的
但是在src下makefile有错误
lxq@ubuntu:~/libtest/src$ make
make -C ../lib
make[1]: Entering directory `/home/lxq/libtest/lib'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/home/lxq/libtest/lib'
src下makefile编写如下:
STATIC_FLAGS=-L ../lib -lhello -static -I ../include
DYNAMIC_FLAGS=-L ../lib -lhello -I ../include
STATIC_MAIN=main_static
DYNAMIC_MAIN=main_dync
.PHONY:submake clean
all:submake $(STATIC_MAIN) $(DYNAMIC_MAIN)
submake:
$(MAKE) -C ../lib
$(STATIC_MAIN):main.c
gcc $< $(STATIC_FLAGS) -o $@
$(DYNAMIC_MAIN):main.c
gcc $< $(DYNAMIC_FLAGS) -o $@
clean:
rm -rf *.o $(STATIC_MAIN) $(DYNAMIC_MAIN)