Tuesday, July 14, 2009

Beginning with C in ubuntu linux?

Where do I start?


I got the build essential and an IDE

Beginning with C in ubuntu linux?
If you have an IDE great. I never bother with them. I just grab whatever text editor is lying around (nano, vi, gvim and either gedit when I'm on Gnome and kedit here on KDE) do my writing with a terminal window open, save it to the directory I'm in in my terminal and do one of the following at the terminal prompt:





gcc -o %26lt;program name%26gt; %26lt;program name%26gt;.c


g++ -o %26lt;program name%26gt; %26lt;program name%26gt;.cc (the extension for c++ files I use. If you use cpp fine).





gcc -o %26lt;program name%26gt; -g %26lt;program name%26gt;.c





I think you can figure out the last one. If you don't use the -o switch then gcc will compile your program into a file called a.out. Back when I started using gcc in the early 90's (around 1991) I used to change the name rather than use the extension except I've always been a fool





Ubuntu is in many ways just like any other linux. Which other ways? Let's just say once you're used to linux in the best possible ways. I have issues with Synaptic, Update Manager and some of the security settings but those aren't the whole of the OS by any other means. What I have to say next applies to any other Linux and most unixes.





To run the program, if you have used the -o switch, type:





./%26lt;program name%26gt;





The ./ or dot slash as it is called, tells the os to look in the current directory for the program if the current directory is not in your path, which by default it is in Microsoft Windows, but not always in Unix/GNU/Linux. If you have used the -g switch then just type:





gdb %26lt;program name%26gt; .





That starts the Gnu Debugger, gdb. You can get a listing of the first 10 lines by typing "list" or l. Oh, heck. Type "info gdb" at the command line, assuming you have it installed and you will get the user's manual. If you don't have gdb installed type "sudo apt-get install gdb" rather than going to some gui.





What I'm talking about is the part of Linux that depends most heavily on GNU tools (among which is GCC the c compiler), so I'm talking about GNU/Linux. If you know how to handle your IDE great, but you really don't need it.





Good luck.


=-)


No comments:

Post a Comment