|
From: Tatsh <dd...@gm...> - 2010-02-11 14:29:21
|
Googling around it seems this question has been asked a lot but I still cannot figure out exactly what is going wrong here. I have a working GCC cross-compiler. Linking to many libs works fine. $ i686-pc-mingw32-gcc -v Using built-in specs. Target: i686-pc-mingw32 Configured with: /var/tmp/portage/cross-i686-pc-mingw32/gcc-4.4.3/work/gcc-4.4.3/configure --prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/i686-pc-mingw32/gcc-bin/4.4.3 --includedir=/usr/lib/gcc/i686-pc-mingw32/4.4.3/include --datadir=/usr/share/gcc-data/i686-pc-mingw32/4.4.3 --mandir=/usr/share/gcc-data/i686-pc-mingw32/4.4.3/man --infodir=/usr/share/gcc-data/i686-pc-mingw32/4.4.3/info --with-gxx-include-dir=/usr/lib/gcc/i686-pc-mingw32/4.4.3/include/g++-v4 --host=x86_64-pc-linux-gnu --target=i686-pc-mingw32 --build=x86_64-pc-linux-gnu --disable-altivec --disable-fixed-point --without-ppl --without-cloog --enable-nls --without-included-gettext --with-system-zlib --disable-checking --disable-werror --enable-secureplt --disable-libmudflap --disable-libssp --enable-libgomp --enable-cld --with-python-dir=/share/gcc-data/i686-pc-mingw32/4.4.3/python --with-arch=i686 --enable-languages=c,c++,java,fortran --with-sysroot=/usr/i686-pc-mingw32 --disable-bootstrap --disable-libgomp --with-bugurl=http://bugs.gentoo.org/ --with-pkgversion='Gentoo 4.4.3 p1.0' Thread model: win32 gcc version 4.4.3 (Gentoo 4.4.3 p1.0) I went to the (dated) pthreads-win32 site and got the pre-built files from: ftp://sourceware.org/pub/pthreads-win32/prebuilt-dll-2-8-0-release/ Copied the following: pthread.h -> /usr/i686-pc-mingw32/usr/include sched.h -> /usr/i686-pc-mingw32/usr/include/ semaphore.h -> /usr/i686-pc-mingw32/usr/include/ libpthreadGC2.a -> /usr/i686-pc-mingw32/usr/lib libpthreadGCE2.a -> /usr/i686-pc-mingw32/usr/lib pthreadGC2.dll -> /usr/i686-pc-mingw32/usr/bin pthreadGCE2.dll -> /usr/i686-pc-mingw32/usr/bin Here is the code I found in an example I'm trying to test with (added ptw32_processInitialize()): // Start #include <pthread.h> #include <stdio.h> #include <stdlib.h> #define NUM_THREADS 5 void *print_hello(void *thread_id) { long tid; tid = (long)thread_id; printf("Thread #%ld responding.\n", tid); pthread_exit(NULL); } int main(int argc, char *argv[]) { pthread_t threads[NUM_THREADS]; int rc; long i; ptw32_processInitialize(); for (i = 0; i < NUM_THREADS; i++) { printf("In main: creating thread %ld\n", i); rc = pthread_create(&threads[i], NULL, print_hello, (void *)i); if (rc) { printf("Error: return code from pthread_create() is %d\n", rc); exit(-1); } } pthread_exit(NULL); exit(EXIT_SUCCESS); } // End Output is like this: tatsh@tatshbook:~/dev-tutorials/pthreads-win32$ i686-pc-mingw32-gcc -o example.exe -g -mthreads -DPTW32_STATIC_LIB -lpthreadGC2 example.c /tmp/cca6ndLi.o: In function `print_hello': /home/tatsh/dev-tutorials/pthreads-win32/example.c:11: undefined reference to `_pthread_exit' /tmp/cca6ndLi.o: In function `main': /home/tatsh/dev-tutorials/pthreads-win32/example.c:19: undefined reference to `_ptw32_processInitialize' /home/tatsh/dev-tutorials/pthreads-win32/example.c:22: undefined reference to `_pthread_create' /home/tatsh/dev-tutorials/pthreads-win32/example.c:28: undefined reference to `_pthread_exit' collect2: ld returned 1 exit status Without -DPTW32_STATIC_LIB then undefined references turn from _pthread_exit to __imp_pthread_exit for example. I am not sure to do. One clue was to have the call to ptw32_processInitialize() but this has just added another undefined reference. Clearly the headers are found but the linker is not finding these lib files. Thanks -- Tatsh www.tatsh.net dd...@gm... |