大牙牙53 2021-03-24 16:28 采纳率: 0%
浏览 346

vs2019跨平台运行Linux程序的一个神奇现象:对pthread_create的未定义使用

vs2019上跑一个很简单的多线程程序,这个代码很简单

#include <iostream>
#include <pthread.h>
using namespace std;
void* thread_fun(void*)
{
    int a = 1;
    int b = 2;
    cout << a+b << endl;
    return NULL;
}

int main()
{
    pthread_t tid;
    unsigned int data = 56;
    int tret = pthread_create(&tid,NULL,thread_fun,&data);
}

诡异的是我Debug模式下运行的就好好的,但是Release版本下运行就会出现对pthread_create的未定义使用,这是为什么呀

  • 写回答

1条回答 默认 最新

  • 大牙牙53 2021-03-24 16:46
    关注

    找到问题啦,在项目的属性页配置的时候配置只设置了Debug下的库依赖项,需要把配置那里改成release,在库依赖项处再添加pthread即可,自己的最快回答

    评论

报告相同问题?