当前位置:网站首页>Cmake Learning Series I
Cmake Learning Series I
2022-06-13 08:55:00 【Human high quality Algorithm Engineer】
lately , Encountered a very serious problem , The output of the model is not aligned , The output of the compiled model is different from that of colleagues , It's the same model , The same picture , What's the problem , It turns out that I always make install, Didn't put build Delete , Colleagues explain changes to model files ,make install Yes, there is bug Of , Each time the code changes will be scanned and compiled , There is no reading into the model , So it has always been the result of the previous model , this … Looking for mistakes all morning , Is this , hold build Delete it and rearrange it .. in the final analysis , I am right cmake Not familiar …
I hope this series will have a bright future 234
Let's get to the point
One . What is? cmake
You may have heard of several Make Tools ( Actually, I haven't heard of ), for example GNU Make ,QT Of qmake , Microsoft MS nmake,BSD Make(pmake),Makepp, wait . these Make Tools follow different norms and standards , Executed Makefile The format is also very different . This brings up a serious problem : If software wants to cross platform , You have to be able to compile on different platforms . And if you use the above Make Tools , You have to write for each standard once Makefile , It's going to be a crazy job .
CMake It is a tool designed to solve the above problems : It starts with Allow developers to write a platform independent CMakeList.txt File to customize the entire compilation process , Then further generate the required localization according to the target user's platform Makefile And engineering documents , Such as Unix Of Makefile or Windows Of Visual Studio engineering . So that “Write once, run everywhere”. obviously ,CMake It's more than the above make More advanced compilation configuration tool . Some uses CMake Well known open source projects as project architecture systems are VTK、ITK、KDE、OpenCV、OSG etc. [1].
stay linux Use under platform CMake Generate Makefile And the process of compiling is as follows :
- To write CMake The configuration file CMakeLists.txt
- Carry out orders cmake PATH perhaps ccmake PATH Generate Makefile(ccmake and cmake The difference is that the former provides an interactive interface ), among PATH yes CMakeLists.txt directory
- Use make Command to compile
example
Calculate the exponential power of a number
#include <stdio.h>
#include <stdlib.h>
/** * power - Calculate the power of number. * @param base: Base value. * @param exponent: Exponent value. * * @return base raised to the power exponent. */
double power(double base, int exponent)
{
int result = base;
int i;
if (exponent == 0) {
return 1;
}
for (i = 1; i < exponent; ++i) {
result = result * base;
}
return result;
}
int main(int argc, char *argv[])
{
if (argc < 3) {
printf("Usage: %s base exponent \n", argv[0]);
return 1;
}
double base = atof(argv[1]);
int exponent = atoi(argv[2]);
double result = power(base, exponent);
printf("%g ^ %d is %g\n", base, exponent, result);
system("pause");
return 0;
}
To write CMakeLists.txt, Keep in touch with main.cpp Source files in the same directory
# Project information
project(zz0225)
# Specify the build target
add_executable(Demo main.cpp)
add_executable: take main.cpp The source file is compiled into a file named Demo.exe The executable of
Build a new one under the project build Catalog
cmake After compilation , The executable file is obtained
Right click the property page of the project , Change the working directory to OutDir, In this way, a pile of junk generated by software will be in build In the folder
Enter into exe directory , Just run directly
边栏推荐
- 【安全】零基础如何从0到1逆袭成为安全工程师
- turf. JS usage
- JS string method
- An error CV2 is reported when the picture is converted to grayscale cvtColor(img, cv2.COLOR_BGR2GRAY)
- 1. Learning sequence of SolidWorks modules
- [network security penetration] if you don't understand CSRF? This article gives you a thorough grasp
- Calculation method of paging
- JS format file unit display
- 2、 Three ways to write JS code
- Knowledge points related to system architecture 2
猜你喜欢
WARNING:tornado. access:404 GET /favicon. ICO (172.16.8.1) 1.84ms [with static file settings]
【 sécurité 】 comment devenir ingénieur de sécurité de 0 à 1 contre - attaque pour la Fondation zéro
Container concept and cloud native
[network security penetration] if you don't understand CSRF? This article gives you a thorough grasp
Invalid flex layout setting width
0.一些自己初学Solidworks的疑惑
容器概念和云原生
useRoutes() may be used only in the context of a <Router> component.
JS array using the reduce() method
Centering problem - the width and height of child elements are known
随机推荐
Tensorflow1.14 corresponds to numpy version
8、 JS data type conversion
Brief description of port, domain communication port and domain service
Loss outputs Nan for the Nan model
JS array using the reduce() method
Invalid flex layout setting width
Paging query template of Oracle
An error CV2 is reported when the picture is converted to grayscale cvtColor(img, cv2.COLOR_BGR2GRAY)
pytorch统计模型的参数个数
\Difference between N and \r
How to save the video of wechat video number locally?
Object array de encapsulation
How to resolve "the operation cannot be completed successfully because the file contains viruses or potentially junk software
Gbase 8A disk problems and Solutions
Uni app subcontracting loading and optimization
Animation through svg
银行理财产品有哪些?清算期是多长?
Docker installing MySQL local remote connection docker container MySQL
Installing pytorch under Anaconda
VI editor