PDA

View Full Version : C compiler command?



Jamesbowden
January 7th, 2007, 01:12 PM
I have been using C++ for a little while now, i install the build essential pack from the package manager so i could use the "gcc" and "g++" command to compile my code.

however i am thinking of doing a bit of C, but i dont know the command to compile it.

what command do i use?

Canis familiaris
January 7th, 2007, 01:15 PM
Use the command:


user@user-pc:~/dev$ gcc filename.c -o program.bin

Jamesbowden
January 7th, 2007, 01:18 PM
Use the command:


user@user-pc:~/dev$ gcc filename.c -o program.bin

I thought gcc was only for c++?

Canis familiaris
January 7th, 2007, 01:20 PM
gcc is for C
g++ is for C++

Jamesbowden
January 7th, 2007, 01:21 PM
gcc is for C
g++ is for C++

Ahh thanks.

mxrten
January 7th, 2007, 01:23 PM
It's just the same as with c++-code, gcc can be used for both languages, just use a c-file instead. Gcc decides which language to use based upon the file extension.

You can force language selection with the -x <language> flag... E.g. -x c

Canis familiaris
January 7th, 2007, 01:31 PM
gcc intended mainly for C. If you try to compile C++ programs with gcc it refuses to compile classes (alteast when i try to compile)

moma
January 7th, 2007, 01:47 PM
The basic gcc command looks like this
$ gcc -Wall program.c -o program

Run the program
$ ./program

An old but good intro to c. Replace cc with gcc.
http://users.actcom.co.il/%7Echoo/lupg/tutorials/c-on-unix/c-on-unix.html

Of course the GCC... (http://gcc.gnu.org) (GNU's compiler collection that includes c, c++, Ada, Fortran...) has it's own documentation: http://www.gnu.org/software/gcc/onlinedocs/
---------------

GCC can determine the source language from file extension.

$ gcc test1.c will start a c-compiler. (a compiler in means of a module, program )
$ gcc test1.cpp will start a c++ compiler. You must link with -lstdc++
$ gcc test1.f77 will start a fortran compiler.
$ gcc test1.java will start the GCJ Java compiler.

gcc's command line is rather general, so you may need to add flags and referencies to link libraries.

What is the difference between gcc and g++ ?
g++ is a program that calls gcc with appropriate flags and libraries for c++ compilation. Thus for c++ coding, the g++ is more convenient to use than gcc.
For example:

$ g++ test1.cpp -o test1
(is equal to)
$ gcc -lstdc++ test1.cpp -o test1 ( requires linkage to libstdc++ library)

Run it
$ ./test1

See also:
Browse to this... (http://home.online.no/%7Eosmoma/opportunities.html) and locate
* Linux development platform...(pdf) Chapter 3.3
* Advanced Linux programming(pdf)

Download the books (pdf) and read ;-)

See also 2:
http://www.ubuntuforums.org/showthread.php?p=1962696#post1962696

Canis familiaris
January 7th, 2007, 02:01 PM
What is the difference between gcc and g++ ?
g++ is a program that calls gcc with appropriate flags and libraries for c++ compilation. Thus for c++ coding, the g++ is more convenient to use than gcc.
For example:

$ g++ test1.cpp
(is equal to)
$ gcc -lstdc++ test1.cpp (requires linkage to libstdc++ library)


See also:
Browse to this... (http://home.online.no/%7Eosmoma/opportunities.html) and locate
* Linux development platform...(pdf) Chapter 3.3
* Advanced Linux programming(pdf)

Download the books (pdf) and read ;-)

See also 2:
http://www.ubuntuforums.org/showthread.php?p=1962696#post1962696

Er, thanks!