Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4575114
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T20:01:04+00:00 2026-05-21T20:01:04+00:00

It seems to me that gcc can deal with both c and c++ projects,so

  • 0

It seems to me that gcc can deal with both c and c++ projects,so why is g++/gcc-c++ needed?

What’s the difference between g++ and gcc-c++?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T20:01:05+00:00Added an answer on May 21, 2026 at 8:01 pm

    gcc will compile C source files as C and C++ source files as C++ if the file has an appropriate extension; however it will not link in the C++ library automatically.

    g++ will automatically include the C++ library; by default it will also compile files with extensions that indicate they are C source as C++, instead of as C.

    From http://gcc.gnu.org/onlinedocs/gcc/Invoking-G_002b_002b.html#Invoking-G_002b_002b:

    C++ source files conventionally use one of the suffixes .C, .cc, .cpp, .CPP, .c++, .cp, or .cxx; C++ header files often use .hh, .hpp, .H, or (for shared template code) .tcc; and preprocessed C++ files use the suffix .ii. GCC recognizes files with these names and compiles them as C++ programs even if you call the compiler the same way as for compiling C programs (usually with the name gcc).

    However, the use of gcc does not add the C++ library. g++ is a program that calls GCC and treats .c, .h and .i files as C++ source files instead of C source files unless -x is used, and automatically specifies linking against the C++ library. This program is also useful when precompiling a C header file with a .h extension for use in C++ compilations.

    For example, to compile a simple C++ program that writes to the std::cout stream, I can use either (MinGW on Windows):

    • g++ -o test.exe test.cpp
    • gcc -o test.exe test.cpp -lstdc++

    But if I try:

    • gcc -o test.exe test.cpp

    I get undefined references at link time.

    And for the other difference, the following C program:

    #include <stdlib.h>
    #include <stdio.h>
    
    int main() 
    {
        int* new;
        int* p = malloc(sizeof(int));
    
        *p = 42;
        new = p;
    
        printf("The answer: %d\n", *new);
    
        return 0;
    }
    

    compiles and runs fine using:

    • gcc -o test.exe test.c

    But gives several errors when compiled using:

    • g++ -o test.exe test.c

    Errors:

    test.c: In function 'int main()':
    test.c:6:10: error: expected unqualified-id before 'new'
    test.c:6:10: error: expected initializer before 'new'
    test.c:7:32: error: invalid conversion from 'void*' to 'int*'
    test.c:10:9: error: expected type-specifier before '=' token
    test.c:10:11: error: lvalue required as left operand of assignment
    test.c:12:36: error: expected type-specifier before ')' token
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It seems that we can show layers and even use a different zPosition for
It seems that JavaScript's Date() function can only return local date and time. Is
The code below demonstrates a behavior of gcc 4.6.2 that I can't account for.
I'm playing around with a toolchain that seems to wrap gcc (qcc), but also
GCC seem to think that I am trying to make a function call in
Seems that This will be an easy question for you but this problem is
Seems that even after unchecking the option in the PyDev/Debug preferenecs pane to launch
It seems that runClasses() doesn't terminate the code being tested even after the test
It seems that often I find that my code when moving either from one
It seems that it is not advisable to use <meta http-equiv=REFRESH CONTENT=3;url=url> for redirects

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.