LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-02-2005, 04:02 PM   #1
anandt4u
LQ Newbie
 
Registered: Jun 2005
Location: Montreal
Distribution: Fedora Core 3
Posts: 29

Rep: Reputation: 15
g++ vs gcc


can someone give me the difference bet g++ and gcc??
 
Old 06-02-2005, 04:33 PM   #2
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
g++ is a C++ compiler, gcc is a C compiler.
 
Old 06-02-2005, 04:42 PM   #3
anandt4u
LQ Newbie
 
Registered: Jun 2005
Location: Montreal
Distribution: Fedora Core 3
Posts: 29

Original Poster
Rep: Reputation: 15
Quote:
Originally posted by itsme86
g++ is a C++ compiler, gcc is a C compiler.
what?? do you mean g++ was written in c++ and gcc in C???

both g++ and gcc compile c and c++ programs
 
Old 06-02-2005, 08:18 PM   #4
aluser
Member
 
Registered: Mar 2004
Location: Massachusetts
Distribution: Debian
Posts: 557

Rep: Reputation: 43
On my machine, gcc doesn't like c++ programs correctly, at least with default arguments. Also, g++ will compile and link a c++ program which has a .c extension, while gcc won't even compile it. (looks like it doesn't know where the c++ headers are)

gcc and g++ do share a lot of code. In fact, I want to say that g++ just invokes gcc with some set of additional arguments.
 
Old 06-03-2005, 06:38 AM   #5
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
g++ is just a wrapper for gcc.


gcc -Lstdc++ == g++
 
Old 06-03-2005, 09:03 AM   #6
aluser
Member
 
Registered: Mar 2004
Location: Massachusetts
Distribution: Debian
Posts: 557

Rep: Reputation: 43
Code:
09:58 aluser@alf:~/test/c$ cat hello.cpp 
#include <iostream>

using namespace std;

int main() {
        cout << "hello world\n";
        return 0;
}
09:58 aluser@alf:~/test/c$ gcc -Lstdc++ -o hello hello.cpp
/tmp/cc4E4x2P.o(.text+0x1b): In function `main':
: undefined reference to `std::cout'
/tmp/cc4E4x2P.o(.text+0x20): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/tmp/cc4E4x2P.o(.text+0x49): In function `__static_initialization_and_destruction_0(int, int)':
: undefined reference to `std::ios_base::Init::Init[in-charge]()'
/tmp/cc4E4x2P.o(.text+0x7a): In function `__tcf_0':
: undefined reference to `std::ios_base::Init::~Init [in-charge]()'
/tmp/cc4E4x2P.o(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
09:58 aluser@alf:~/test/c$ g++ -o hello hello.cpp
09:59 aluser@alf:~/test/c$
This is on debian sarge. not quite sure what's going on, but the two aren't quite equivalent.

Even if we get the -L and -Is figured out, I'm fairly sure that g++ will compile c++ files with a .c extension, where gcc will give you a bunch of syntax errors.

Mostly the same code, but there are enough differences that you want to get in the habit of using the right one : )
 
Old 06-03-2005, 09:19 AM   #7
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
Quote:
Mostly the same code, but there are enough differences that you want to get in the habit of using the right one : )
Technically speaking it is 100% the same source code. The difference is when you use a front end wrapper like g++ it assumes you are compiling c++ code regardless of the file extension you use. When you just invoke "gcc" it decides what language the source is in based on the extension of the file.

".c" are assumed to be C files.
".cxx", ".cc", ".cpp", ".C", ect. are assumed to be C++.

Check out the Compiling C++ section of the GCC manual for more info.

Quote:
g++ is a program that calls GCC with the default language set to C++, and automatically specifies linking against the C++ library. On many systems, g++ is also installed with the name c++.
- The GCC Manual.

Last edited by jtshaw; 06-03-2005 at 09:21 AM.
 
Old 06-03-2005, 10:36 AM   #8
anandt4u
LQ Newbie
 
Registered: Jun 2005
Location: Montreal
Distribution: Fedora Core 3
Posts: 29

Original Poster
Rep: Reputation: 15
thanks for all the info
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
gcc wont install, 'failed dependencies: glibc-devel is needed by gcc-3.3.3-41' TdlSnare SUSE / openSUSE 3 11-29-2004 02:13 PM
Kernel compiling: gcc-3.3 is 586, should be gcc-3.3 386 Erik Plaggenmar Linux - Software 0 10-01-2004 11:38 AM
running software built with gcc 3.0.2 on Redhat 8 - gcc 3.2 dst1989 Linux - Software 3 03-08-2004 10:23 PM
a doubt with host gcc and arm-linux-gcc renjithgopal Linux - General 1 09-11-2003 04:02 PM
export CC=/usr/bin/gcc-3.2 - switch gcc version? ferreter Linux - Software 1 08-20-2003 12:07 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:55 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration