Thread: Compliling C from command line

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    21

    Compliling C from command line

    I am currently doing all my C or C++ in Visual Studio or Dev C++, both installed in free version form on my computer. What I would like to do is simply write a C program (not C++) in Notepad++ and run from the cmd command line. The Java equivalent would be javac [name of java file]. Do I need to download anything not already given with the IDEs already mentioned?

    How do I do this?

  2. #2
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314

  3. #3
    Registered User
    Join Date
    Mar 2011
    Posts
    21
    Yes I did 'bother to search' but didn't find exactly what I needed. It will be obvious to an expert like you. Thanks for the link anyway.

  4. #4
    Registered User
    Join Date
    Mar 2011
    Posts
    3
    Hi musicman,

    If you have visual whatever, I have to assume you're on a windows system. On Linux/Mac you have the gnu compiler collection preinstalled as 'gcc'. However, I'm unfortunately forced to use a windows box on a particular machine at work. What I did was install cygwin which gives you a unix like environment. It allows you to click checkboxes at config time and you just need to select gcc. You will have to research this a bit more as I don't have the answer to exactly what you need to check but search on gcc and cygwin and you should be able to figure this out.

    However, there may be another alternative to getting gcc to work on your windows command interface. Again, you'll have to research. I'm sure there are many other viable options for windows other than gcc. I've heard of something like minigw?

    This wikipedia entry may be of use:
    List of compilers - Wikipedia, the free encyclopedia

    Yeah, the cygwin/gcc route is the only one I've personally used. Lastly, if you do choose to go with gcc, there are many options for how to compile your code. Before you learn them all, you should be able to get going with:
    gcc -Wall -ggdb yourprogram.c

    This will create an a.out executable file that you should be able to run your program should it compile. The 'Wall' is for warning all, the -ggdb, creates debugging symbols allowing you to run the program from gdb ./a.out (you mentioned javac, so I believe the analog is jdb right?) This is a whole other beast of it's own. I suggest you also look in to ddd which is a nice front end to gdb should you get in to debugging your code; ahem, why wouldn't you? I personally just run the gdb commands and enjoy seeing more of my code listed.

    Hope all this is helpful to you!
    Last edited by rlevin; 03-06-2011 at 09:13 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compliling with libs
    By ginoitalo in forum Linux Programming
    Replies: 1
    Last Post: 03-23-2005, 12:24 PM