c - 如何在C程序中使用静态pthread库(Visual Studio 2008)?

标签 c visual-studio-2008 pthreads static-libraries static-linking

我得到了以下测试程序:

#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/

相关文章:

c - posix线程内存消耗

C算术表达式与printf不一致并赋值给另一个变量

asp.net-mvc - 在 ASP.NET MVC RC1 中对强类型 View 使用“添加 View ”对话框时出现问题

c++ - 在 Visual Studio 2008 中制作 .exe

c - Raspberry PI 上的多线程 C 程序

linux - Linux 上的 msemaphore?

c - 如果 srand() 采用 32 位整数... 为什么 rand() 不返回相同值?

c - 使用 Lua 注册一个闭包

C : Making sure the element you return from an array is correct

c++ - Visual Studio 停止调试时真的可以不清理吗?