I'm reading a tutorial about threads in C++ and tested the following code:

```
#include <iostream>
#include <pthread.h>
#include <cstdlib>

using namespace std;

#define NUM_THREADS     5

void *PrintHello(void *threadid)
{
   long tid;
   tid = (long)threadid;
   cout << "Hello World! Thread ID, " << tid << endl;
   pthread_exit(NULL);
}

int main ()
{
   pthread_t threads[NUM_THREADS];
   int rc;
   int i;
   for( i=0; i < NUM_THREADS; i++ ){
      cout << "main() : creating thread, " << i << endl;
      rc = pthread_create(&threads[i], NULL, 
                      PrintHello, &threads[i]);
      if (rc){
         cout << "Error:unable to create thread," << rc << endl;
         exit(-1);
      }
   }
   pthread_exit(NULL);
}

```

I've tried to compile this code using both gcc and g++, but I always get compilation errors.

Using gcc -pthread thread\_test.c:

> 
> /tmp/ccmpQLyp.o: In function `PrintHello(void*)':
>  thread_test.cpp:(.text+0x1a): undefined reference to`std::cout'
>  thread\_test.cpp:(.text+0x1f): 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*)'
>  thread_test.cpp:(.text+0x2e): undefined reference to`std::ostream::operator<<(long)'
>  thread\_test.cpp:(.text+0x33): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
>  thread_test.cpp:(.text+0x3b): undefined reference to`std::ostream::operator<<(std::ostream& (\*)(std::ostream&))'
>  /tmp/ccmpQLyp.o: In function `main':
>  thread_test.cpp:(.text+0x63): undefined reference to`std::cout'
>  thread\_test.cpp:(.text+0x68): 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*)'
>  thread_test.cpp:(.text+0x75): undefined reference to`std::ostream::operator<<(int)'
>  thread\_test.cpp:(.text+0x7a): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
>  thread_test.cpp:(.text+0x82): undefined reference to`std::ostream::operator<<(std::ostream& (\*)(std::ostream&))'
>  thread\_test.cpp:(.text+0xcc): undefined reference to `std::cout'
>  thread_test.cpp:(.text+0xd1): undefined reference to`std::basic\_ostream >& std::operator<< >(std::basic\_ostream >&, char const\*)'
>  thread\_test.cpp:(.text+0xde): undefined reference to `std::ostream::operator<<(int)'
>  thread_test.cpp:(.text+0xe3): undefined reference to`std::basic\_ostream >& std::endl >(std::basic\_ostream >&)'
>  thread\_test.cpp:(.text+0xeb): undefined reference to `std::ostream::operator<<(std::ostream& (*)(std::ostream&))'
>  /tmp/ccmpQLyp.o: In function`\_\_static\_initialization\_and\_destruction\_0(int, int)':
>  thread\_test.cpp:(.text+0x141): undefined reference to `std::ios_base::Init::Init()'
>  thread_test.cpp:(.text+0x150): undefined reference to`std::ios\_base::Init::~Init()'
>  /tmp/ccmpQLyp.o:(.eh\_frame+0x47): undefined reference to `\_\_gxx\_personality\_v0'
>  collect2: error: ld returned 1 exit status
> 
> 
> 

Can you help? Do I have to do something so this code runs on Linux and Windows?