开发者

How to create a makefile without having to include every single source file in the project?

开发者 https://www.devze.com 2023-01-23 05:41 出处:网络
I\'m taking some C++ classes and开发者_JS百科 have send the teacher 9 exercises, each exercise is a simple directory with the name \'ex$\' where $ is the number. Each directory has a single source fil

I'm taking some C++ classes and开发者_JS百科 have send the teacher 9 exercises, each exercise is a simple directory with the name 'ex$' where $ is the number. Each directory has a single source file named 'ex$.cpp. I want to create a makefile that will allow me to type:

make ex$

And it will build a executable that corresponds to the compiled source file inside 'ex$' directory. The catch is that I want to do that without creating a target for each exercise(Some kind of 'generic target'). I also need to have an 'all' target that will go into each directory starting with 'ex' and build the executable there. How can I do that?


If all your C++ targets can be built with essentially the same command, you can do this fairly easily. Read this. Look for $@, in particular. Since this is part of an education, I'll leave the rest vague.


Can I also suggest looking at CMake which will make better makefiles for you to use IMO. Initial high learning curve for major long term gain. :)

0

精彩评论

暂无评论...
验证码 换一张
取 消