For some time I’ve been trying to get amavisd-new to play nicely with ClamAV using Mail::ClamAV under FreeBSD. It just would not behave – I would get an error like /usr/local/lib/libclamav.so.1: undefined reference to pthread_mutex_create() and fall over. (This error message would only appear if amavisd-new was being run in debug mode; otherwise, mail would just silently fail to be delivered and queue forever.)
Well, I finally discovered the problem: Perl is not built multithreaded by default on FreeBSD! 🙁 You have to build Perl, defining WITH_THREADS and this will work.
Obviously this isn’t apparent from the above error message. It looks like ClamAV is the culprit, rather than the ClamAV.so that’s built by Mail::ClamAV. I guess it’s just because in the course of using the ClamAV API, libclamav.so.1 is the caller, so the runtime link problem is wrongly attributed to it.
It is very apparent from the error message. Here is how:
1. There is an undefined reference to pthread_mutex_create().
2. So where is pthread_mutex_create() defined? In the pthread lib.
3. The executable that you are running is amavisd-new, which is actually Perl. So when the Perl binary is executed, the runtime linker can't find pthread_mutex_create(), leading to the "undefined reference" error.
4. So clearly Perl was not linked with the threading library, which "perl -V" would have confirmed.