Тёмный

More Tips for Setting up a Programming Project: Subdirectories and Structure 

Jacob Sorber
Подписаться 165 тыс.
Просмотров 34 тыс.
50% 1

Опубликовано:

 

27 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 77   
@mshingote
@mshingote 3 года назад
Cool. Can you also make a video on cross platform build system. Cmake, premake etc?
@nagarajahuliyapuradamata3447
@nagarajahuliyapuradamata3447 3 года назад
+1
@lucasteixeira5346
@lucasteixeira5346 3 года назад
Amazing video. I just tried to reproduce these concepts in my own makefile and had a few problems, so maybe I can share some points that I figured out. From what I understood, the "variables" are, in fact, macros. This means that their values are substituted when called, so trailing white spaces can become a problem. For example, I wrote the following line: SRC = src # Source files directory This became a problem, because $(SRC)/file.cpp would become "src /file.cpp" (mind the space before the slash). Therefore, I had to change to: # Source files directory SRC=src Anyway, this is what I understood, hope it can help someone.
@ewrietz
@ewrietz 3 года назад
Awesome video, I’m just getting into make. Makefiles always looked like gibberish until I watched this series
@JacobSorber
@JacobSorber 3 года назад
Nice. That's what I'm going for. Glad I could help.
@wilfreddv
@wilfreddv 3 года назад
I jokingly said "eat the frog, make a script that sets up a project for you". I actually finished it :d
@papasmurf9146
@papasmurf9146 2 года назад
A good scripting exercise is to write a script that creates the Makefile. Between header dependencies (which is missing from the simple wildcard based Makefiles) and the difference between tabs and spaces, hand crafting/maintaining a Makefile gets old very quickly with a project of any size.
@abzrg
@abzrg 10 месяцев назад
thanks for videos on make! Could you go over these topics by any chance: - VPATH - implicit variables - automatic header dependency management - building external library as a prerequisite (for example googletest) and link against them
@hagen1555
@hagen1555 3 года назад
I'd like to see a quick video about library paths in make. I've tried these -I -L options, but it somehow still doesn't work :/
@neillunavat
@neillunavat 3 года назад
You sir are a saviour... I spent 19 hours trying to get my makefile to work with this project setup I have and then I saw you upload this video. Thank god. Also, I would like to know how to make the the Makefile to recompile if any custom header files change... Thanks
@m4xdev
@m4xdev 3 года назад
Adding/modifying like the following should do the trick: CFLAGS=-g -Wall -MD # "-MD" means Make Dependencies DEPS=$(patsubst $(SRC)/%.c, $(OBJ)/%.d, $(SRCS)) # "-MD" outputs makefile dependency files with .d extensions so lets generate a target list -include $(DEPS) # Run each dependency makefile but don't report an error if something fails("-")
@swarnavasamanta2628
@swarnavasamanta2628 3 года назад
Awesome video. Will you in the future make a video explaining directory structures for common open source projects ? Like those include, libs, and other dir that we see in open source projects in GitHub but have no idea how they are designed. Thank you.
@nagarajahuliyapuradamata3447
@nagarajahuliyapuradamata3447 3 года назад
1. I often use layered architecture while programming. Therefore, it makes sense for me to keep source files in different sub folders within $(SRC). How would you modify above Makefile to accommodate? 2. I often (CD/CI) incremental build/compile projects on different machines/devices (ex. Apple tablet or Samsung Tablet or Samsung mobiles, depending on which my family members are not using/left out device) using corresponding device specific Linux emulators. A structured $(BIN)/$(PLATFORM) arrangement in Makefile example would benefit hobby developers like me. Thanks!
@boxedowl
@boxedowl 3 года назад
Anything Make or C related I'm here for.
@suncrafterspielt9479
@suncrafterspielt9479 3 года назад
Hey i am interested in a detailed debug an release build video
@JacobSorber
@JacobSorber 3 года назад
I'll put it on the list and see what I can do. Thanks.
@bloom945
@bloom945 22 дня назад
!! at 7:49, be VERY careful when using make clean like that. I accidentally deleted every regular file on my pc because I changed the name of my DIR variable, making it empty when substituting into the expression "rm -rf $(DIR)/*". Typing "make clean" essentially ran "rm -rf /*", deleting most of my filesystem. Not fun! I suggest always prefixing with ./
@anon_y_mousse
@anon_y_mousse 2 года назад
An excellent addition to the first video.
@10e999
@10e999 3 года назад
Great video. Here's some topic idea that are interesting IMO: Makefile dependency management and ./configure script
@nemis123
@nemis123 2 года назад
Thanks, I needed that.
@smrtfasizmu6161
@smrtfasizmu6161 2 года назад
This channel is golden
@JacobSorber
@JacobSorber 2 года назад
Thanks.
@cernejr
@cernejr 3 года назад
Nice tutorial, but still quite simplistic. With a real-world project one would not be overwriting debug and release binaries in the same directory, there should be dedicated rls and dedicated dbg dirtrees. Designing build is often tedious/painful, but also extremely important. Cut corners and you will pay the price over time. Not sure if you should make more videos on this subject - one can spend a lot of time on this and it is a dry/tedious subject. Maybe just make a video illustrating how much effort/complexity real-world builds entail. And in that context please also mention cmake, it is pretty much industry standard.
@michelles.3835
@michelles.3835 2 года назад
This was really useful. Do you have any tips on source directories with more folders inside them?
@basedboi8852
@basedboi8852 3 года назад
Will you do a video on higher level (and cross platform) build systems like CMake?
@naveencrasta2685
@naveencrasta2685 3 года назад
New to Make. Simple and clear! How about header files in include/ ?
@lifeless9768
@lifeless9768 3 года назад
Thank you so much :D
@integral1191
@integral1191 3 года назад
would have been great if you would have discussed multiple sub folders inside of src because I'm confused
@themiwi
@themiwi Год назад
While for the very simple, one-off stuff I use raw make, it really doesn't scale when you go cross-platform or have dependencies. Adding a basic project setup with CMake is a breeze, abstracts a lot of the nitty gritty tedious details and platform differences away and lets you focus on the important stuff. That's not to say that programmers shouldn't understand make and the low-level details of building a binary, but that doesn't mean you should *always* have to deal with it.
@xhivo97
@xhivo97 2 года назад
How can I include external libraries in my project with their source files and compile a statically linked binary? Specifically I wanna use libpng, libz and libjpeg.
@integral1191
@integral1191 3 года назад
I definitely needed this
@gn03398604
@gn03398604 3 года назад
Good tip! thank you so much for introducing in this vedio
@diegoporras7769
@diegoporras7769 Год назад
Do we aways need to have intermediate object files (.o) and then link or can I just compile w/o the -o flag all together?
@RAMB0VI
@RAMB0VI Год назад
Does this notation work on windows platform?
@Slime_Head
@Slime_Head 3 года назад
Could you make a video on phony targets in make?
@integral1191
@integral1191 3 года назад
also im making a Makefile, but when I go to run make, its saying that there is a duplicate of every single one of my functions
@pajeetsingh
@pajeetsingh 3 года назад
0:06 Omg! Pls tell me that music name. I've heard it and can't find the source. It's giving me headache.
@sukivirus
@sukivirus 3 года назад
Hi Jacob good work. I follow your videos to learn more about C programming but lately I found visual studio much more useful than vs code because it points out mistakes in memory allocation/deallocation by providing warning immediately by syntax highlighting. Also I feel as the project grows its easier to add more files and work on it and worry about make file stuff. May be I am a windows user so make file will be much useful in other operating system. Your thoughts are appreciated. Thanks
@JacobSorber
@JacobSorber 3 года назад
I have talked about how I feel about IDEs in a few other videos. They're fine, but for new programmers, I prefer tools/systems that hide fewer details from the student.
@benjaminshinar9509
@benjaminshinar9509 3 года назад
really timely video, I had to update my makefile last week. some questions: how do you account for both windows and unix systems in the same makefile? i found a flag that detects the OS and i use it to replace my rm (to del) and my .out to .exe, but it still feels weird. I have an issue that if i update a h file (cpp, so the templated code), it doesn't rebuild properly until i clean everything. is there a correct way to handle this?
@warrenbuckley3267
@warrenbuckley3267 3 года назад
Hey Jacob, I'm curious why you don't use Cmake? Just familiarity?
@JacobSorber
@JacobSorber 3 года назад
I'm familiar with cmake, and have used it from time to time. I'm not in love with it - probably a product of the sort of work I do - but I can see why others like it. Also, in my classes, I prefer to use build systems with less magic, so the students can more easily understand what is actually going on. Still, there will probably be a cmake video in the future.
@Hellohiq10
@Hellohiq10 3 года назад
When you are so early there isn’t any comments.
@IrizarryBrandon
@IrizarryBrandon 3 года назад
When you're so early you're able to put a "like" on each comment :)
@TheVertical92
@TheVertical92 3 года назад
i dont get the 'all: $(BIN)' rules 🤔 First of all, what does it? And when i use this, i always get the error: make: *** No rule to make target 'bin/main', needed by 'all'. Stop.
@praenubilus1980
@praenubilus1980 3 года назад
Is it possible to have a tutorial about CMake?
@JacobSorber
@JacobSorber 3 года назад
We don't know yet. But, probably. 🤔 I'll see what I can do.
@PiyushASupe
@PiyushASupe 3 года назад
Much needed ine
@slayerofyounglings66
@slayerofyounglings66 3 года назад
CMake is your friend. Mostly.
@user-sf9gs2pg1b
@user-sf9gs2pg1b Год назад
CISC gang where you at?
@ladyViviaen
@ladyViviaen 3 года назад
rust programmers be like : cargo new how_it_feels --bin
@user-ux2kk5vp7m
@user-ux2kk5vp7m 3 года назад
Rust is cringe
@erwinschrodinger2320
@erwinschrodinger2320 3 года назад
I like peanut butter
@JacobSorber
@JacobSorber 3 года назад
Me too.
@weremsoft
@weremsoft 3 года назад
I’d like to see how you habdle complex structures inside the src folder. Like deep ly nested folders with .h and .c files. Thanks
@jacobschmidt
@jacobschmidt 3 года назад
honestly one of the most helpful videos I've seen, thank you
@JacobSorber
@JacobSorber 3 года назад
You're welcome! Glad you liked it.
@Slime_Head
@Slime_Head 3 года назад
This would have been so useful in my first year of university. I looked around for this kind of stuff, but found little information at the time. Awesome video!
@nikhilreddydev
@nikhilreddydev 2 года назад
What if I need a binary for each source file in src folder?. Like I need a structure like following / ---src/ ---bin/ Makefile. Can someone guide me on this?
@reverse_shell
@reverse_shell 3 года назад
This is a great topic to continue as the startup for projects is critical, please continue this series!
@JacobSorber
@JacobSorber 3 года назад
Thanks. Are there project setup topics you would specifically want me to address?
@reverse_shell
@reverse_shell 3 года назад
@@JacobSorber I didn't even see a notification until today! Wow, but having multiple library directories and a main project. How to chain these together appropriately and work with the build system in an optimal manner. Let's safe for purposes of video length, you'd have 2 x small example libraries and 1 x main project folder to compile the executable. How do we handle this for both release and debug builds?
@SoulSukkur
@SoulSukkur 3 года назад
For most of my applications, I prefer to keep different sources in different 1-deep subdirctories, which requires more complex shenanigans to have all of them searched seamlessly. also, i think with this setup, if you update a header file, this makefile won't know to recompile everything that included it. For that, I learned about the -MMD flag, which creates files containing depenendencies which can be imported into the makefile. both clang and gcc have the MMD flag.
@fusca14tube
@fusca14tube 3 года назад
Excellent! Please, make a video explaining this DEBUG symbol. I really did not understand why are you using NDEBUG instead of simple DEBUG. Thanks.
@hbobenicio
@hbobenicio 2 года назад
The %.o: %.c matching pattern is good for simple projects, but not really precise in some bigger ones. For example, it doen't recompile some source files which depend on some other header files which do not have its .c counterpart. In big projects it's really a mess and a nightmare to keep track of dependencies manually. That's why most modern C/C++ compilers support autodependency file generation with -MD and -MP flags which could be used in conjunction with -include in Makefiles to ease this process. Last thing to note is that there are some missing .PHONY rules to be more precise too. It's not easy to make good scalable Makefiles for big project by hand though. That's when I go to CMake or meson. Anyway, it was a great video! I really enjoy and learn a lot watching your channel!
@archibald-yc5le
@archibald-yc5le 3 года назад
Thanks for the great tips! I'd love to see a video about testing with make. I have my own routine with a bunch of test-* rules but the catch is that some test modules/cases are much bigger than others, which creates total spaghetti in my project environment. Moreover, at some point you realize some project parts deserve their own folders and even Makefiles but it's always too late. A video on how to manage tests would be deeply appreciated!
@CosmonautCoding
@CosmonautCoding 3 года назад
Awesome vid!
@EnkoVlog
@EnkoVlog 3 года назад
Thanks for exp. Could you please create similar lesson for CMake?
@JacobSorber
@JacobSorber 3 года назад
At some point, there will definitely be a cmake video on here. Just not sure when. It's on the list (but it's a good-sized list).
@Silverdragon98
@Silverdragon98 3 года назад
Nice one Jacob, I've set this up now for myself. One other thing I did that others might find useful, is a make target to run valgrind. This way you can use to test for memory leaks on all versions.
@nashs.4206
@nashs.4206 2 года назад
Great video! One way to expand on the content of this video would be to implement dependencies on header files.
@tomnetoo
@tomnetoo Год назад
The best of all is that you never get drunk.
@mbilalsheikh
@mbilalsheikh 3 года назад
your videos are awesome jacob you put a lot of effort to be concise and it really shows
@khomo12
@khomo12 2 года назад
A bit more advanced but very cool!
@dhruvildave887
@dhruvildave887 3 года назад
Best best best!!
@RockTo11
@RockTo11 3 года назад
Do you have thoughts on Unity Builds (not the game engine): en.wikipedia.org/wiki/Unity_build
@marusdod3685
@marusdod3685 3 года назад
this would've been very useful like, months ago. I ended up switching to cmake xD
Далее