The next two lines talk about C++ Application Binary Interface (ABI).The first line is self-explanatory: it is saying that CMake idenfities the C++ compiler be GNU gcc 7.5.0.Build files have been written to: /home/jingnanshi/code/VNAV2023/example-project/build Check for working CXX compiler: /usr/bin/c++ - skipped The CXX compiler identification is GNU 7.5.0 In main.cpp, put down the following text: While this is less important for an executable, for libraries that depend on other libraries it is important to use PRIVATE so that downstream users are not burdened with unnecessary libraries. The PRIVATE keyword means that this linking is not transitive: mylib is not exposed to other binaries that link against main. We then link main with our library mylib. We then create our executable main, which consists of the file main.cpp. We first create a library called mylib, which consists of the files my_lib.cpp and my_lib.hpp. The next three lines define the actual library and executable. This is something that you should define yourselves based on your projects. The arguments say that our project is named hello_world, is versioned at 1.0, and is in C++. By default, the CMake version installed on Ubuntu 20.04 is 3.16. If your installed CMake has version lower than 3.10, then CMake will generate an error and abort the build process. This statement enforces that the minimum version required for CMake to generate build files for this project is 3.10. Target_link_libraries(main PRIVATE mylib)įirst, we have cmake_minimum_required(VERSION 3.10). Create a new folder, with the following files in it: Let’s try creating our first CMake project to see how CMake works. We then call CMake to generate makefiles, which are then used to compile and generate libraries and executables. With CMake, we write CMakeLists.txt files to inform it where to find source code and header files. Users of such systems usually need to write some configurations files, from which the build environments will then generate native makefiles for compilation.ĬMake is one of such systems. Luckily, we have these so called build systems that give developers a nearly unified interface across different platforms. And each of those compilers might have different options and settings that we need to account for. In addition, since C++ does not have a centralized distribution of an official compiler, for different platforms we might need to use different compilers. However, for large-scale C++ software codebase, we need a better and more automatic tool to compile, organize and install all the required files and binaries. For small-scale projects, this is sufficient. So far we have used command line commands to directly compile programs.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |