gcc vs g++

The following code does not compile in gcc, but complies fine with g++,
can anyone tell me the reason why this might happen?

This is a basic program in multicore programming, taken from the book "Professional Multicore Programming and Development for C++ Programmers"

I am a beginner in linux programming.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
// Listing 2-1
// uses sysconf() function to determine how many
// processors are available to the OS.
                    
using namespace std;
#include  <unistd.h>
#include  "iostream" 
                   
int main(int argc,char *argv[])
{
   cout  <<sysconf(_SC_NPROCESSORS_CONF)<<endl;
   return(0);
} 
Last edited on
gcc does not link the C++ standard libraries by default. You can make it work by passing -lstdc++ to gcc.
It fails to work because gcc is the C compiler and g++ is the C++ compiler in GNU.
$ whatis gcc
gcc - GNU project C and C++ compiler 
Besides, the problem is at the linking stage ;)
I get it! thanks for the responses!
Topic archived. No new replies allowed.