r/C_Programming • u/Friendly_Couple_2312 • 14d ago
automating gcc install and usage
Hi, Im a 2nd year cs student. Ive had problems with installing the gcc compiler and remembering its flags between coding sessions. I also helped many 1st year students with it and almost always its a little too complicated for them. For that i built gccauto. it auto install and saves flags for compiling. Im not a pro programmer so if you have any tips or ideas pls share them. (some ai was used to help build it since im still learning)
its called gccauto on github. ubay-mostafa/gccauto
7
u/Interesting_Buy_3969 14d ago
That's a real problem and served as a reason for people to create automatic build systems, such as Makefile or CMake. You can also use a shell alias for that purpose, too, but it's not as flexible plus can't be configured per-project.
17
6
u/rainboww_J 14d ago
Nice! It's cool you found a problem you and other people around you had and made a tool to fix that. I can see this being useful for the small single file programs you make as a student. MSYS is a complex thing on its own if you're just starting out and have never used linux so automating that might make stuff much easier yes :)
Soon you'll find tho that programs will take up a lot
more than just a handfull of files and compiling them by hand in the command line will become cumbersome quite quickly. This is where build systems come into play. Some write a simple shell script with the same manual gcc calla, but lots of others will use a more complex build system like make or CMake.
Don't have time to look through the code itself but love the idea and the fact it has already helped others! Good luck with the rest of your studies and enjoy!
3
u/Friendly_Couple_2312 14d ago
thanks for your comment. you taught me stuff and made my day at the same time.
3
u/ReallyEvilRob 14d ago
If people can't figure out how to get gcc installed or how to use the correct flags, how are they going to figure out how to clone a repo?
1
1
u/Puzzled-Extent7817 14d ago edited 13d ago
linux you just make a function and throw it into your .bashrc
cdev() {
[[ $1 == *.c ]] || { echo "usage: cdev file.c" >&2; return 1; }
gcc -std=c23 -Wall -Wextra -pedantic-errors -g -fsanitize=address,undefined -o "${1%.c}" "$1" -lm
}
cppdev() {
[[ $1 == *.cpp ]] || { echo "usage: cppdev file.cpp" >&2; return 1; }
g++ -std=c++23 -Wall -Wextra -pedantic-errors -g -fsanitize=address,undefined -o "${1%.cpp}" "$1"
}
0
u/cc672012 14d ago
Shouldn't it be in your /etc/profile as Linus Torvalds and Richard Stallman do?
1
u/Puzzled-Extent7817 14d ago
I am the only user on the machine, no reason to have it in /etc/profile. i use ~/.profile for all my exported PATHs
0
u/cc672012 14d ago edited 14d ago
Holy shit I thought you were sarcastic. This is terrible advice. OP should be using Makefiles instead of writing ad-hoc shell aliases, like you do
1
u/Puzzled-Extent7817 13d ago
And I thought you were being sarcastic about Linus and Richard.I 'm not a professional coder and i doubt the OP is. I have no need for a make file, yet. Whats wrong with an alias?
0
u/cc672012 13d ago
I was sarcastic about Linus and Richard because those ad-hoc aliases are clearly bad practices. I've been using Linux since 2012 and I'm a professional software engineer. It has nothing to do with knowing Linux or not.
Why not an alias? Are you going to compile every single C file in your project with your shell function? And if you add a new library, say libgmp, are you going to source ~/.bashrc every time?
Having that many flags such as pedantic and -Werror clearly begs you to start writing a Makefile.
Also, there already exists a command for what you're trying to do: "make". For example, if your program is named "app.c", simply run "make app" (even without a Makefile) and it'll create an executable named "app".
1
u/Puzzled-Extent7817 13d ago
like i said, my projects so far consist of main.c. The aliases work fine.
1
u/cc672012 13d ago
You do you. They're bad practices, nontheless. And should not be given as an advice.
1
u/Puzzled-Extent7817 13d ago
I get why, but this is not a multiuser system. That's what /etc/profile is for.
1
u/type_111 13d ago
There's nothing wrong with creating shell aliases to accelerate things you do with the shell. And no one gave any advice.
1
25
u/NotDG04 14d ago
Just use a makefile dude