2
votes

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?

1
pthread.lib.lib looks suspicious. If that's not a typo in your question, I'd check this really matches the name of the static library.simonc
On a side note, how about using a real C compiler like gcc, instead of microsoft's c compiler which is still C89? With that, such basic libraries as pthread already come with the (almost-)POSIX-compliant gnu libraries.Shahbaz
pthread.lib.lib was not a typo, it's the original name when building from that source (using the included visual studio project). I've renamed it to pthread.lib but decided not to change anything in my question.Reimund

1 Answers

4
votes

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

#define PTW32_STATIC_LIB