Need your HELP: C in LINUX

N

Nirjhar Oberoi

Hi,

I am new to Linux and wanted to know how to use GCC to Compile the Code
written in C? I dont want to use EMacs or VI for my editor. Can you
suggest a good IDE for linux for C Programming..

Does C Programming on windows environment and on linux environment
differ???

Thank you.

Keep Rocking
 
R

Richard Heathfield

Nirjhar Oberoi said:
Hi,

I am new to Linux and wanted to know how to use GCC to Compile the Code
written in C?

gcc -W -Wall -ansi -pedantic -Wformat-nonliteral -Wcast-align
-Wpointer-arith -Wbad-function-cast -Wmissing-prototypes
-Wstrict-prototypes -Wmissing-declarations -Winline -Wundef
-Wnested-externs -Wcast-qual -Wshadow -Wconversion -Wwrite-strings
-Wno-conversion -ffloat-store -O2 -o foo foo.c
I dont want to use EMacs or VI for my editor.

Fine, so don't do that.
Can you
suggest a good IDE for linux for C Programming..

Linux *is* an IDE for C programming.
Does C Programming on windows environment and on linux environment
differ???

No. C is a portable language. If you confine yourself to the C language and
standard library, you will have no difficulty getting your C programs to
work on either platform.
 
J

junky_fellow

Hi,

I am new to Linux and wanted to know how to use GCC to Compile the Code
written in C? I dont want to use EMacs or VI for my editor.

As a beginner you may find it somewhat awkward to use "vi" editor. But,
"vi"
is a powerful tool that enables fast, simple and effective editing of
files.
It provides certain commands that are in particular helpful when you
are
writing/reading a c program.
However, if you dont want to use it for any reason, there are text
editors
available on linux systems.
 
B

Bill Pursell

Nirjhar said:
I am new to Linux and wanted to know how to use GCC to Compile the Code
written in C? I dont want to use EMacs or VI for my editor. Can you
suggest a good IDE for linux for C Programming..

Does C Programming on windows environment and on linux environment
differ???

Your choice of editor has nothing to do with compilation. Programming
in windows is different from programming in linux in the same way
way that any other task is different, but the code should be
the same on both (unless you use system specific calls).

The best IDE for programming in C on linux is bash, using
vim/emacs, make, ctags/etags, and gdb. If you disregard vim/emacs
right off the bat, you are doing yourself a disservice. If you really
have a need to avoid vim & emacs, you might try ed:

echo -e "a\n#include <stdio.h>\nint main(void) { printf(\"Hello\\\n\");
return 0;}\n.\nwq foo.c\n" | ed 2>&1 | gcc foo.c | ./a.out

....but that's crazy talk.
 
K

KDr2

Bill Pursell said:
Your choice of editor has nothing to do with compilation. Programming
in windows is different from programming in linux in the same way
way that any other task is different, but the code should be
the same on both (unless you use system specific calls).

The best IDE for programming in C on linux is bash, using
vim/emacs, make, ctags/etags, and gdb. If you disregard vim/emacs
right off the bat, you are doing yourself a disservice. If you really
have a need to avoid vim & emacs, you might try ed:

echo -e "a\n#include <stdio.h>\nint main(void) { printf(\"Hello\\\n\");
return 0;}\n.\nwq foo.c\n" | ed 2>&1 | gcc foo.c | ./a.out

...but that's crazy talk.

Yeah,Bash,Emacs/Vim,make,ctags/etags,they are so powerful...if you do not want to use them,try "anjuta" or "kdeveloper3",maybe you will found the things what you
wanted!

Good Luck!!
--
For some reasons,my EMail had been changed to "kdr2[#]163.com" now...

NO GNUS is Bad News.

------yours Killy Draw
 
K

Kenny McCormack

Bill Pursell said:
The best IDE for programming in C on linux is bash, using
vim/emacs, make, ctags/etags, and gdb. If you disregard vim/emacs

There's no such thing as vim/emacs.

Given that people here have had heart attacks (and some have died as a
result) when people refer to "C/C++", I'm amazed that you would even
chance uttering such a ridiculous thing (as vim/emacs).
 
S

srj

Nirjhar said:
Hi,

