不能在子线程中使用std [英] cannot use std in subthread
本文介绍了不能在子线程中使用std的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我使用gcc编译这个程序时,我得到一堆错误,例如:对std :: cout的未定义引用,对std :: basic_ostream的未定义引用等等。
有人帮帮我吗?
这是我的程序:
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:
#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;
}
推荐答案
对不起,我不知道为什么,但是当我用g ++编译时,它不再给我了错误并成功编译。
Sorry, I don't know why, but when I compile by g++, it gives me no more error and compiles successfully.
这篇关于不能在子线程中使用std的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文