On Sat, Feb 19, 2011 at 7:55 PM, Mark Himsley <mark@mdsh.com> wrote:
On 18/02/2011 20:47, Leo Izen wrote:
> I'm getting pthread linker errors when building libschroedinger for
> mingw32. This is my configure line:
>
> ./configure --with-thread=pthread --with-gnu-ld --disable-gtk-doc
> --enable-static --disable-shared --host=x86_64-w64-mingw32
> --prefix=/usr/local/x86_64-w64-mingw32
>
> I'm not using --with-thread=win32 because my frontend uses pthreads. I
> don't want any type of answer even remotely close to "use win32
> threads." I'm using pthreads. Period.

I agree, if I use this configure command then cd into the schroedinger
sub-directory and make && sudo make install (since all I want is the
libraries) I get a library built and installed.

PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig \
CPPFLAGS="-I/usr/i586-mingw32msvc/include -I$PREFIX/include" \
LDFLAGS="-L/usr/i586-mingw32msvc/lib -L$PREFIX/lib" \
./configure \
       --prefix=$PREFIX \
       --host=i586-mingw32msvc \
       --enable-static \
       --disable-shared \
       --with-thread=pthread

But, maybe I'm showing my ignorance in static library building, I would
not expect the undefined symbols in libschroedinger-1.0.a to be prefixed
with __imp_. They look like they are for dynamic linking.

Yea, I figured it out. Just add -DPTW32_STATIC_LIB to your CPPFLAGS (or CFLAGS).
This will remove the dllimport stuff that causes the __imp_.
 

$ i586-mingw32msvc-nm $PREFIX/lib/libschroedinger-1.0.a | grep "__imp_"
        U __imp___iob
        U __imp__pthread_attr_destroy
        U __imp__pthread_attr_init
        U __imp__pthread_cond_broadcast
        U __imp__pthread_cond_init
        U __imp__pthread_cond_signal
        U __imp__pthread_cond_timedwait
        U __imp__pthread_cond_wait
        U __imp__pthread_condattr_destroy
        U __imp__pthread_condattr_init
        U __imp__pthread_create
        U __imp__pthread_getspecific
        U __imp__pthread_join
        U __imp__pthread_key_create
        U __imp__pthread_mutex_destroy
        U __imp__pthread_mutex_init
        U __imp__pthread_mutex_lock
        U __imp__pthread_mutex_unlock
        U __imp__pthread_mutexattr_destroy
        U __imp__pthread_mutexattr_init
        U __imp__pthread_setspecific


