Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I am new in Ubuntu. Now I am using ubuntu 12.04(lts). I want to run my C programming code (.c/.cpp). But I dont know how to compile and run code in ubuntu. SO i need help. Please tell me How can I run single .c code in ubuntu.

share|improve this question
add comment

3 Answers 3

I assume there is terminal emulator widget in your geany (which is suggested by geany package). Click on it (In lower-left corner) and first navigate to folder in which is your source file:

cd Path/To/Source

To compile file YourSourceFile.c type:

gcc YourSourceFile.c -o ProgramName

To run the program type:

./ProgramName
share|improve this answer
add comment

In Geany you can execute your code in two ways. In the first way you can click at Build option at the global menu there you can find options for compiling ,building and executing. Look at the image enter image description here

If you are a hotkey lover then you can do with hotkeys also. Here F8 for Compiling and F5 for Running the C program.

share|improve this answer
add comment

If you don't already have the compiler installed, you'll need to install it and other development tools:

sudo apt-get install build-essential

Once that's done, the compiler command is gcc. To compile code from the command line run:

gcc sourcefile.c

This will, if successful, produce an executable called a.out. Run the command:

./a.out

If you want a different executable name, use the -o option with gcc:

gcc sourcefile.c -o myprogram

This will produce an executable called myprogram. Run it as you did a.out:

./myprogram

Once you've installed everything and have the basics down, then using geany or other programmer's editors to run your build can be don as Jai noted.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.