美文网首页
makefile & CMake 简明模板

makefile & CMake 简明模板

作者: 4c6ed2800025 | 来源:发表于2020-04-10 18:10 被阅读0次

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)

相关文章

  • makefile & CMake 简明模板

    makefile cmake

  • C程序生成工具

    (1)makefile常用模板:(2)automake和autoconf (3)cmake

  • CMake语法-自动编译和链接

    makefile、cmake和shell之间的联系 makefile:帮组我们管理编译项目 CMake是一个跨平台...

  • 编译:CMAKE

    CMAKE 0、CMake CMake中,我们先输入cmake 命令对工程进行分析,生成makefile文件; 然...

  • cmake

    CMake 什么是CMake 构建工具,Cmake 读取CMakeLists.txt 生成 makefile编译多...

  • cmake用法

    示例源码在 linux 平台下使用 CMake 生成 Makefile 并编译的流程如下: 编写 CMake 配置...

  • CMKAE总结

    CMKAE总结 cmake:生成一个makefile文件。make:根据这个makefile文件的内容编译整个工程...

  • CMake使用

    CMake简介 CMake是一个跨平台的、开源的构建工具。cmake是makefile的上层工具,它们的目的正是为...

  • xmake自动构建工具

    一 前言 autotool简化了Makefile的构建难度,让我们方便的生成复杂项目的Makefile;CMake...

  • cmake

    cmake解决了软件跨平台需要重复编写makefile的问题 在 linux 平台下使用 CMake 生成 Mak...

网友评论

      本文标题:makefile & CMake 简明模板

      本文链接:https://www.haomeiwen.com/subject/kibrmhtx.html