| Written by: | MadhaniHarsh |
Score: 10 votes: 14 Format: Article |
How to run C program in linux?
Install C and C++ Compilers in Mint
sudo aptitude install build-essential
This will install all the required packages for C and C++ compilers
Compiling Your first C Programs
Now you need to open first.c file
sudo gedit first.c
add the following lines save and exit the file
#include
int main()
{
printf(“Hello world\n”);
return 0;
}
Firstly compile the code using the following command
cc -c first.c
that would produce an object file you may need to add to the library.
then create an executable using the following command
cc -o first first.c
Now run this executable using the following command
./first
Output should show as follows
Hello, world
Tags: c in linux
Created: 1 year ago.
Last edited: 1 year ago.
Reviewed: 1 year ago.
Read 0 times.
| Comments | |||
| 1 year ago |
dagon |
The tags are removed when you press edit, but you can fix the tutorial and save it and it will work. If you then choose to edit it once more you must make sure to also re-add whatever the editor takes away... :( I don't know of any other way. |
|
| 1 year ago |
MadhaniHarsh |
@dagon:exactly.... | |
| 1 year ago |
dagon |
Ok. The code probably went missing after editing the text. A bug in CKEditor: http://drupal.org/node/1258998 |
|
| 1 year ago |
dagon |
1. #include should be: #include <stdio.h> // parenthesis won't render (html/xml???) This explains the "undeclaired" part of the errors... 2. printf(“Hello world\n”) The quotation marks is not plain ascii so that would explain the "stray `\342'... etc. We need a "Code component" thing for tutorials! 3. I'm with @frankh: gcc -o name name.c |
|
| 1 year ago |
MadhaniHarsh |
@parashargunjan:have you used conio.h header file? | |
| 1 year ago |
parashargunjan |
first.c: In function ‘main’: first.c:4: error: stray ‘\342’ in program first.c:4: error: stray ‘\200’ in program first.c:4: error: stray ‘\234’ in program i m getting the below error plz help me out first.c:4: error: ‘Hello’ undeclared (first use in this function) first.c:4: error: (Each undeclared identifier is reported only once first.c:4: error: for each function it appears in.) first.c:4: error: expected ‘)’ before ‘world’ first.c:4: error: stray ‘\’ in program first.c:4: error: stray ‘\342’ in program first.c:4: error: stray ‘\200’ in program first.c:4: error: stray ‘\235’ in program |
|
| 1 year ago |
Vishal |
very nice.. |
|
| 1 year ago |
efthialex |
@MadhaniHarsh: Nice job! |
|
| 1 year ago |
MadhaniHarsh |
@trollboy:thankx,spread it if u like it | |
| 1 year ago |
trollboy |
Nice simple introduction | |
| 1 year ago |
kazztan0325 |
@MadhaniHarsh: Needless to say, I clicked on Promote Button when I added my first comments. ( And then I added you as my friend. I would be glad if you would also add me as your friend.) |
|
| 1 year ago |
MadhaniHarsh |
@kazztan0325:thankx,i will keep this way of explaining.If u like it then please promote it. | |
| 1 year ago |
frankh |
Comment: For the simplest compilation and use of C i Linux, it's not necessary to create an object file first. You can do gcc -o name name.c, and you'll immediately have an executable file. |
|
| 1 year ago |
kazztan0325 |
I think this tutorial is very useful and easy to follow for beginners who are interested in C and C++ to start learning them. |
|
Ideas
Tutorials
Hardware
Software
Countries
Users
Moderation
Chat room
ISO Images