makefile
CC = gcc
INCLUDES = -I/usr/local/include -Ia -Ib -Ic -I($(HOME)/include
LIBINCLUDES = -L/usr/local/lib -Lbuild/lib -L $(HOME)/lib
INC = $(INCLUDES) $(LIBINCLUDES)
CFLAGS= -O2 -fPIC
OBJS = a.o b.o c.o
LIBS = -lm -lthread -lgtk2
prog: prog main.o
$(CC) $(CFLAGS) $(INC) main.o $(OBJS) $(LIBS)
main.o: main.c $(OBJS)
$(CC) $(CFLAGS) $(INC) -c main.c
a.o: a/a.c
cd a
$(CC) $(CFLAGS) $(INC) -c a.c
b.o: b/b.c
cd b
$(CC) $(CFLAGS) $(INC) -c b.c
c.o: c/c.c
cd c
$(CC) $(CFLAGS) $(INC) -c c.c
clean:
rm -f *.o *~ prog
cd a
rm -f *.o *~
cd b
rm -f *.o *~
cd c
rm -f *.o *~
cmake
cmake_minimum_required(VERSION 2.8.9)
project (demo)
# 头文件
#Bring the headers, such as Student.h into the project
include_directories(include)
# 源文件
#However, the file(GLOB...) allows for wildcard additions:
file(GLOB SOURCES "*.c")
# 使用静态库.a/共享库.so
#For the shared library:
#set ( PROJECT_LINK_LIBS libtestStudent.so )
#link_directories( ~/exploringBB/extras/cmake/studentlib_shared/build )
#For the static library:
#set ( PROJECT_LINK_LIBS libtestStudent.a )
#link_directories( ~/exploringBB/extras/cmake/studentlib_static/build )
include_directories(~/exploringBB/extras/cmake/studentlib_shared/include)
# 构建可执行文件
add_executable(main ${SOURCES})
# 构建共享库.so
#Generate the shared library from the sources
#add_library(testStudent SHARED ${SOURCES})
#Set the location for library installation -- i.e., /usr/lib in this case
# not really necessary in this example. Use "sudo make install" to apply
#install(TARGETS testStudent DESTINATION /usr/lib)