libboost_regex, FreeBSD problems

Hi, I did some development with libboost_regex-gcc.so (1.31.0) on a Linux platform: no problems. However, when I try to compile on FreeBSD, I get the following errors: g++ -o myprog Unit1.o Unit2.o /usr/local/lib/libboost_regex-gcc.so /usr/local/lib/libboost_regex-gcc.so: undefined reference to 'pthread_mutex_unlock' /usr/local/lib/libboost_regex-gcc.so: undefined reference to 'pthread_mutex_destroy' /usr/local/lib/libboost_regex-gcc.so: undefined reference to 'pthread_mutex_lock' /usr/local/lib/libboost_regex-gcc.so: undefined reference to 'pthread_mutex_init' I've installed Boost on the FreeBSD platform using both the ports package available from freebsd.org and the source from boost.org. Both yield the same results. Any ideas appreciated, as I am not that experienced with C++, Boost, and cross-platform deployment. Thanks, Steve

Steve Bobrowski wrote:
Hi,
I did some development with libboost_regex-gcc.so (1.31.0) on a Linux platform: no problems. However, when I try to compile on FreeBSD, I get the following errors:
g++ -o myprog Unit1.o Unit2.o /usr/local/lib/libboost_regex-gcc.so
/usr/local/lib/libboost_regex-gcc.so: undefined reference to 'pthread_mutex_unlock' /usr/local/lib/libboost_regex-gcc.so: undefined reference to 'pthread_mutex_destroy' /usr/local/lib/libboost_regex-gcc.so: undefined reference to 'pthread_mutex_lock' /usr/local/lib/libboost_regex-gcc.so: undefined reference to 'pthread_mutex_init'
I've installed Boost on the FreeBSD platform using both the ports package available from freebsd.org and the source from boost.org. Both yield the same results.
Any ideas appreciated, as I am not that experienced with C++, Boost, and cross-platform deployment.
Yes... Seems that it's requiring thread support so... Either add the "-pthread" option to your compiles (and links) manually, or use a build system tool that adds it for you (like Boost.Build). -- -- Grafik - Don't Assume Anything -- Redshift Software, Inc. - http://redshift-software.com -- rrivera/acm.org - grafik/redshift-software.com - 102708583/icq

On Thu, Jul 29, 2004 at 11:25:49AM +0100, John Maddock wrote:
Either add the "-pthread" option to your compiles (and links) manually, or use a build system tool that adds it for you (like Boost.Build).
There isn't a -pthread option on BSD, it's spelled -lpthread :-)
Are you sure? $ uname FreeBSD $ gcc -pthread gcc: No input files specified $ gcc -pthreads gcc: unrecognized option `-pthreads' gcc: No input files specified $ gcc -lpthread /usr/libexec/elf/ld: cannot find -lpthread $ locate libpthread /usr/compat/linux/lib/libpthread-0.9.so /usr/compat/linux/lib/libpthread.so.0 libpthread doesn't exist on most FreeBSD systems, unless (as above) as part of the linux compatibility runtime, used when running linux executables). Instead the pthread_* functions are contained in a reentrant version of libc: libc_r. For GCC 3 on FreeBSD when -pthread is given then the linker is passed -lc_r (to link to the reentrant version of libc) and when -pthread is absent the linker is passed -lc (the non-reentrant libc). (It's slightly complicated by the absence/presence of -pg, as there are also profiling versions of libc, so you end up with one of libc, libc_r, libc_p, or libc_r_p) The behaviour seems to be the same on GCC 2.95 though I haven't checked the source to confirm that. jon -- Dull but sincere filler

There isn't a -pthread option on BSD, it's spelled -lpthread :-)
Are you sure?
$ uname FreeBSD $ gcc -pthread gcc: No input files specified $ gcc -pthreads gcc: unrecognized option `-pthreads' gcc: No input files specified $ gcc -lpthread /usr/libexec/elf/ld: cannot find -lpthread $ locate libpthread /usr/compat/linux/lib/libpthread-0.9.so /usr/compat/linux/lib/libpthread.so.0
libpthread doesn't exist on most FreeBSD systems, unless (as above) as part of the linux compatibility runtime, used when running linux executables). Instead the pthread_* functions are contained in a reentrant version of libc: libc_r.
For GCC 3 on FreeBSD when -pthread is given then the linker is passed -lc_r (to link to the reentrant version of libc) and when -pthread is absent the linker is passed -lc (the non-reentrant libc).
(It's slightly complicated by the absence/presence of -pg, as there are also profiling versions of libc, so you end up with one of libc, libc_r, libc_p, or libc_r_p)
The behaviour seems to be the same on GCC 2.95 though I haven't checked the source to confirm that.
You're right! Serves me right for relying on memory, I take it all back, -pthread is the option to use. Thanks! John.

I did some development with libboost_regex-gcc.so (1.31.0) on a Linux platform: no problems. However, when I try to compile on FreeBSD, I get the following errors:
g++ -o myprog Unit1.o Unit2.o /usr/local/lib/libboost_regex-gcc.so
/usr/local/lib/libboost_regex-gcc.so: undefined reference to 'pthread_mutex_unlock' /usr/local/lib/libboost_regex-gcc.so: undefined reference to 'pthread_mutex_destroy' /usr/local/lib/libboost_regex-gcc.so: undefined reference to 'pthread_mutex_lock' /usr/local/lib/libboost_regex-gcc.so: undefined reference to 'pthread_mutex_init'
I've installed Boost on the FreeBSD platform using both the ports package available from freebsd.org and the source from boost.org. Both yield the same results.
Any ideas appreciated, as I am not that experienced with C++, Boost, and cross-platform deployment.
gcc on FreeBSD is set up thread safe by default, so regex is as well, just add -lpthread to the link command line (alternatively you could rebuild everything with -DBOOST_DISABLE_THREADS). John.
participants (4)
-
John Maddock
-
Jonathan Wakely
-
Rene Rivera
-
Steve Bobrowski