News:

Re-organized the forum to more cleanly delineate the development section, as the end user support side appears to have taken a life of its own!

Author Topic: Compiling ServFox or other Threaded Applications tip  (Read 3812 times)

  • No avatar
  • *****
February 16, 2011, 05:28:54 pm
If you take a look at the ServFox source, you'll notice that it uses pthreads.
This is a threading library that is provided in the BSP distribution (in uClinux-dist/lib/lib/libpthread.a)

Unfortunately, it doesn't compile well at all with the default gcc 3.0, and gcc complains about missing pthread header function bits.

Code: [Select]
make
arm-elf-gcc -O2 -DLINUX  -c -o server.o server.c
arm-elf-gcc -O2 -DLINUX  -c -o spcav4l.o spcav4l.c
arm-elf-gcc -O2 -DLINUX  -c -o utils.o utils.c
arm-elf-gcc -O2 -DLINUX  -c -o tcputils.o tcputils.c
arm-elf-gcc -O2 -DLINUX  -o servfox server.o spcav4l.o utils.o tcputils.o  -lpthread
/usr/local/arm_tools/bin/../lib/gcc-lib/arm-elf/3.0/../../../../arm-elf/lib/libpthread.a(join.o): In function `pthread_exit':
join.o(.text+0x190): undefined reference to `thcfg'
/usr/local/arm_tools/bin/../lib/gcc-lib/arm-elf/3.0/../../../../arm-elf/lib/libpthread.a(join.o): In function `$a':
join.o(.text+0x25c): undefined reference to `thcfg'
/usr/local/arm_tools/bin/../lib/gcc-lib/arm-elf/3.0/../../../../arm-elf/lib/libpthread.a(join.o): In function `pthread_join':
join.o(.text+0x48c): undefined reference to `thcfg'
/usr/local/arm_tools/bin/../lib/gcc-lib/arm-elf/3.0/../../../../arm-elf/lib/libpthread.a(join.o): In function `pthread_detach':
join.o(.text+0x600): undefined reference to `thcfg'
/usr/local/arm_tools/bin/../lib/gcc-lib/arm-elf/3.0/../../../../arm-elf/lib/libpthread.a(manager.o): In function `pthread_allocate_stack':
manager.o(.text+0x4d4): undefined reference to `thcfg'
/usr/local/arm_tools/bin/../lib/gcc-lib/arm-elf/3.0/../../../../arm-elf/lib/libpthread.a(manager.o)(.text+0x854): more undefined references to `thcfg' follow
collect2: ld returned 1 exit status
make: *** [servfox] Error 1

Hmm, lets have a quick look at our compiler.

Code: [Select]
arm-elf-gcc -v
Reading specs from /usr/local/arm_tools/bin/../lib/gcc-lib/arm-elf/3.0/specs
Configured with: ../gcc-3.0/configure --target=arm-elf --host=i686-pc-linux --build=i686-pc-linux --prefix=/home/clyu2/gcc3.0/arm_com --with-gnu-ld --with-gnu-as : (reconfigured) ../gcc-3.0/configure --target=arm-elf --host=i686-pc-linux --build=i686-pc-linux --prefix=/home/clyu2/gcc3.0/arm_com --with-gnu-ld --with-gnu-as --with-newlib : (reconfigured) ../gcc-3.0/configure --target=arm-elf --host=i686-pc-linux --build=i686-pc-linux --prefix=/home/clyu2/gcc3.0/arm_com --with-gnu-ld --with-gnu-as --with-newlib : (reconfigured) ../gcc-3.0/configure --target=arm-elf --host=i686-pc-linux --build=i686-pc-linux --prefix=/home/clyu2/gcc3.0/arm_com --with-gnu-ld --with-gnu-as --with-newlib : (reconfigured) ../gcc-3.0/configure --target=arm-elf --host=i686-pc-linux --build=i686-pc-linux --prefix=/home/clyu2/gcc3.0/arm_com --with-gnu-ld --with-gnu-as --with-newlib : (reconfigured) ../gcc-3.0/configure --target=arm-elf --host=i686-pc-linux --build=i686-pc-linux --prefix=/home/clyu2/gcc3.0/arm_com --with-gnu-ld --with-gnu-as --with-newlib : (reconfigured) ../gcc-3.0/configure --target=arm-elf --host=i686-pc-linux --build=i686-pc-linux --prefix=/home/clyu2/gcc3.0/arm_com --with-gnu-ld --with-gnu-as --with-newlib : (reconfigured) ../gcc-3.0/configure --target=arm-elf --host=i686-pc-linux --build=i686-pc-linux --prefix=/home/clyu2/gcc3.0/arm_com --with-gnu-ld --with-gnu-as --with-newlib : (reconfigured) ../gcc-3.0/configure --target=arm-elf --host=i686-pc-linux --build=i686-pc-linux --prefix=/home/clyu2/gcc3.0/arm_com --with-gnu-ld --with-gnu-as --with-newlib
Thread model: single
gcc version 3.0

Any bonus points for working out what the issue is?  Hint, our Thread model could be an issue ;)
Thats what you get when you use the default toolchains from a BSP, sigh..


What to do?

Use our gcc 3.3.4 compiler!


Remember to make clean first, so that the borked .o files are gone, and run gcc (3.3.4)

Code: [Select]
make clean
Cleaning up directory.
rm -f *.a *.o servfox   core *~ log errlog
minty servfox # make
arm-elf-gcc -O2 -DLINUX  -c -o server.o server.c
arm-elf-gcc -O2 -DLINUX  -c -o spcav4l.o spcav4l.c
arm-elf-gcc -O2 -DLINUX  -c -o utils.o utils.c
arm-elf-gcc -O2 -DLINUX  -c -o tcputils.o tcputils.c
arm-elf-gcc -O2 -DLINUX  -o servfox server.o spcav4l.o utils.o tcputils.o  -lpthread

Nice and clean with 3.3.4!

Code: [Select]
arm-elf-gcc -v
Reading specs from /usr/local/arm_tools_3.3.4/bin/../lib/gcc-lib/arm-elf/3.3.4/specs
Configured with: /Temp/make-compile/arm-tool/gcc-3.3.4/configure --target=arm-elf --prefix=/Temp/make-compile/arm_tools_3.3.4 --enable-languages=c,c++ --enable-target-optspace --with-gnu-ld --with-local-prefix=/Temp/make-compile/arm_tools_3.3.4/arm-elf --disable-nls --disable-__cxa_atexit --enable-c99 --enable-long-long --disable-clocale --disable-c-mbchar --enable-static --disable-shared --enable-threads=posix --enable-cxx-flags="-D_ISOC99_SOURCE -D_BSD_SOURCE"
Thread model: posix
gcc version 3.3.4

No thread problems now!