TransWikia.com

What is Cmake file and why do we use it when we have VIsual studio

Stack Overflow Asked by Hillary on December 27, 2021

Sorry for asking such basic question. Being a beginner in C++, I’m puzzled about a lot of things:

  1. if we have Visual stuido and other IDEs, as well as Cygwin as compilers, what kind of roles do CMake play in helping a C++ programmer to develop programmes? Can we just write C++ programmes without using C Make?

  2. I understand header files are like prototypes of functions that will be used in C++ files, or declarations of them, so I assume all header files should be accompanied by actual library files in the form of C++ files, as that’s where the functions know what to do when being called. However,this is not usally the case, as there are header only libraries such as PyBind11.

  3. What is bash? is it like another Windows command prompt? Whats its relationship wth C++?

  4. Why do we have function macros and what is its advantages over normal functions?

Thank you very much!

3 Answers

what kind of roles do CMake play in helping a C++ programmer to develop programmes?

Can we just write C++ programmes without using C Make?

Yes. It is possible to write C++ programs without any tools. It is possible to even compile C++ without any build system.

However, building complex C++ programs without a build system is difficult and tedious. Build systems help to keep the complexity under control.

But using a platform specific build system hinders compilation on systems that don't have that specific build system.

CMake solves this dilemma by being able to generate builds for several build systems on various platforms. So CMake is a generator for build systems.

so I assume all header files should be accompanied by actual library files in the form of C++ files

Your assumption is not quite correct. It is a decent rule of thumb that applies often, but not always.

What is bash?

bash is a shell. It is the most commonly used shell on POSIX systems. On windows, bash can be used through WSL or Cygwin.

is it like another Windows command prompt?

Windows command prompt is another shell. It is used only on windows.

Whats its relationship wth C++?

There is no close relationship between bash and C++.

Bash is often used to write shell scripts. Such shell scripts are sometimes used to help with building complex C++ programs.

Why do we have function macros

For text replacement within the source code.

what is its advantages over normal functions?

Functions cannot replace text in source code.

Use cases for macros (functional or otherwise) are rare. They are sometimes overused, which is not a good thing. Generally, functions have many advantages over macros. Among the advantages of functions are type safety and scoped names.

Answered by eerorika on December 27, 2021

CMake is a kind of a build system. Build systems help to organize all files in the project, handle proper order of compilation, linking, and other steps that are necessary to obtain a binary (executable or library). They allow describing the process of building in an abstract way, reducing dependencies between project and other build tools, e.g. you can easily change the compiler.

CMake is a special flavor of the build systems because it doesn't handle building by itself. It generates scripts of other build systems, e.g. Makefiles on Linux. That allows for a multiplatform approach to building applications.

Considering Your questions about macros and headers, I would suggest a good C++ book

Bash is a system shell with its own scripting language, allowing for running system scripts. It is mostly used on Linux based systems, however it can be used also on windows.

Answered by b00rt00s on December 27, 2021

CMake is a buildsystem.

if we have Visual stuido and other IDEs, as well as Cygwin as compilers, what kind of roles do CMake play in helping a C++ programmer to develop programmes? Can we just write C++ programmes without using C Make?

CMake allows for crossplatform development. It allows you to create projectfiles/Makefiles/... from a CMakeLists.txt file ==> The file suitable for the platform is created. If you use CMake, you can simply program on windows (CMake will generate Visual Studio Solution Files) and if somebody tries to compile it on linux, CMake will generate Makefiles. Using CMake, you only have one buildsystem and don't have to write buildfiles for every platform you support

I understand header files are like prototypes of functions that will be used in C++ files, or declarations of them, so I assume all header files should be accompanied by actual library files in the form of C++ files, as that's where the functions know what to do when being called. However,this is not usally the case, as there are header only libraries such as PyBind11.

I don't understand the question, but a header-only library hasn't to be linked to your program, as all the source code is in the headers.

What is bash? is it like another Windows command prompt? Whats its relationship wth C++?

bash is a shell, that executes commands. It's like the command prompt, only sometimes a bit better. It has no relationship to C++.

Why do we have function macros and what is its advantages over normal functions?

Macros have rarely advantages over functions, because the clutter the code, increase the compilation times (Because the preprocessor inserts a copy of the macro everytime, it is applied==>More code, slower compilation). The only advantage I can think of, is in a situation like this for conditional compilation:

#ifdef DEBUG
#define LOG(x) printf(x)
#else
#define LOG(x)
#endif

Answered by JCWasmx86 on December 27, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP