13 Replies - 2201 Views - Last Post: 13 January 2008 - 10:26 PM Rate Topic: -----

#1 cricketfancy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 12-January 08

c under linux

Post icon  Posted 12 January 2008 - 11:17 PM

how to write a c program in linux?also guide how to compile and execute it.
i am currently using fedora 8.

Is This A Good Question/Topic? 0
  • +

Replies To: c under linux

#2 jjhaag  Icon User is offline

  • me editor am smartastic
  • member icon

Reputation: 44
  • View blog
  • Posts: 1,789
  • Joined: 18-September 07

Re: c under linux

Posted 12 January 2008 - 11:30 PM

Moved to C/C++.

Please read the rules and post in the correct forum.

And welcome to </dic> :)
Was This Post Helpful? 0
  • +
  • -

#3 PennyBoki  Icon User is offline

  • system("revolution");
  • member icon

Reputation: 53
  • View blog
  • Posts: 2,334
  • Joined: 11-December 06

Re: c under linux

Posted 13 January 2008 - 03:05 AM

View Postcricketfancy, on 12 Jan, 2008 - 11:17 PM, said:

how to write a c program in linux?also guide how to compile and execute it.
i am currently using fedora 8.


You could use a text editor to write the code, then save the file as a e.g. nameOfTheFile.c

Then you can use the command line to compile the code, you should be in the folder where the .c file is.

So write:

gcc nameOfTheFile.c

and if there are no errors to run your program do:

a.out

or

./a.out
Was This Post Helpful? 0
  • +
  • -

#4 cricketfancy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 12-January 08

Re: c under linux

Posted 13 January 2008 - 05:25 AM

View PostPennyBoki, on 13 Jan, 2008 - 03:05 AM, said:

View Postcricketfancy, on 12 Jan, 2008 - 11:17 PM, said:

how to write a c program in linux?also guide how to compile and execute it.
i am currently using fedora 8.


You could use a text editor to write the code, then save the file as a e.g. nameOfTheFile.c

Then you can use the command line to compile the code, you should be in the folder where the .c file is.

So write:

gcc nameOfTheFile.c

and if there are no errors to run your program do:

a.out

or

./a.out

it is giving an error as follows:
bash: a.out: command not found
also tried ./a.out but:
bash: ./a.out: No such file or directory
also guide whether we can directly include header files like
stdio.h, conio.h, graphics.h............
Was This Post Helpful? 0
  • +
  • -

#5 revenge2  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 25-December 07

Re: c under linux

Posted 13 January 2008 - 06:05 AM

hey there, sorry i just had to ask this question as well. Im also just trying out linux- Ubuntu, im wondering how you can compile the code with the terminal/consol
Thing
Was This Post Helpful? 0
  • +
  • -

#6 PennyBoki  Icon User is offline

  • system("revolution");
  • member icon

Reputation: 53
  • View blog
  • Posts: 2,334
  • Joined: 11-December 06

Re: c under linux

Posted 13 January 2008 - 06:52 AM

View Postcricketfancy, on 13 Jan, 2008 - 05:25 AM, said:

also guide whether we can directly include header files like
stdio.h, conio.h, graphics.h............


ok for the run try this:

./nameOfTheFile.c

and the headers include them in the .c file.
Was This Post Helpful? 0
  • +
  • -

#7 PennyBoki  Icon User is offline

  • system("revolution");
  • member icon

Reputation: 53
  • View blog
  • Posts: 2,334
  • Joined: 11-December 06

Re: c under linux

Posted 13 January 2008 - 07:04 AM

View Postrevenge2, on 13 Jan, 2008 - 06:05 AM, said:

hey there, sorry i just had to ask this question as well. Im also just trying out linux- Ubuntu, im wondering how you can compile the code with the terminal/consol
Thing


For ubuntu try:

$ gcc nameOfTheFile.c

then:

$ ./a.out

Now, I want to show you a trick it's called google ;)

go to www.google.com

just write the question you need and there and there you go.

:) Hope this helps.

This post has been edited by PennyBoki: 13 January 2008 - 07:05 AM

Was This Post Helpful? 0
  • +
  • -

#8 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: c under linux

Posted 13 January 2008 - 07:13 AM

As for the question about conio.h, graphics.h, etc...it will depend on the library. You cannot include conio.h on linux, as it is platform dependant. You'll habe to check whatever library you want to include to see if it's available for your platform.

The standard C library is as follows:

http://www.utas.edu..../C/CStdLib.html
Was This Post Helpful? 0
  • +
  • -

#9 cricketfancy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 12-January 08

Re: c under linux

Posted 13 January 2008 - 09:59 AM

View PostPennyBoki, on 13 Jan, 2008 - 06:52 AM, said:

View Postcricketfancy, on 13 Jan, 2008 - 05:25 AM, said:

also guide whether we can directly include header files like
stdio.h, conio.h, graphics.h............


ok for the run try this:

./nameOfTheFile.c

and the headers include them in the .c file.

