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

  Рет қаралды 32,633

Jacob Sorber

Jacob Sorber

3 жыл бұрын

Patreon ➤ / jacobsorber
Courses ➤ jacobsorber.thinkific.com
Website ➤ www.jacobsorber.com
---
More Tips for Setting up a Programming Project: Subdirectories and Structure // Enough with these simple projects, where everything is in one directory. This video provides more tips about how to setup a programming project, including how to subdirectories with your makefile or other build system.
Related video:
• Setup Tips for Your Ne...
***
Welcome! I post videos that help you learn to program and become a more confident software developer. I cover beginner-to-advanced systems topics ranging from network programming, threads, processes, operating systems, embedded systems and others. My goal is to help you get under-the-hood and better understand how computers work and how you can use them to become stronger students and more capable professional developers.
About me: I'm a computer scientist, electrical engineer, researcher, and teacher. I specialize in embedded systems, mobile computing, sensor networks, and the Internet of Things. I teach systems and networking courses at Clemson University, where I also lead the PERSIST research lab.
More about me and what I do:
www.jacobsorber.com
people.cs.clemson.edu/~jsorber/
persist.cs.clemson.edu/
To Support the Channel:
+ like, subscribe, spread the word
+ contribute via Patreon --- [ / jacobsorber ]
Source code is also available to Patreon supporters. --- [jsorber-youtube-source.heroku...]

Пікірлер: 76
@mshingote
@mshingote 3 жыл бұрын
Cool. Can you also make a video on cross platform build system. Cmake, premake etc?
@nagarajahuliyapuradamata3447
@nagarajahuliyapuradamata3447 3 жыл бұрын
+1
@wilfreddv
@wilfreddv 3 жыл бұрын
I jokingly said "eat the frog, make a script that sets up a project for you". I actually finished it :d
@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.
@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.
@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!
@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
@mbilalsheikh
@mbilalsheikh 3 жыл бұрын
your videos are awesome jacob you put a lot of effort to be concise and it really shows
@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.
@nemis123
@nemis123 2 жыл бұрын
Thanks, I needed that.
@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?
@CosmonautCoding
@CosmonautCoding 3 жыл бұрын
Awesome vid!
@anon_y_mousse
@anon_y_mousse 2 жыл бұрын
An excellent addition to the first video.
@integral1191
@integral1191 3 жыл бұрын
I definitely needed this
@gn03398604
@gn03398604 3 жыл бұрын
Good tip! thank you so much for introducing in this vedio
@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.
@10e999
@10e999 3 жыл бұрын
Great video. Here's some topic idea that are interesting IMO: Makefile dependency management and ./configure script
@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.
@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!
@lifeless9768
@lifeless9768 3 жыл бұрын
Thank you so much :D
@abzrg
@abzrg 7 ай бұрын
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
@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.
@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.
@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.
@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!
@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.
@smrtfasizmu6161
@smrtfasizmu6161 2 жыл бұрын
This channel is golden
@JacobSorber
@JacobSorber 2 жыл бұрын
Thanks.
@PiyushASupe
@PiyushASupe 3 жыл бұрын
Much needed ine
@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!
@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("-")
@michelles.3835
@michelles.3835 2 жыл бұрын
This was really useful. Do you have any tips on source directories with more folders inside them?
@dhruvildave887
@dhruvildave887 3 жыл бұрын
Best best best!!
@khomo12
@khomo12 2 жыл бұрын
A bit more advanced but very cool!
@basedboi8852
@basedboi8852 3 жыл бұрын
Will you do a video on higher level (and cross platform) build systems like CMake?
@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.
@naveencrasta2685
@naveencrasta2685 2 жыл бұрын
New to Make. Simple and clear! How about header files in include/ ?
@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.
@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?
@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).
@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?
@Slime_Head
@Slime_Head 3 жыл бұрын
Could you make a video on phony targets in make?
@integral1191
@integral1191 3 жыл бұрын
would have been great if you would have discussed multiple sub folders inside of src because I'm confused
@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?
@xhivo97
@xhivo97 Жыл бұрын
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.
@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.
@RAMB0VI
@RAMB0VI 10 ай бұрын
Does this notation work on windows platform?
@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.
@tomnetoo
@tomnetoo 9 ай бұрын
The best of all is that you never get drunk.
@marusdod3685
@marusdod3685 3 жыл бұрын
this would've been very useful like, months ago. I ended up switching to cmake xD
@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 :)
@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
@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.
@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.
@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.
@RockTo11
@RockTo11 3 жыл бұрын
Do you have thoughts on Unity Builds (not the game engine): en.wikipedia.org/wiki/Unity_build
@slayerofyounglings66
@slayerofyounglings66 3 жыл бұрын
CMake is your friend. Mostly.
@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.
@user-sf9gs2pg1b
@user-sf9gs2pg1b 10 ай бұрын
CISC gang where you at?
@erwinschrodinger2320
@erwinschrodinger2320 3 жыл бұрын
I like peanut butter
@JacobSorber
@JacobSorber 3 жыл бұрын
Me too.
@ladyViviaen
@ladyViviaen 3 жыл бұрын
rust programmers be like : cargo new how_it_feels --bin
@user-ux2kk5vp7m
@user-ux2kk5vp7m 3 жыл бұрын
Rust is cringe
A Few Embedded Systems Tips for Beginners
8:19
Jacob Sorber
Рет қаралды 29 М.
Setup Tips for Your Next Programming Project
12:33
Jacob Sorber
Рет қаралды 28 М.
DO YOU HAVE FRIENDS LIKE THIS?
00:17
dednahype
Рет қаралды 90 МЛН
Always be more smart #shorts
00:32
Jin and Hattie
Рет қаралды 49 МЛН
ОСКАР ИСПОРТИЛ ДЖОНИ ЖИЗНЬ 😢 @lenta_com
01:01
When You Get Ran Over By A Car...
00:15
Jojo Sim
Рет қаралды 23 МЛН
Make your Data Type more Abstract with Opaque Types in C
13:41
Jacob Sorber
Рет қаралды 48 М.
How To Structure A Programming Project…
19:00
Tech With Tim
Рет қаралды 88 М.
How to Check Your Pointers at Runtime
14:12
Jacob Sorber
Рет қаралды 30 М.
Project Setup: Automated Testing with Make (using queue example)
17:00
2 Years Of Learning C | Prime Reacts
22:24
ThePrimeTime
Рет қаралды 252 М.
CONCURRENCY IS NOT WHAT YOU THINK
16:59
Core Dumped
Рет қаралды 89 М.
How to Write Function-Like Preprocessor Macros (C example)
13:59
Jacob Sorber
Рет қаралды 40 М.
How To Structure Your Programming Projects
13:11
Hallden
Рет қаралды 256 М.
Premature Optimization
12:39
CodeAesthetic
Рет қаралды 770 М.
how do hackers exploit buffers that are too small?
8:25
Low Level Learning
Рет қаралды 189 М.
DO YOU HAVE FRIENDS LIKE THIS?
00:17
dednahype
Рет қаралды 90 МЛН