I am new to Linux and wanted to know how to use GCC to Compile the Code
written in C? I dont want to use EMacs or VI for my editor. Can you
suggest a good IDE for linux for C Programming..

Does C Programming on windows environment and on linux environment
differ???

Thank you.

Keep Rocking

first of all i'd recomend u 2 check out the man page for gcc.
type "man gcc" on console
you can save aafile using vi or any other text editor, save it as
"name.c"
do "cc name.c"
u'll get an output file"a.out"(default)
run it by" ./a.out"
u can rename a.out by "mv a.out newname"

or do "cc name.c -o newname"
this will create output file newname instead of default a.out

hav fun with LINUX
 
C

CBFalconer

srj said:
.... snip ...

first of all i'd recomend u 2 check out the man page for gcc.
type "man gcc" on console

Who is this universal programmer named u? A U2 is an airplane,
BTW.
 
?

=?ISO-8859-2?Q?Jaros=B3aw_Rafa?=

Nirjhar Oberoi napisa³(a):
I am new to Linux and wanted to know how to use GCC to Compile the Code
written in C? I dont want to use EMacs or VI for my editor. Can you
suggest a good IDE for linux for C Programming..

I don't use an IDE. Using gcc is fairly simple. As for my editor
preference, I usually use joe. It has a built in function to compile the
code using compiler specified in the configuration, but I don't even use
that. Simply open 2 terminal windows, joe with the code in one window,
shell in the other. Save your file from the editor, then type in the
other window: "gcc file.c" - this is the simplest form of using gcc.
Repeat this until you get rid of compile errors ;-). It compiles and
links your program and puts the executable into the file "a.out". Then
you can run it by typing "./a.out". If you want to change the
executable's name, use "gcc -o outfile file.c", then your executable
will be named "outfile".
To compile a program consisting of several source files, you can type
"gcc -o outfile file1.c file2.c file3.c". You can also compile each
module individually (with the command like "gcc -c -o file1.o file1.c" -
the "-c" flag means compile only, do not link) and then link them with
"gcc -o outfile file1.o file2.o file3.o". You can probably figure out by
yourself various mixtures of these methods... ;-)
For more information, read the manual with "man gcc" - be warned,
there's LOT of options (most of them although you will never use). -I,
-L and -l are the most important ones. -I specifies the additional
locations for include files, -L the same for library files, -l tells the
linker what libraries to link (standard library doesn't need to be
specified).
So, for example
gcc -o test main.c common.o mystring.o -I ./include -lnsl
will compile the file "main.c", link it with object files "common.o" and
"mystring.o" and with the library named "nsl", and put the executable
into the file "test". Include files will be searched - beside standard
locations - in subdirectory "include" of the current directory.
Hope this helps.
Does C Programming on windows environment and on linux environment
differ???

Library functions differ (except for the standard library - printf,
scanf etc., which should be the same on both platforms), not the
language itself. It depends on what libraries you were using in Windows.
 
N

Nirjhar Oberoi

Jarosław Rafa said:
Nirjhar Oberoi napisa³(a):

I don't use an IDE. Using gcc is fairly simple. As for my editor
preference, I usually use joe. It has a built in function to compile the
code using compiler specified in the configuration, but I don't even use
that. Simply open 2 terminal windows, joe with the code in one window,
shell in the other. Save your file from the editor, then type in the
other window: "gcc file.c" - this is the simplest form of using gcc.
Repeat this until you get rid of compile errors ;-). It compiles and
links your program and puts the executable into the file "a.out". Then
you can run it by typing "./a.out". If you want to change the
executable's name, use "gcc -o outfile file.c", then your executable
will be named "outfile".
To compile a program consisting of several source files, you can type
"gcc -o outfile file1.c file2.c file3.c". You can also compile each
module individually (with the command like "gcc -c -o file1.o file1.c" -
the "-c" flag means compile only, do not link) and then link them with
"gcc -o outfile file1.o file2.o file3.o". You can probably figure out by
yourself various mixtures of these methods... ;-)
For more information, read the manual with "man gcc" - be warned,
there's LOT of options (most of them although you will never use). -I,
-L and -l are the most important ones. -I specifies the additional
locations for include files, -L the same for library files, -l tells the
linker what libraries to link (standard library doesn't need to be
specified).
So, for example
gcc -o test main.c common.o mystring.o -I ./include -lnsl
will compile the file "main.c", link it with object files "common.o" and
"mystring.o" and with the library named "nsl", and put the executable
into the file "test". Include files will be searched - beside standard
locations - in subdirectory "include" of the current directory.
Hope this helps.


