Tap to unmute

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

  Рет қаралды 34,830

Jacob Sorber

Jacob Sorber

Күн бұрын

Пікірлер: 77
@abzrg
@abzrg Жыл бұрын
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
@mshingote
@mshingote 3 жыл бұрын
Cool. Can you also make a video on cross platform build system. Cmake, premake etc?
@nagarajahuliyapuradamata3447
@nagarajahuliyapuradamata3447 3 жыл бұрын
+1
@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.
@bloom945
@bloom945 4 ай бұрын
!! 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 ./
@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?
@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!
@wilfreddv
@wilfreddv 3 жыл бұрын
I jokingly said "eat the frog, make a script that sets up a project for you". I actually finished it :d
@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.
@anon_y_mousse
@anon_y_mousse 2 жыл бұрын
An excellent addition to the first video.
@mbilalsheikh
@mbilalsheikh 3 жыл бұрын
your videos are awesome jacob you put a lot of effort to be concise and it really shows
@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.
@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
@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.
@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("-")
@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!
@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.
@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.
@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!
@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!
@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.
@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 :/
@boxedowl
@boxedowl 3 жыл бұрын
Anything Make or C related I'm here for.
@10e999
@10e999 3 жыл бұрын
Great video. Here's some topic idea that are interesting IMO: Makefile dependency management and ./configure script
@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.
@smrtfasizmu6161
@smrtfasizmu6161 2 жыл бұрын
This channel is golden
@JacobSorber
@JacobSorber 2 жыл бұрын
Thanks.
@nemis123
@nemis123 2 жыл бұрын
Thanks, I needed that.
@gavridgeway
@gavridgeway 3 жыл бұрын
Awesome vid!
@nikhilreddydev
@nikhilreddydev 3 жыл бұрын
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?
@michelles.3835
@michelles.3835 3 жыл бұрын
This was really useful. Do you have any tips on source directories with more folders inside them?
@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.
@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?
@integral1191
@integral1191 3 жыл бұрын
I definitely needed this
@naveencrasta2685
@naveencrasta2685 3 жыл бұрын
New to Make. Simple and clear! How about header files in include/ ?
@gn03398604
@gn03398604 3 жыл бұрын
Good tip! thank you so much for introducing in this vedio
@RAMB0VI
@RAMB0VI Жыл бұрын
Does this notation work on windows platform?
@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.
@khomo12
@khomo12 2 жыл бұрын
A bit more advanced but very cool!
@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).
@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.
@basedboi8852
@basedboi8852 3 жыл бұрын
Will you do a video on higher level (and cross platform) build systems like CMake?
@lifeless9768
@lifeless9768 3 жыл бұрын
Thank you so much :D
@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.
@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.
@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.
@themiwi
@themiwi 2 жыл бұрын
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.
@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?
@integral1191
@integral1191 3 жыл бұрын
would have been great if you would have discussed multiple sub folders inside of src because I'm confused
@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
@dhruvildave887
@dhruvildave887 3 жыл бұрын
Best best best!!
@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.
@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.
@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
@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 :)
@PiyushASupe
@PiyushASupe 3 жыл бұрын
Much needed ine
@tomnetoo
@tomnetoo Жыл бұрын
The best of all is that you never get drunk.
@slayerofyounglings66
@slayerofyounglings66 3 жыл бұрын
CMake is your friend. Mostly.
@ladyViviaen
@ladyViviaen 3 жыл бұрын
rust programmers be like : cargo new how_it_feels --bin
@user-ux2kk5vp7m
@user-ux2kk5vp7m 3 жыл бұрын
Rust is cringe
@user-sf9gs2pg1b
@user-sf9gs2pg1b Жыл бұрын
CISC gang where you at?
@erwinschrodinger2320
@erwinschrodinger2320 3 жыл бұрын
I like peanut butter
@JacobSorber
@JacobSorber 3 жыл бұрын
Me too.
A Few Embedded Systems Tips for Beginners
8:19
Jacob Sorber
Рет қаралды 30 М.
Setup Tips for Your Next Programming Project
12:33
Jacob Sorber
Рет қаралды 29 М.
Support each other🤝
00:31
ISSEI / いっせい
Рет қаралды 81 МЛН
IL'HAN - Qalqam | Official Music Video
03:17
Ilhan Ihsanov
Рет қаралды 700 М.
“Don’t stop the chances.”
00:44
ISSEI / いっせい
Рет қаралды 62 МЛН
How Senior Programmers ACTUALLY Write Code
13:37
Thriving Technologist
Рет қаралды 1,6 МЛН
How to Check Your Pointers at Runtime
14:12
Jacob Sorber
Рет қаралды 32 М.
The purest coding style, where bugs are near impossible
10:25
Coderized
Рет қаралды 1 МЛН
Make your Data Type more Abstract with Opaque Types in C
13:41
Jacob Sorber
Рет қаралды 52 М.
How to make memory read-only in your C programs.
12:57
Jacob Sorber
Рет қаралды 21 М.
How To Structure A Programming Project…
19:00
Tech With Tim
Рет қаралды 116 М.
why do header files even exist?
10:53
Low Level
Рет қаралды 451 М.
2 Years Of Learning C | Prime Reacts
22:24
ThePrimeTime
Рет қаралды 330 М.
The Perfect Dependency - SQLite Case Study
19:32
Tom Delalande
Рет қаралды 84 М.
Master Pointers in C:  10X Your C Coding!
14:12
Dave's Garage
Рет қаралды 341 М.
Support each other🤝
00:31
ISSEI / いっせい
Рет қаралды 81 МЛН