zoukankan      html  css  js  c++  java
  • Modern C++ Course [Lecture 3] {CMake, Google Test, Namespaces, Classes}

     workflow of cmake:

    edit CMakeLists.txt in the root directory of the project:

    create an empty build folder, and cmake inside it. ".." means the root direction, which should include a "CMakeLists.txt.

     

     run cmake and recive a large bunch of information.  (not showed here)

     check the Makefile, although it's dummy. (have no meaningful code under ../src/ now)

     add two more lines in CMakeLists.txt

    let's make CMake happy

    edit our main func in src

     main.cpp:

     edit the CMake file in the same folder

     build again

     (a combo of "cmake" and "make" under build folder)

     execuate this binary file:

    here, under build folder, a src folder will mimic the structure of the src under root

    add a header file  "hello.h"

    declare and define at the same time now.

     line 3, "./" in "./xxx.h" means only search for this file in this folder. Not a proper way, but will remove the error sign.

     

    cd ../build/

    cmake

    make

    ./src/bin_main

    => Hello function

    since we didn't divide the header file into header and definition, we don't need to modify the makefile, but program can be inefficient, because the compiler will compile the header file again and again.

    cmake doesnt know the header files now, apart from where to search for them.

    angular bracket means will search all the system path, rather than the path of main.cpp

    => get error :

    the topmost cmake:

    => successful building now!

    create a hello.cpp

    delete redundant definition in hello.h

     

    modify the cmake file under root/src 

    make again 

     => Hello function

    create two new files in src

     

      (main func)

     (cmake under src)

     => Hello function

          Blah

    What about dynamic library?

    (add SHARED)

    static library: .a file 

    dynamic library: .so file (cpp and h file can be everywhere in system, and the only way to use it is to first search for it) 

     

      

      

     

     

     

     

     

     

     

     

     

     

     

  • 相关阅读:
    第六章:体系结构篇
    Linux查看显示编辑文本文件
    第五章:管理数据库实例
    yum [Errno 256] No more mirrors to try 解决方法
    第四章:Oracle12c 数据库在linux环境安装
    第三章:数据库管理的任务
    13 款免费但好用到哭的项目管理工具
    在CentOS 7上部署Ghost博客
    CentOS7上部署taiga项目管理软件
    CentOS6配置Taiga
  • 原文地址:https://www.cnblogs.com/ecoflex/p/10184610.html
Copyright © 2011-2022 走看看