简体   繁体   English

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

[英]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.

相关问题 如何使用visual studio 2008重新初始化静态C库中的所有全局变量? - How can I reinitialize all global variables in a static C library using visual studio 2008? 如何在VIsual Studio C ++ 2008中使用本地时间功能 - how to use localtime function with VIsual Studio C++ 2008 如何使用 gettimeofday() 或与 Visual Studio C++ 2008 等效的东西? - how to use gettimeofday() or something equivalent with Visual Studio C++ 2008? 如何为Visual Studio 2005安装pthread_win32(Windows pthread / posix线程库)? - How do I install pthread_win32 (Windows pthread / posix thread library) for Visual Studio 2005? 如何在Visual Studio 2008中使用Unix库 - how to use unix libraries in visual studio 2008 如何在Visual Studio 2008中使用.a lib文件? - How to use .a lib files with Visual Studio 2008? 如何在Visual Studio 2008中编译C代码? - How to compile C code in Visual Studio 2008? 如何在 Visual Studio 代码中使用 C++ 中的安装库? - how to use install library in c++ in visual studio code? 如何使用“静态链接”和“动态链接”与gcc和Visual Studio构建C / C ++程序? - How can I build a C/C++ program using `static linking` & `Dynamic linking` with gcc & Visual studio? 如何在Visual Studio中查找静态c / c ++库中的哪些函数 - How to find which functions are in a static c/c++ library in Visual Studio
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM