Difference between Cmake, gnu make and manually compiling

后端 未结 2 1673
渐次进展
渐次进展 2021-01-30 17:08

I\'m new to programming so this is a more of a abstract question than a technical one. I\'ve been using IDE\'s to learn but I heard they tend to oversimplify the act of compilin

2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-30 17:35

    When compiling a large project with lots of files you can get lost if you call the compiler directly.

    Of course you can put the related commands in a script and run it, but then you need to update the script if you add/remove a file. Also in that case you might want not to recompile everything every time you make a small change, so you want to only compile the parts that were changed. If you add this (and other quality of life) functionality in your hyphotetical script you are going to reinvent make.

    make is designed to run only the compilation of the parts of your code that were changed till your last call to make. It also allows you to automate adding sourcefiles and etc.

    However if you want your code to work with several different compilers, and on several different platforms, and to link to different libraries, and so on, things get a little complicated for make. You can still do it, but it is a lot of work. This is where cmake comes.

    cmake builds makefiles (or similar build systems, example: Visual Studio) for the system you want. cmake has prebuilt profiles for different compilers and systems that will automatically find the right set of compiler flags, find an link to the correct libraries and so on.

    Of course if you are writing a "Hello World!" or similar program you don't need neither make nor cmake. If you don't need to support multiple compilers/platforms you don't need cmake. If you are working on some huge library/application though make and cmake will help you do things easier.

提交回复
热议问题