Thread: learn to develop C on linux

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    15

    learn to develop C on linux

    i want to learn how to develop C on linux, now i have installed two styles linux system(ubantu ,debian).i am a newbie, don't know where i should write my c programme in ? and what tool to compile my C code. any tips would be appreciated, the more detail,the better.

  2. #2
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    Depending on the distribution there should be plenty of IDEs available as well as compilers. The most popular compiler is still gcc I think, which can be found easily through a google search.

    As for IDEs I think KDevelop, Codeblocks and even Eclipse (with the CDT plugin) are pretty popular. Eclipse is somewhat quirkier though in my experience because it is written in Java.

    You also might want to explore writing code in a simple text editor and compiling, linking and debugging code manually through command line tools. This will make your work more tedious but as a beginner you will learn a lot about C programming and programming in general as well.

  3. #3
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    However keep in mind that the core features of a programming language are not really system dependent, unless you use specific OS libraries. So learning C should not be associated with learning a particular OS, at least IMO. Not that learning an OS would be a bad thing, don't get me wrong, and Linux can be particularly useful in a lot of situations.

  4. #4
    Registered User
    Join Date
    Mar 2010
    Posts
    15
    i am also a beginner to learn about C programming , lots of people tell me the best platform to learn C is on linux. so i want to do this. i don't know where to write C code and compiling, linking and debugging code manually .and how to set up gcc. is there an example to explain this. thank you.

  5. #5
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    Well, in that case you are better off using an IDE for now. At least until you understand some basic C syntax and what the whole fuss is about. So go on the web download an IDE such as Codeblock or KDevelop, install it on your Linux system and get started.

    A good place for answers to the ton of questions you may have at this point is here:

    Cprogramming.com: How to Get Started with C++

    The site also has tutorials, quizzes and various useful links to C programming resources. Ultimately, you can ask SPECIFIC questions on this forum if you are having problems with something in particular.

  6. #6
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Here's another alternative.

    gcc is very simple to use. You do need to get used to working on the command line in linux if you are not and want to program there. Open a terminal into your home directory (~). First make sure you are there:
    cd ~
    Make a directory to keep your code in:
    mkdir C
    Now move into it:
    cd C
    Install gedit if you don't have it already (you probably do), it is pretty simple and does syntax highlighting for .c files. So write some code in gedit and then save it in ~/C make sure you name the file "something.c", "something" can be anything but it must end in ".c". This will turn the syntax highlighting on.
    Now, from the command line terminal where you are in the ~/C directory, you can check and see the file there:
    ls -A
    To compile:
    gcc -Wall something.c
    The "-Wall" turns warnings on. Warnings are different than errors -- a warning will not prevent the code from being compiled. An error will. So if there are no errors, you should now have a file called "a.out" in ~/C. To execute it:
    ./a.out
    "./" just refers to the fact that this is in the current directory. You need to do this with an executable outside of the executable path, which you are. If you want to name the executable something else, you can do this:
    gcc -Wall -o exename something.c
    Be careful you get the names in the right order, or do not accidently use "something.c" twice, that will overwrite your code . gedit keeps backup files by default, I think they look like "~something.c". You can make a backup or snapshot:
    cp something.c something.c-1
    A safer way to rename the exe:
    mv a.out exename
    To delete:
    rm a.out

    That's all there is to it. You can google around for information on gcc (tutorials, etc). gedit is a totally simple point and click, menu driven, mouse operated GUI text editor and probably needs no instructions.
    Last edited by MK27; 03-21-2010 at 11:08 PM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  7. #7
    Registered User
    Join Date
    Mar 2010
    Posts
    15
    ,thanks for all you replies.what is the best editor for writeing C code on linux, i am only want to make my C ability perfect .for the moment, don't learn linux OS

  8. #8
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by runeveryday View Post
    ,thanks for all you replies.what is the best editor for writeing C code on linux, i am only want to make my C ability perfect .for the moment, don't learn linux OS
    Well, your inability to use the OS is going to severely cramp your ability to program on it. You may find some tools (eg, an IDE) which will "replace" some of the immediate and inescapable needs for this, but then you've added a heavy layer of abstraction, learning the tool will probably take you just as long, and you will be stuck needing that tool to do things for you (which it will not save any time or effort, it will just require a different kind of effort) rather than knowing how to do them yourself.

    Vis, text editors, just choose a basic GUI editor like "gedit" or "kate" for now. You don't have any experience coding yet, so it is absurd to start looking around for what will be the best thing for you for all time -- you have no way to judge for yourself. Google "linux GUI text editor" and find one you like. They're simple to use and later on, when you understand in more concrete terms what programming involves, you can start to think about more complex tools. So I would avoid stuff like "vim" or "emacs" initially, just like I would avoid an IDE.

    Otherwise you are like the rich guy who shows up at that ski shop and says, "Sell me the best equipment, I need to learn to ski". It doesn't matter how much you spend at this point -- you will just end up with a bunch of veterans showing up trying to sell you what they use, which is very likely inappropriate and may even lead to additional difficulties. You're a beginner, be happy about it, but don't believe for a second than you can just skip the fundamentals because if someone tells you what "the best editor for writing C code" is this will help make your "C ability perfect". That means doing some work and learning, not shopping around for (even more) equipment* you can't use.

    This is not something you need to waste more than 5 minutes thinking about. If I were you, I'd just start up gedit and get coding.

    * by "even more" I refer to the fact that you said you were using linux because you heard it's a good platform to learn C on, and it is. But now you want to skip learning the basics of the OS that you already chose and installed so you can chose and install even more software -- that's an endless silly game -- you haven't bothered with what you already have, start there before you move on. Anything else is just foolishness. I'm sorry, but programming takes time, patience, and effort. Get used to it. There will be plenty of time to work on your wardrobe later.
    Last edited by MK27; 03-22-2010 at 07:54 AM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  9. #9
    Registered User
    Join Date
    Mar 2010
    Posts
    15
    many thanks to your very cool tips, i'll start up gedit and get coding. i know on the way of making my c ability perfect, there will be lots of hard time waiting for me. but i think i am able to come through it. wish you can do me lots of favour later.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. installing linux for the first time
    By Micko in forum Tech Board
    Replies: 9
    Last Post: 12-06-2004, 05:15 AM
  2. dual os with linux?
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 19
    Last Post: 09-09-2004, 10:33 PM
  3. Linux for Windows!
    By Strut in forum Linux Programming
    Replies: 2
    Last Post: 12-25-2002, 11:36 AM
  4. Linux? Windows Xp?
    By VooDoo in forum Linux Programming
    Replies: 15
    Last Post: 07-31-2002, 08:18 AM
  5. linux vs linux?
    By Dreamerv3 in forum Linux Programming
    Replies: 5
    Last Post: 01-22-2002, 09:39 AM