gcc vs g++

Jul 12, 2012 at 10:27pm
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 Jul 12, 2012 at 10:28pm
Jul 12, 2012 at 10:49pm
gcc does not link the C++ standard libraries by default. You can make it work by passing -lstdc++ to gcc.
Jul 13, 2012 at 12:24pm
It fails to work because gcc is the C compiler and g++ is the C++ compiler in GNU.
Jul 13, 2012 at 1:10pm
$ whatis gcc
gcc - GNU project C and C++ compiler 
Besides, the problem is at the linking stage ;)
Jul 13, 2012 at 2:08pm
I get it! thanks for the responses!
Topic archived. No new replies allowed.