Sign in with
Sign up | Sign in
Your question

c/c++ in linux

Last response: in Linux/Free BSD
Share
February 5, 2006 12:59:36 PM

I was wondering wether anyone knew a good way to learn how to use c/c++ in linux.

Thanks

More about : linux

a b 5 Linux
February 8, 2006 7:11:23 AM

Quote:
I was wondering wether anyone knew a good way to learn how to use c/c++ in linux.

Thanks



# Easy!

[code:1:82f6bfa61d]
gcc filename.c # will compile filename.c with gcc

g++ filename.cpp # will compile filename.cpp with g++

man gcc # gcc manual page

# if you have the documentation installed you can also look in /usr/share/doc/$package_name/ for additional documentation or /usr/share/doc/gcc4-4.0.0 etc your gcc version may differ

# you can also run:

info gcc

[/code:1:82f6bfa61d]

# you may have to install the development tools if you do not already have them

# what version of Linux are you running?

# what kind of computer do you have (hardware specs)?

# do you already know C/C++?
a b 5 Linux
February 18, 2006 3:47:01 PM

Do you want to learn how to write C/C++ (from scratch) or do you know how to write C/C++ in Windows and want to learn how to write it in Linux? They are two different questions and have two different answers.

I am learning how to write C in Linux, but I have never programmed in C before. I simply bought a textbook that is used in a CS class ("C How to Program, 4th Ed. Deitel and Deitel, Prentice Hall, 2004.) as generally textbooks are better than reference books to teach oneself some topic- they have examples and problems to solve.

If you want to be able to write, compile, and execute C code in Linux, use a text editor like Kate, KWrite, or Gedit that has highlighting. It think it is a big help in seeing the different types of functions/instructions. To complie, enter something like:

gcc -o name_of_output -Wall ./name_of_source.c

and it will make an executable with whatever name you specified after -o. -Wall tells the complier to list all error and warning messages, like unused or undefined variables- things that do not cause errors severe enough to make the compiler fail. You can also use optimization flags- type in "man gcc" without the quotes to see all of the possible options you can pass to the compiler.
a b 5 Linux
February 19, 2006 3:04:35 AM

http://oreilly.com/ publishes some of the best computer books :D 


You can also:

man 3 printf # brings up the manual page for the C printf function

man 3 string # string operations

man 3 stdio # stdio - standard input/output library functions


If you have the inclination and the patience you could learn how to program entirely from the man pages / other free sources of information :D 
!