Linux:从给定的源文件自动创建 C++ makefile

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19069444/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-07 00:57:07  来源:igfitidea点击:

Linux: Create automatically C++ makefile from given source files

c++linuxmakefile

提问by Anonymous

I have a project structure like that:

我有一个这样的项目结构:

src/main.cpp
src/Folder/this.cpp
src/Folder/that.cpp
src/NewFolder/foo.cp
// etc.

In addition I need some libs so that I can link, e.g. lboost_system. How can I simply create a makefile with these given information? I read all the time about creating a makefile manually, CMake and so on but this is in my opinion way to complicated! Isn't there any tool where I can specify the following information:

另外我需要一些库以便我可以链接,例如lboost_system。如何使用这些给定的信息简单地创建一个 makefile?我一直在阅读有关手动创建 makefile、CMake 等的信息,但我认为这很复杂!没有任何工具可以指定以下信息:

Source folder: /home/bla/src/
Additional Libs: lboost_system
Compiler Flags: -std=c++0x (or whatever)

And a makefile is generated?! Is it really that hard?

并生成了一个makefile?!真的有那么难吗?

回答by Mariusz Lotko

You can write a Makefile in a generic way - that is you won't have to specify each source file one by one. Have a look at http://www.puxan.com/Computers/Howto-write-generic-Makefiles, I did it quite a long time ago, so I don't remember details, but in the end adding *.cpp files does not (usually) require a Makefile change.

您可以以通用方式编写 Makefile - 也就是说,您不必一一指定每个源文件。看看http://www.puxan.com/Computers/Howto-write-generic-Makefiles,我很久以前做过,所以我不记得细节了,但最后添加了 *.cpp 文件不需要(通常)需要更改 Makefile。

You can also have a look at automake (http://www.gnu.org/software/automake/manual/automake.html) which is some step ahead to bare cmake. It standardizes make goals and looks like make your life easier if you want to distribute your software as source files.

您还可以查看 automake ( http://www.gnu.org/software/automake/manual/automake.html),它比裸 cmake 领先了一步。如果您想将软件作为源文件分发,它标准化了制定目标并且看起来让您的生活更轻松。