Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
1.60/5 (2 votes)
See more:
when I use gcc to compile this program, I get bunches of errors, like:"Undefined reference to std::cout","Undefined reference to std::basic_ostream",etc.
Anyone help me?

This is my program:
C++
#include <iostream>
#include <pthread.h>

void *function1(void *arg);
void *function2(void *arg);

int main(int argc, char *argv[])
{
  pthread_t p1,p2;
  pthread_create(&p1,NULL,function1,NULL);
  pthread_create(&p2,NULL,function2,NULL);
  pthread_exit(NULL);
  return 0;
}

void *function1(void *arg)
{
  std::cout<<"thread1"<<std::endl;
}

void *function2(void *arg)
{
  std::cout<<"thread2"<<std::endl;
}
Posted
Updated 29-Jun-13 7:05am
v2
Comments
[no name] 29-Jun-13 13:11pm    
Try adding "using namespace std;"
H.Brydon 29-Jun-13 20:20pm    
That is not needed (at least for this code portion) because the namespace references are fully qualified already.

1 solution

Sorry, I don't know why, but when I compile by g++, it gives me no more error and compiles successfully.
 
Share this answer
 
Comments
Maximilien 29-Jun-13 15:04pm    
Well, DUH, , gcc is the C compiler ans g++ is the C++ compiler...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900