cmake指令簡單講解,以及給出示例檔案

2021-09-22 14:06:17 字數 2942 閱讀 9969

cmake_current_source_dir 指向cmakelists.txt所在的目錄

cmake_build_type 「debug」 /「release」 一般指定這兩種形式

這個變數值為debug的時候,cmake會使用變數cmake_flags_debug 和 cmake_c_flags_debug中的字串作為編譯選項生成makefile,

當這個變數值為release的時候,工程會使用變數cmake_cxx_flags_release和cmake_cflags_release選項生成makefil

cmake_cxx_flags 指定c++編譯器

cmake_install_prefix定義安裝路徑

示例:cmake -d

add_subdirectory 將指定的資料夾新增到build任務列表中

find_package 在指定路徑下尋找包

add_executable 使用給定的原始檔,為工程生成乙個可執行檔案

target_link_libraries 將目標檔案與庫檔案進行鏈結(簡單來說,自己寫的檔案和系統庫檔案進行鏈結)

add_library(libname shared $) 新增名為libname動態鏈結庫(shared因此是動態鏈結庫,執行時被載入)

install(targets library destination $/install/)

library動態庫,archive靜態庫 destination指定安裝後的路徑

指令:set(src main.cpp eval.cpp datareader.cpp) 用src代替後面的檔案main.cpp eval.cpp datareader.cpp

example:

原始檔: hello.c

標頭檔案: hello.h

so檔案:libhello.so

安裝位置: /hello/install/

源檔案目錄:/home/hello/libhello/hello.c

/home/hello/libhello/hello.h

編譯生成的中間檔案 /home/hello/build/

hello.c

#include

#inclide"hello.h"

void hello()

hello.h

#ifndef hello_h

#define hello_h

#include

void hello;

#endif

使用cmake編譯和安裝

在/home/hello/資料夾下新建cmakelists.txt,新增如下內容:

cmake_minimum_required(version 2.6)

add_library(hello shared $/libhello/hello.c) 只依賴.c檔案,而不需要.**件,感覺比較奇怪

project_source_dir是cmakelists.txt檔案所在的絕對路徑

install(targets hello library destination lib)

給乙個完整的示例檔案:**於專案工程檔案,完全可以編譯通過

cmake_minimum_required(version 2.8)

project(demo)

set(cmake_build_type release)

set(cmake_cxx_flags 「$ -fpic -std=c++11 -wall -ofast -wfatal-errors」)ma

kecu

rren

tsou

rced

ir/t

enso

rrtw

rapp

er/c

ode)

adds

ubdi

rect

ory(

cmakec

​urr

ents

​our

ced​

ir/t

enso

rrtw

rapp

er/c

ode)

adds

​ubd

irec

tory

(include_directories($/include)

#add opencv

find_package(opencv required)

include_directories(ope

ncvi

nclu

dedi

rs)l

inkd

irec

tori

es

() link_directories(

opencv

i​nc

lude

d​ir

s)li

nkd​

irec

tori

es()

#build runyolov3

add_executable(runyolov3 main.cpp eval.cpp datareader.cpp)

target_link_libraries(runyolov3 trtnet $)

#generate so file

set($)

set(src main.cpp eval.cpp datareader.cpp)

add_library(libyolov3 shared $)

install(files library destination $)

#generate exe file

install(targets runyolov3 destination $/install/)

so庫呼叫方法: 使用python介面進行呼叫

coordinations = libyolov3.main.yolov3(file_name)

TCP UDP以及HTTP的簡單講解

先來乙個講tcp udp和http關係的 1 tcp ip是個協議組,可分為三個層次 網路層 傳輸層和應用層。在網路層有ip協議 icmp協議 arp協議 rarp協議和bootp協議。在傳輸層中有tcp協議與udp協議。在應用層有ftp http telnet smtp dns等協議。因此,htt...

TCP UDP以及HTTP的簡單講解

先來乙個講tcp udp和http關係的 1 tcp ip是個協議組,可分為三個層次 網路層 傳輸層和應用層。在網路層有ip協議 icmp協議 arp協議 rarp協議和bootp協議。在傳輸層中有tcp協議與udp協議。在應用層有ftp http telnet smtp dns等協議。因此,htt...

TCP UDP以及HTTP的簡單講解

先來乙個講tcp udp和http關係的 1 tcp ip是個協議組,可分為三個層次 網路層 傳輸層和應用層。在網路層有ip協議 icmp協議 arp協議 rarp協議和bootp協議。在傳輸層中有tcp協議與udp協議。在應用層有ftp http telnet smtp dns等協議。因此,htt...