hi,
thanks for giving responses.............
but the issue still remains
firstly after tryingg to run by ./nameofthefile.c error came as:
bash: ./sample.c: Permission denied
next
compiler gave error messages for clrscr() and getch() functions
sample.c:(.text+0xa): undefined reference to `clrscr'
sample.c:(.text+0x23): undefined reference to `getch'
lastly
does the ./ concept work under fedora...........
under ubuntu it did work..............
but what about fedora?
coz its giving errors all the time!!
Was This Post Helpful? 0
  • +
  • -

#10 Tom9729  Icon User is offline

  • Segmentation fault
  • member icon

Reputation: 180
  • View blog
  • Posts: 2,641
  • Joined: 30-December 07

Re: c under linux

Posted 13 January 2008 - 10:57 AM

cc -o name_of_executable name_of_source.c will compile your source.
./name_of_executable will run the executable.

If you get errors compiling, the executable will not be made.

Also, you can't execute the source code. That only works with interpreted languages like Perl and Bash.

Can you please post the code you're trying to compile? I don't think clscr is a standard function...

It's also worth noting that there are plenty of C IDE's out there. I don't understand why people think that programming on Linux always means calling GCC from the commmand line...

Try Eclipse CDT, Anjuta, KDevelop.

All of them should be available from your distribution's package manager.
Was This Post Helpful? 0
  • +
  • -

#11 MorphiusFaydal  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 43
  • View blog
  • Posts: 1,376
  • Joined: 12-May 05

Re: c under linux

Posted 13 January 2008 - 04:48 PM

clrscr() and getch() are both functions in conio.h which is Windows only. I had that problem the first time I tried to build a program in Linux.
Was This Post Helpful? 0
  • +
  • -

#12 Bench  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 856
  • View blog
  • Posts: 2,339
  • Joined: 20-August 07

Re: c under linux

Posted 13 January 2008 - 04:53 PM

View Postrevenge2, on 13 Jan, 2008 - 01:05 PM, said:

hey there, sorry i just had to ask this question as well. Im also just trying out linux- Ubuntu, im wondering how you can compile the code with the terminal/consol
Thing

I installed Ubuntu a while back, and I noticed that it does not come with all the files which you need in order to compile and run C code.

Have a look at this thread which details how to install the files you need

http://ubuntuforums....ad.php?t=120421
Was This Post Helpful? 0
  • +
  • -

#13 cricketfancy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 12-January 08

Re: c under linux

Posted 13 January 2008 - 09:37 PM

View PostTom9729, on 13 Jan, 2008 - 10:57 AM, said:

cc -o name_of_executable name_of_source.c will compile your source.
./name_of_executable will run the executable.

If you get errors compiling, the executable will not be made.

Also, you can't execute the source code. That only works with interpreted languages like Perl and Bash.

Can you please post the code you're trying to compile? I don't think clscr is a standard function...

It's also worth noting that there are plenty of C IDE's out there. I don't understand why people think that programming on Linux always means calling GCC from the commmand line...

Try Eclipse CDT, Anjuta, KDevelop.

All of them should be available from your distribution's package manager.

hi,
it worked out.............
thanks a lot...........

how to use the other compilers which you specified like eclipse , anjuta , kdevelop
also like under turbo c we have a watch option ...........
how to do that under linux.........
means executing step by step and also viewing the changes.............
Was This Post Helpful? 0
  • +
  • -

#14 MorphiusFaydal  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 43
  • View blog
  • Posts: 1,376
  • Joined: 12-May 05

Re: c under linux

Posted 13 January 2008 - 10:26 PM

View Postcricketfancy, on 13 Jan, 2008 - 10:37 PM, said:

View PostTom9729, on 13 Jan, 2008 - 10:57 AM, said:

cc -o name_of_executable name_of_source.c will compile your source.
./name_of_executable will run the executable.

If you get errors compiling, the executable will not be made.

Also, you can't execute the source code. That only works with interpreted languages like Perl and Bash.

Can you please post the code you're trying to compile? I don't think clscr is a standard function...

It's also worth noting that there are plenty of C IDE's out there. I don't understand why people think that programming on Linux always means calling GCC from the commmand line...

Try Eclipse CDT, Anjuta, KDevelop.

All of them should be available from your distribution's package manager.

hi,
it worked out.............
thanks a lot...........

how to use the other compilers which you specified like eclipse , anjuta , kdevelop
also like under turbo c we have a watch option ...........
how to do that under linux.........
means executing step by step and also viewing the changes.............


We know what debugging is. It varies on what IDE you're using. Usually, you click in the margin next to the line number to set a breakpoint, then you go to the debug menu and hit "run". Also in the debug menu should be an option to show the watches window. What IDE are you using, and we may be able to provide slightly more detailed directions.

BTW; Eclipse, Anjuta, and KDevelop are IDEs, like Visual Studio or Turbo C. They all use GCC though.

For command line debugging, do man gdb and read it. That will tell you how to use the GNU DeBugger.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1