> It compiles just fine, but this is the linker error:
>
> libtool: link: x86_64-w64-mingw32-gcc -Wall -Werror -I..
> -I/usr/include/orc-0.4 -DSCHRO_ENABLE_UNSTABLE_API -w -O3 -o arith.exe
> arith.o  -L/usr/local/x86_64-w64-mingw32/lib ./.libs/libschrotest.a
> /home/Leo/ffmpeg-w64/libschroedinger/schroedinger/.libs/libschroedinger-1.0.a
> ../schroedinger/.libs/libschroedinger-1.0.a
> /usr/bin/../lib/gcc/x86_64-w64-mingw32/4.6.0/../../../../x86_64-w64-mingw32/lib/../lib/libstdc++.dll.a
> -lpthread /usr/local/x86_64-w64-mingw32/lib/liborc-test-0.4.a
> /usr/local/x86_64-w64-mingw32/lib/liborc-0.4.a
> -L/usr/bin/../lib/gcc/x86_64-w64-mingw32/4.6.0/../../../../x86_64-w64-mingw32/lib/../lib
> -L/usr/bin/../lib/gcc/x86_64-w64-mingw32/4.6.0/../../../../x86_64-w64-mingw32/lib/../lib
> /home/Leo/ffmpeg-w64/libschroedinger/schroedinger/.libs/libschroedinger-1.0.a(libschroedinger_1.0_la-schroasync-pthread.o):schroasync-pthread.c:(.text+0x23):
> undefined reference to `__imp_pthread_setspecific'
> /home/Leo/ffmpeg-w64/libschroedinger/schroedinger/.libs/libschroedinger-1.0.a(libschroedinger_1.0_la-schroasync-pthread.o):schroasync-pthread.c:(.text+0x2a):
> undefined reference to `__imp_pthread_cond_signal'
> /home/Leo/ffmpeg-w64/libschroedinger/schroedinger/.libs/libschroedinger-1.0.a(libschroedinger_1.0_la-schroasync-pthread.o):schroasync-pthread.c:(.text+0x31):
> undefined reference to `__imp_pthread_cond_wait'
> /home/Leo/ffmpeg-w64/libschroedinger/schroedinger/.libs/libschroedinger-1.0.a(libschroedinger_1.0_la-schroasync-pthread.o):schroasync-pthread.c:(.text+0x73):
> undefined reference to `__imp_pthread_mutex_unlock'
> /home/Leo/ffmpeg-w64/libschroedinger/schroedinger/.libs/libschroedinger-1.0.a(libschroedinger_1.0_la-schroasync-pthread.o):schroasync-pthread.c:(.text+0x18a):
> undefined reference to `__imp_pthread_cond_wait'
> /home/Leo/ffmpeg-w64/libschroedinger/schroedinger/.libs/libschroedinger-1.0.a(libschroedinger_1.0_la-schroasync-pthread.o):schroasync-pthread.c:(.text+0x20d):
> undefined reference to `__imp_pthread_mutex_unlock'
> /home/Leo/ffmpeg-w64/libschroedinger/schroedinger/.libs/libschroedinger-1.0.a(libschroedinger_1.0_la-schroasync-pthread.o):schroasync-pthread.c:(.text+0x27e):
> undefined reference to `__imp_pthread_mutex_lock'
> /home/Leo/ffmpeg-w64/libschroedinger/schroedinger/.libs/libschroedinger-1.0.a(libschroedinger_1.0_la-schroasync-pthread.o):schroasync-pthread.c:(.text+0x351):
> undefined reference to `__imp_pthread_mutexattr_init'
> /home/Leo/ffmpeg-w64/libschroedinger/schroedinger/.libs/libschroedinger-1.0.a(libschroedinger_1.0_la-schroasync-pthread.o):schroasync-pthread.c:(.text+0x35f):
> undefined reference to `__imp_pthread_mutex_init'
> /home/Leo/ffmpeg-w64/libschroedinger/schroedinger/.libs/libschroedinger-1.0.a(libschroedinger_1.0_la-schroasync-pthread.o):schroasync-pthread.c:(.text+0x36a):
> undefined reference to `__imp_pthread_condattr_init'
> /home/Leo/ffmpeg-w64/libschroedinger/schroedinger/.libs/libschroedinger-1.0.a(libschroedinger_1.0_la-schroasync-pthread.o):schroasync-pthread.c:(.text+0x37a):
> undefined reference to `__imp_pthread_cond_init'
> /home/Leo/ffmpeg-w64/libschroedinger/schroedinger/.libs/libschroedinger-1.0.a(libschroedinger_1.0_la-schroasync-pthread.o):schroasync-pthread.c:(.text+0x3a2):
> undefined reference to `__imp_pthread_attr_init'
> /home/Leo/ffmpeg-w64/libschroedinger/schroedinger/.libs/libschroedinger-1.0.a(libschroedinger_1.0_la-schroasync-pthread.o):schroasync-pthread.c:(.text+0x3ac):
> undefined reference to `__imp_pthread_mutex_lock'
> /home/Leo/ffmpeg-w64/libschroedinger/schroedinger/.libs/libschroedinger-1.0.a(libschroedinger_1.0_la-schroasync-pthread.o):schroasync-pthread.c:(.text+0x3ba):
> undefined reference to `__imp_pthread_create'
> /home/Leo/ffmpeg-w64/libschroedinger/schroedinger/.libs/libschroedinger-1.0.a(libschroedinger_1.0_la-schroasync-pthread.o):schroasync-pthread.c:(.text+0x3ff):
> undefined reference to `__imp_pthread_mutex_unlock'
> /home/Leo/ffmpeg-w64/libschroedinger/schroedinger/.libs/libschroedinger-1.0.a(libschroedinger_1.0_la-schroasync-pthread.o):schroasync-pthread.c:(.text+0x40a):
> undefined reference to `__imp_pthread_attr_destroy'
> /home/Leo/ffmpeg-w64/libschroedinger/schroedinger/.libs/libschroedinger-1.0.a(libschroedinger_1.0_la-schroasync-pthread.o):schroasync-pthread.c:(.text+0x415):
> undefined reference to `__imp_pthread_mutexattr_destroy'
> /home/Leo/ffmpeg-w64/libschroedinger/schroedinger/.libs/libschroedinger-1.0.a(libschroedinger_1.0_la-schroasync-pthread.o):schroasync-pthread.c:(.text+0x420):
> undefined reference to `__imp_pthread_condattr_destroy'
> /home/Leo/ffmpeg-w64/libschroedinger/schroedinger/.libs/libschroedinger-1.0.a(libschroedinger_1.0_la-schroasync-pthread.o):schroasync-pthread.c:(.text+0x49d):
> undefined reference to `__imp_pthread_key_create'
> /home/Leo/ffmpeg-w64/libschroedinger/schroedinger/.libs/libschroedinger-1.0.a(libschroedinger_1.0_la-schroasync-pthread.o):schroasync-pthread.c:(.text+0x4f8):
> undefined reference to `__imp_pthread_mutex_lock'
> /home/Leo/ffmpeg-w64/libschroedinger/schroedinger/.libs/libschroedinger-1.0.a(libschroedinger_1.0_la-schroasync-pthread.o):schroasync-pthread.c:(.text+0x50f):
> undefined reference to `__imp_pthread_cond_signal'
> /home/Leo/ffmpeg-w64/libschroedinger/schroedinger/.libs/libschroedinger-1.0.a(libschroedinger_1.0_la-schroasync-pthread.o):schroasync-pthread.c:(.text+0x516):
> undefined reference to `__imp_pthread_cond_wait'
> /home/Leo/ffmpeg-w64/libschroedinger/schroedinger/.libs/libschroedinger-1.0.a(libschroedinger_1.0_la-schroasync-pthread.o):schroasync-pthread.c:(.text+0x53e):
> undefined reference to `__imp_pthread_mutex_unlock'
> /home/Leo/ffmpeg-w64/libschroedinger/schroedinger/.libs/libschroedinger-1.0.a(libschroedinger_1.0_la-schroasync-pthread.o):schroasync-pthread.c:(.text+0x54d):
> undefined reference to `__imp_pthread_join'
> /home/Leo/ffmpeg-w64/libschroedinger/schroedinger/.libs/libschroedinger-1.0.a(libschroedinger_1.0_la-schroasync-pthread.o):schroasync-pthread.c:(.text+0x5b7):
> undefined reference to `__imp_pthread_cond_broadcast'
> /home/Leo/ffmpeg-w64/libschroedinger/schroedinger/.libs/libschroedinger-1.0.a(libschroedinger_1.0_la-schroasync-pthread.o):schroasync-pthread.c:(.text+0x5eb):
> undefined reference to `__imp_pthread_mutex_lock'
> /home/Leo/ffmpeg-w64/libschroedinger/schroedinger/.libs/libschroedinger-1.0.a(libschroedinger_1.0_la-schroasync-pthread.o):schroasync-pthread.c:(.text+0x5fa):
> undefined reference to `__imp_pthread_cond_wait'
> /home/Leo/ffmpeg-w64/libschroedinger/schroedinger/.libs/libschroedinger-1.0.a(libschroedinger_1.0_la-schroasync-pthread.o):schroasync-pthread.c:(.text+0x615):
> undefined reference to `__imp_pthread_mutex_unlock'
> /home/Leo/ffmpeg-w64/libschroedinger/schroedinger/.libs/libschroedinger-1.0.a(libschroedinger_1.0_la-schroasync-pthread.o):schroasync-pthread.c:(.text+0x649):
> undefined reference to `__imp_pthread_cond_broadcast'
> /home/Leo/ffmpeg-w64/libschroedinger/schroedinger/.libs/libschroedinger-1.0.a(libschroedinger_1.0_la-schroasync-pthread.o):schroasync-pthread.c:(.text+0x6d1):
> undefined reference to `__imp_pthread_cond_timedwait'
> /home/Leo/ffmpeg-w64/libschroedinger/schroedinger/.libs/libschroedinger-1.0.a(libschroedinger_1.0_la-schroasync-pthread.o):schroasync-pthread.c:(.text+0x807):
> undefined reference to `__imp_pthread_mutex_lock'
> /home/Leo/ffmpeg-w64/libschroedinger/schroedinger/.libs/libschroedinger-1.0.a(libschroedinger_1.0_la-schroasync-pthread.o):schroasync-pthread.c:(.text+0x827):
> undefined reference to `__imp_pthread_mutex_unlock'
> /home/Leo/ffmpeg-w64/libschroedinger/schroedinger/.libs/libschroedinger-1.0.a(libschroedinger_1.0_la-schroasync-pthread.o):schroasync-pthread.c:(.text+0x847):
> undefined reference to `__imp_pthread_cond_broadcast'
> /home/Leo/ffmpeg-w64/libschroedinger/schroedinger/.libs/libschroedinger-1.0.a(libschroedinger_1.0_la-schroasync-pthread.o):schroasync-pthread.c:(.text+0x871):
> undefined reference to `__imp_pthread_mutex_lock'
> /home/Leo/ffmpeg-w64/libschroedinger/schroedinger/.libs/libschroedinger-1.0.a(libschroedinger_1.0_la-schroasync-pthread.o):schroasync-pthread.c:(.text+0x8cf):
> undefined reference to `__imp_pthread_attr_init'
> /home/Leo/ffmpeg-w64/libschroedinger/schroedinger/.libs/libschroedinger-1.0.a(libschroedinger_1.0_la-schroasync-pthread.o):schroasync-pthread.c:(.text+0x8f7):
> undefined reference to `__imp_pthread_create'
> /home/Leo/ffmpeg-w64/libschroedinger/schroedinger/.libs/libschroedinger-1.0.a(libschroedinger_1.0_la-schroasync-pthread.o):schroasync-pthread.c:(.text+0x905):
> undefined reference to `__imp_pthread_mutex_unlock'
> /home/Leo/ffmpeg-w64/libschroedinger/schroedinger/.libs/libschroedinger-1.0.a(libschroedinger_1.0_la-schroasync-pthread.o):schroasync-pthread.c:(.text+0x910):
> undefined reference to `__imp_pthread_attr_destroy'
> /home/Leo/ffmpeg-w64/libschroedinger/schroedinger/.libs/libschroedinger-1.0.a(libschroedinger_1.0_la-schroasync-pthread.o):schroasync-pthread.c:(.text+0x93d):
> undefined reference to `__imp_pthread_getspecific'
> /home/Leo/ffmpeg-w64/libschroedinger/schroedinger/.libs/libschroedinger-1.0.a(libschroedinger_1.0_la-schroasync-pthread.o):schroasync-pthread.c:(.text+0x969):
> undefined reference to `__imp_pthread_mutexattr_init'
> /home/Leo/ffmpeg-w64/libschroedinger/schroedinger/.libs/libschroedinger-1.0.a(libschroedinger_1.0_la-schroasync-pthread.o):schroasync-pthread.c:(.text+0x977):
> undefined reference to `__imp_pthread_mutex_init'
> /home/Leo/ffmpeg-w64/libschroedinger/schroedinger/.libs/libschroedinger-1.0.a(libschroedinger_1.0_la-schroasync-pthread.o):schroasync-pthread.c:(.text+0x982):
> undefined reference to `__imp_pthread_mutexattr_destroy'
> /home/Leo/ffmpeg-w64/libschroedinger/schroedinger/.libs/libschroedinger-1.0.a(libschroedinger_1.0_la-schroasync-pthread.o):schroasync-pthread.c:(.text+0x997):
> undefined reference to `__imp_pthread_mutex_lock'
> /home/Leo/ffmpeg-w64/libschroedinger/schroedinger/.libs/libschroedinger-1.0.a(libschroedinger_1.0_la-schroasync-pthread.o):schroasync-pthread.c:(.text+0x9b7):
> undefined reference to `__imp_pthread_mutex_unlock'
> /home/Leo/ffmpeg-w64/libschroedinger/schroedinger/.libs/libschroedinger-1.0.a(libschroedinger_1.0_la-schroasync-pthread.o):schroasync-pthread.c:(.text+0x9da):
> undefined reference to `__imp_pthread_mutex_destroy'
> collect2: ld returned 1 exit status
> make[3]: *** [arith.exe] Error 1
> make[3]: Leaving directory `/home/Leo/ffmpeg-w64/libschroedinger/testsuite'
> make[2]: *** [all-recursive] Error 1
> make[2]: Leaving directory `/home/Leo/ffmpeg-w64/libschroedinger/testsuite'
> make[1]: *** [all-recursive] Error 1
> make[1]: Leaving directory `/home/Leo/ffmpeg-w64/libschroedinger'
> make: *** [all] Error 2
>
> When I run x86_64-w64-mingw32-nm on
> libschroedinger_1.0_la-schroasync-pthread.o, it does show those symbols
> with a U (undefined). However all the symbols are in libpthread.a except
> without the __imp_ in the front i.e. in libpthread.a there's
> pthread_join, not __imp_pthread_join.
>
> 1. Are these undefined symbols actually trying to reference the ones
> without the __imp_ at the beginning?
> 2. I couldn't fine these defined anywhere, so doing find-and-replace on
> the source code is a little difficult.
> 3. How can I make it so it is actually referencing the symbols in
> libpthread.a (e.g. pthread_join) and not these undefined things (e.g.
> __imp_pthread_join). I already tried adding -DNO_PREFIX to CPPFLAGS and
> CFLAGS before configure, then re-configuring. That didn't work.
>
> Thanx.
>