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

时间:2022-07-15 15:08:13

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:

另外,我需要一些libs,这样我就可以链接,例如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吗?真的那么难吗?

1 个解决方案

#1


5  

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- general - 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/automare/automal/manual/automake.html),它比bare cmake领先了一些。如果您希望将您的软件作为源文件分发,则可以标准化“制定目标”,并使您的生活变得更轻松。

#1


5  

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- general - 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/automare/automal/manual/automake.html),它比bare cmake领先了一些。如果您希望将您的软件作为源文件分发,则可以标准化“制定目标”,并使您的生活变得更轻松。