Makefile

makefile 的好处

Makefile 带来的好处就是——“自动化编译”,一旦写好,只需要一个make 命令,整个工程完全自动编译,极大的提高了软件开发的效率。make 是一个命令工具,是一个解释 Makefile 中指令的命令工具。

Makefile 关系到了整个工程的编译规则。一个工程中的源文件不计其数,并且按类型、功能、模块分别放在若干个目录中,makefile 定义了一系列的规则来指定,哪些文件需要先编译,哪些文件需要后编译,哪些文件需要重新编译,甚至于进行更复杂的功能操作,因为 Makefile 就像一个Shell 脚本一样,其中也可以执行操作系统的命令。

rules

源文件首先会生成中间目标文件,再由中间目标文件生成执行文件

# work pipline
# 写代码-> *.cpp -> 编译 -> *.o -> 链接 -> *.a / *.so

# Makefile rules
target ... : prerequisites ...
    command
    ...
    ...

exmaple

about cc

  • cc是unix下面用的编译命令;
  • gcc是linux下面用的编译命令;

很多makefile文件是在Unix下面写的,编译用的是 cc,但是现在很多人喜欢用linux来编译,总不能把makefile文件中所有的cc改成gcc吧,多麻烦啊!

最后某个大神想到了用连接的方法把cc连接的gcc命令上,运行cc就是运行gcc。

resource

  1. Github how to write makefile

Cmake

CMake is an open-source, cross-platform family of tools designed to build, test and package software. CMake is used to control the software compilation process using simple platform and compiler independent configuration files, and generate native makefiles and workspaces that can be used in the compiler environment of your choice. The suite of CMake tools were created by Kitware in response to the need for a powerful, cross-platform build environment for open-source projects such as ITK and VTK.

installation

rules

example

resource

Pybind11

pybind11 is a lightweight header-only library that exposes C++ types in Python and vice versa, mainly to create Python bindings of existing C++ code. Its goals and syntax are similar to the excellent Boost.Python library by David Abrahams: to minimize boilerplate code in traditional extension modules by inferring type information using compile-time introspection.

installation

examples

resource

  1. pybind11 doc