我得到了以下测试程序:
#include <stdio.h>
#include "pthread.h"
void* test_thread(void *ptr)
{
printf("In teh thread");
return NULL;
}
int main(void)
{
int foo = 1;
pthread_t t;
if (0 != pthread_create(&t, NULL, test_thread, (void *)foo)) {
printf("This was never going to work.");
}
while(1)
;
return 0;
}
构建时,我收到以下错误:
1>main.obj : error LNK2019: unresolved external symbol _imp_pthread_create referenced in function _main 1>C:\Users\rtt.PROLAN\Downloads\pthread-win32-master\Debug\Majs.exe : fatal error LNK1120: 1 unresolved externals
我从这个 source 构建了静态库。然后,我将“pthread_lib.lib”添加到项目属性中的“链接器”->“输入”。并确保该文件位于 lib 路径中。
知道是什么导致了链接器错误吗?
最佳答案
静态链接时,您必须将以下行添加到您的应用程序中。
#define PTW32_STATIC_LIB
关于c - 如何在C程序中使用静态pthread库(Visual Studio 2008)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14520090/