Reimund
Reimund

Reputation: 2375

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

I built the static library from this source. I then added "pthread_lib.lib" to Linker -> Input in the Project properties. And made sure that file was in the lib path.

Any idea what's causing the linker errors?

Upvotes: 2

Views: 2884

Answers (1)

Reimund
Reimund

Reputation: 2375

You have to add the following line to your application when you're linking statically.

#define PTW32_STATIC_LIB

Upvotes: 4

Related Questions