【发布时间】:2013-01-09 07:34:27
【问题描述】:
我得到了以下测试程序:
#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:错误 LNK2019:未解析的外部符号 _imp_pthread_create 在函数 _main 1>C:\Users\rtt.PROLAN\Downloads\pthread-win32-master\Debug\Majs.exe 中引用: 致命错误 LNK1120:1 个未解决的外部问题
我从这个source 构建了静态库。然后我将“pthread_lib.lib”添加到链接器 - >项目属性中的输入。并确保该文件位于 lib 路径中。
知道是什么导致了链接器错误吗?
【问题讨论】:
-
pthread.lib.lib 看起来很可疑。如果这不是您的问题中的错字,我会检查这是否与静态库的名称匹配。
-
顺便说一句,使用像
gcc这样的真正的C 编译器,而不是微软的C89 编译器怎么样?这样一来,像 pthread 这样的基本库已经随(几乎)符合 POSIX 标准的 gnu 库一起提供了。 -
pthread.lib.lib 不是拼写错误,它是从该源构建时的原始名称(使用包含的 Visual Studio 项目)。我已将其重命名为 pthread.lib 但决定不更改我的问题中的任何内容。
标签: c visual-studio-2008 pthreads static-libraries static-linking