91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

實例分享cmake編譯一個簡單c++項目(demo)

發布時間:2020-09-19 21:08:04 來源:腳本之家 閱讀:231 作者:mdxy-dxy 欄目:編程語言

下面通過一個小例子來說明cmake編譯一個c++項目,生成可執行文件:

整理目錄結構:

CMake Lists.txt addlib build main.cpp

電腦上沒有tree命令,也不大敢截圖,將就著看看,其中build是cmake編譯指定的路徑,addlib下面也有一個頭文件和源文件  ,還有一個CmakeLists.txt,可以看下:

CMake Lists.txt library.cpp library.h

先看各個文件的代碼:

addlib/library.h:

#ifndef CPPPROJECT_LIBRARY_H
#define CPPPROJECT_LIBRARY_H
 
int acc_add(int);
 
#endif

addlib/library.cpp:

#include "library.h"
#include <iostream>
 
void hello(){
  std::cout<<"hello world"<<std::endl;
}
 
 
int acc_add(int n){
  int sum=0;
  for(int i=0;i<n;i++){
    sum+=i;
  }
  return sum;
}

addlib/CMakeLists.txt:

cmake_minimum_required(VERSION 3.10)
project(accliblibrary)
 
set(CMAKE_CXX_STANDARD 11)
 
add_library(accliblibrary SHARED library.cpp library.h) # 訴生成一個庫文件。

main.cpp:

#include <iostream>
#include <string>
#include "addlib/library.h"
using namespace std;
int main(){
 int n=10;
 int ans=acc_add(n);
 cout<<"1+....+"<<n<<"="<<ans<<endl;
  return 0;
}

CMakeLists.txt:

cmake_minimum_required(VERSION 3.10)
project(cppproject)
 
set(CMAKE_CXX_STANDARD 11)
 
add_subdirectory(acclib)
 
 
add_executable(cppproject main.cpp) #生成一個可執行的文件
 
target_link_libraries(cppproject accliblibrary)

下面就是編譯該項目,生成可執行文件:

cd build/

cmake ..

-- The C compiler identification is AppleClang 8.0.0.8000042
-- The CXX compiler identification is AppleClang 8.0.0.8000042
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/zhoumeixu/Documents/cmakedemo/build

make:

Scanning dependencies of target addliblibrary
[ 25%] Building CXX object addlib/CMakeFiles/addliblibrary.dir/library.cpp.o
[ 50%] Linking CXX shared library libaddliblibrary.dylib
[ 50%] Built target addliblibrary
Scanning dependencies of target cmakedemo
[ 75%] Building CXX object CMakeFiles/cmakedemo.dir/main.cpp.o
[100%] Linking CXX executable cmakedemo
[100%] Built target cmakedemo

./cmakedemo

1+....+10=45

這篇文章就介紹下面,下面億速云小編將繼續為大家介紹

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

敦煌市| 建始县| 遂川县| 鱼台县| 乃东县| 夏邑县| 朔州市| 潼南县| 凌源市| 柞水县| 淮滨县| 北流市| 东光县| 襄城县| 策勒县| 西乌珠穆沁旗| 滦南县| 垦利县| 丘北县| 哈尔滨市| 那坡县| 于田县| 邳州市| 白山市| 依安县| 盐山县| 福海县| 渝中区| 平邑县| 宁武县| 红河县| 渑池县| 体育| 广元市| 抚远县| 石屏县| 方城县| 格尔木市| 新丰县| 佛坪县| 兴化市|