[英]How to use static pthread library in C program (Visual Studio 2008)?
I got the following test program: 我得到了以下测试程序:
#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;
}
When building, I'm getting the following errors: 在构建时,我遇到以下错误:
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
1> main.obj:错误LNK2019:未解析的外部符号_ imp _pthread_create在函数_main 1> C>中引用:C:\\ Users \\ rtt.PROLAN \\ Downloads \\ pthread-win32-master \\ Debug \\ Majs.exe:致命错误LNK1120:1未解决的外部
I built the static library from this source . 我从这个源构建了静态库。 I then added "pthread_lib.lib" to Linker -> Input in the Project properties.
然后我在项目属性中将“pthread_lib.lib”添加到Linker - > Input。 And made sure that file was in the lib path.
并确保该文件位于lib路径中。
Any idea what's causing the linker errors? 知道是什么导致了链接器错误吗?
当您静态链接时,您必须将以下行添加到您的应用程序。
#define PTW32_STATIC_LIB
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.