大家好,上次給大家分享了第一篇 cmake 文章:cmake學(xué)習(xí)總結(jié)(一),今天繼續(xù)給大家分享cmake。那么廢話就不多說,開始內(nèi)容分享。
用好 Cmake,高興一整天(甚至……):
1、多個(gè)源文件,使用命令 aux_source_directory(dir var):
在上一篇文章最后結(jié)尾的時(shí)候,有一個(gè)問題,就是在同一目錄下面,有多個(gè)源文件的時(shí)候,這個(gè)時(shí)候你不能都往下面第三條命令里面一直手動(dòng)添加源文件,那工作效率多低?。?/p>
cmake_minimum_required(VERSION 2.8)
project(main)
add_executable(main main.c test1.c)
于是乎為了解決這種低效率的操作,在 cmake 里面有一條指令可以完全搞定這個(gè)問題;不過為了說明問題,在這之前我又添加了兩個(gè)文件:test2.c 和 test2.h:
root@txp-virtual-machine:/home/txp/test# ls
1 cmake_install.cmake main.c test1.h touch1.c
CMakeCache.txt CMakeLists.txt Makefile test2.c touch1.h
CMakeFiles main test1.c test2.h
test2.c內(nèi)容如下:
#include <stdio.h>
#include "test2.h"
void func1()
{
printf("i like the cmake");
}
test2.h內(nèi)容如下:
#ifndef _TEST2_H_
#define _TEST2_H_
void func1();
#endif
最后main.c里面調(diào)用了func1函數(shù):
#include <stdio.h>
#include "test1.h"
#include "test2.h"
int main(void)
{
func1();
func(8);
printf("TXP嵌入式");
return 0;
}
接下來(lái)我們的重點(diǎn)就來(lái)了,在cmake里面可以使用aux_source_directory(dir var)就可以搞定上面效率低的問題,接下來(lái)我們?cè)贑MakeLists.txt這樣操作:
cmake_minimum_required(VERSION 2.8)
project(main)
aux_source_directory(. SRC_LIST)
add_executable(main ${SRC_LIST})
然后再進(jìn)行編譯:
root@txp-virtual-machine:/home/txp/test# cmake .
-- Configuring done
-- Generating done
-- Build files have been written to: /home/txp/test
root@txp-virtual-machine:/home/txp/test# make
Scanning dependencies of target main
[ 25%] Building C object CMakeFiles/main.dir/main.c.o
[ 50%] Linking C executable main
root@txp-virtual-machine:/home/txp/test# ./main
i like the cmake
the b is 8
TXP嵌入式
-
函數(shù)
+關(guān)注
關(guān)注
3文章
4379瀏覽量
64810 -
編譯
+關(guān)注
關(guān)注
0文章
679瀏覽量
33967
發(fā)布評(píng)論請(qǐng)先 登錄
相關(guān)協(xié)議信號(hào)總結(jié)
基于LockAI視覺識(shí)別模塊:C++二維碼識(shí)別
永磁同步電機(jī)二階迭代學(xué)習(xí)控制
使用STM32CubeMX生成CMake工程中的FLASH.ld被更改怎么解決?
在CubeMX V6.13.0版本上配置的CMake工程無(wú)法通過編譯怎么解決?
為什么無(wú)法在OpenVINO? 2021.3源中使用CMAKE編譯ONNX模型?
TOF學(xué)習(xí)總結(jié)
如何優(yōu)化BP神經(jīng)網(wǎng)絡(luò)的學(xué)習(xí)率
關(guān)于中斷知識(shí)學(xué)習(xí)總結(jié)筆記
一種基于深度學(xué)習(xí)的二維拉曼光譜算法

GPU深度學(xué)習(xí)應(yīng)用案例
《AI for Science:人工智能驅(qū)動(dòng)科學(xué)創(chuàng)新》第二章AI for Science的技術(shù)支撐學(xué)習(xí)心得
國(guó)產(chǎn)芯上運(yùn)行TinyMaxi輕量級(jí)的神經(jīng)網(wǎng)絡(luò)推理庫(kù)-米爾基于芯馳D9國(guó)產(chǎn)商顯板
《圖說本源產(chǎn)品》系列之二:量子計(jì)算全物理體系學(xué)習(xí)機(jī)

評(píng)論