![]() ![]() There are many (relatively) new (meta) buildsystems around lately such as build2 or meson. Let's see how to use cmake in this case.Cmake,tutorial,C++,buildsystem Why CMake?Īt siliceum, we decided to use CMake for our C++ based projects. Sometimes you just need to compile dynamic and static libraries and wait for other programs to use them. compilation control of dynamic library and static library This command is /bin)Īt the same time, cmakelists in the src directory Txt delete. Cmake provides a command that can store all the source files in the specified directory in a variable. However, if there are 100 source files, it will be a bit of a pit to do so again, which can not reflect the advantages of cmake. Then execute cmake again, generate Makefile and run make,īy analogy, if there are multiple source files in the same directory, just add_ Just add all the source files in the executable. Modify cmakelists Txt, in add_ In the parameter of executable, put testfunc C add in cmake_minimum_required (VERSION 2.8) Call testfunc The function func() declared in H, #include TestFunc.h the contents are as follows:, /* TestFunc.c the contents are as follows:, /* ![]() After adding, the overall file structure is as follows:, Let's move on to a slightly more complicated example: there are multiple source files in the same directory.Īdd two files in the previous directory, testfunc C and testfunc h. PS: if you want to regenerate main, enter make clean to delete the elf file main. You can see that the elf file main we need has also been successfully generated, and then run main, You can see that the Makefile generated by executing cmake can display the progress with color. Then enter make under the terminal and press enter, You can see that the Makefile is successfully generated, and there are some files automatically generated by cmake runtime. Let's look at the files in the directory, The following information will be output, Switch to main under the terminal C, and then enter the following command to run cmake, The first line means that the minimum version requirement of cmake is 2.8, and we installed 3.10.2 The second line represents the project information, that is, the project name is demo The third line is more critical, indicating that the name of the elf file to be generated is main, and the source file used is main c Then in main C write cmakelists in the same directory Txt, as follows, cmake_minimum_required (VERSION 2.8) Then in main C write cmakelists in the same directory Txt, as follows, #include Two simple examplesįirst, let's start with the simplest code and experience how cmake operates. To install cmake, use the following command:,Īfter installation, enter cmake -version under the terminal to view the cmake version, This article mainly describes how to use CMake to compile our program under Linux. This configuration file is independent of the running platform and compiler, so there is no need to write Makefile in person, and the configuration file can be directly used on other platforms without modification, which is very convenient. ![]() CMake is an open source and cross platform construction tool, which allows us to generate local Makefile by writing a simple configuration file. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |