peace upon you:
As they say Linux for developers.
so it’s an article to help any Beginner to Began developing C/C++ Under Linux.
————————-
Your distro comes often with the GCC (GNU Compiler Collection) and with the GDB (GNU Debugger) This tools is very important to any C/C++ developer turned to Linux.
1) The GCC:
First: Make sure the build-essential package is installed:
sudo apt-get install build-essential
Second: Compiling a Simple Program :
take this Hello World program and Copy and Paste it in a File Called main.c
#include<stdio.h>
int main()
{
printf(“Hello World!\n”);
return 0;
}
to Compile and make the output named test
gcc main.c -o test
If it work without any Compilation errors you can run your program:
./test
NOTES:
1) if you don’t Determine the output file the compiler will name him “a.out” and if there is another file have the same name the Compiler will replace it.
2) you can give the Compiler the option -Wall to make the Compiler print any error message he would say.
2) The GDB:
When you successfully write your code you will need to debugging it so there is the GDB. to debug any code
gdb ./test
where test is the binary code which the Compiler produce it.
this command will open the gdb prompt to take your Commands:
run
to run your code and stop at any break point you put it.
list
show you the source code of your program with numbered lines to put break points.
break LINE_NUMBER
put a break point in the line number which you determine.
continue
to continue running your code after stopping at break point.
step
next
move one step in your program.
delete
delete all the break point in your program.
clear LINE_NUMBER
clear the break point at this line.
until LINE_NUMBER
runĀ your program until a the Determined line.
display EXPRESSION
to display the value of this expression.
info
this command give you more information about the gdb commands
quit
to quit from the gdb
IMP.NOTES
1) To use the debugger you should run the option -g while compelling
your code with gcc.
2) when you deal with C++ you can follow the same steps but instant using the gcc you will use the g++.
so that’s it any feedback is welcomed
best wishes ,
aboelnour.