Library functions differ (except for the standard library - printf,
scanf etc., which should be the same on both platforms), not the
language itself. It depends on what libraries you were using in Windows.
--
All reply's are good... but i found yours the most informative (NO
OFFENCE guyz) :)
Thank's a lot you all... i will get back to you if i need any help...
Thanks again :)
Happy Programming
 
S

Simon Biber

Richard said:
Nirjhar Oberoi said:


gcc -W -Wall -ansi -pedantic -Wformat-nonliteral -Wcast-align
-Wpointer-arith -Wbad-function-cast -Wmissing-prototypes
-Wstrict-prototypes -Wmissing-declarations -Winline -Wundef
-Wnested-externs -Wcast-qual -Wshadow -Wconversion -Wwrite-strings
-Wno-conversion -ffloat-store -O2 -o foo foo.c

Whoa! How often do you get useful warnings from those that you wouldn't
from simple '-ansi -pedantic -Wall -W -O2'?
Linux *is* an IDE for C programming.

Well, no, Linux is merely a kernel. :)

Granted, just about all operating systems built on Linux do come with
excellent development tools, either automatically installed or as an option.
 
S

Simon Biber

Bill said:
If you really
have a need to avoid vim & emacs, you might try ed:

echo -e "a\n#include <stdio.h>\nint main(void) { printf(\"Hello\\\n\");
return 0;}\n.\nwq foo.c\n" | ed 2>&1 | gcc foo.c | ./a.out

You don't want to pipe the output of ed to gcc; you want to wait until
ed has exited successfully before starting gcc, otherwise the foo.c file
may not yet have been written. Similarly, you should wait until gcc has
exited successfully before starting ./a.out.

....but that's crazy talk.

Indeed.
 
R

Richard Heathfield

Simon Biber said:

Well, no, Linux is merely a kernel. :)

Understood. My use of the term is a lax one - but everybody knows what I
mean, except of course for RMS & Co.
 
C

CBFalconer

Simon said:
Richard Heathfield wrote:
.... snip ...

Whoa! How often do you get useful warnings from those that you
wouldn't from simple '-ansi -pedantic -Wall -W -O2'?

I use "-ansi -pedantic -Wall -W -Wwrite-strings -Wfloat-equal'.
This handles the silly error of attempting to alter anonymous
strings, and of testing floating equality. YMMV.
 
B

Bill Pursell

Simon said:
You don't want to pipe the output of ed to gcc; you want to wait until
ed has exited successfully before starting gcc, otherwise the foo.c file
may not yet have been written. Similarly, you should wait until gcc has
exited successfully before starting ./a.out.

echo -e "a\n#include <stdio.h>\nint main(void) { printf(\"Hello\\\n\");
return 0;}\n.\nwq foo.c\n" | ed 2>&1 && gcc foo.c && ./a.out

yes, originally I had ';' instead of '|', (which is not as correct
as '&&'), but then decided to redirect ed's error stream to
/dev/null, and thought it was clever to pipe it into gcc where
it would be ignored. Unfortunately, I then also unthinkingly
went for the symmetry and piped it into a.out, forgetting
that it would only work (assuming no errors) on the
second invocation. I foolishly hoped no-one would
catch the error... Of course, there's no need at all
for ed here. Maybe the right thing to do (well, other than
the obvious--ignoring this thread comletely! :) ) is something like

echo -e "#include <stdio.h>\nint main(v) { printf(\"Hello\\\n\");return
0;}" | sed s/v/void/ > foo.c && gcc foo.c && ./a.out
 
C

Charles Richmond

CBFalconer said:
Who is this universal programmer named u? A U2 is an airplane,
BTW.
No, no. "u" means "unsigned" and he obviously has
an unsigned constant "2". But ISTM that the "u" should
follow the constant. Anyway...

U2 is a rock group.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top