On Tue, Feb 17, 2009 at 6:16 AM, cnav <c...@talamasca.pl> wrote: > Jacob Meuser wrote: >> >> On Tue, Feb 17, 2009 at 09:03:18AM +0100, cnav wrote: >>> >>> Jacob Meuser wrote: >>>> >>>> On Mon, Feb 16, 2009 at 09:06:25AM -0800, patrick keshishian wrote: >>>>> >>>>> man cc >>>>> /-pthread >>>>> nn >>>>> >>>>> -pthreads >>>>> Add support for multithreading using the POSIX threads >>>>> library. This option sets flags for both the >>>>> preprocessor and linker. This option does not affect >>>>> the thread safety of object code produced by the >>>>> compiler or that of libraries supplied with it. >>>>> >>>> that doesn't answer the questions. >>>> >>>>> On Mon, Feb 16, 2009 at 5:32 AM, cnav <c...@talamasca.pl> wrote: >>>>>> >>>>>> Hi, >>>>>> >>>>>> I just applied following patch: >>>>>> http://cnav.pl/clamav-configure.patch >>>>>> >>>>>> to clamav sources. And after that libclamav seems to work with >>>>>> pthreads. >>>>>> ldd /usr/local/lib/libclamav.so.5.4 >>>>>> /usr/local/lib/libclamav.so.5.4: >>>>>> Start End Type Open Ref GrpRef Name >>>>>> 084ef000 28522000 dlib 1 0 0 >>>>>> /usr/local/lib/libclamav.so.5.4 >>>>>> 0d4b9000 2d4bd000 rlib 0 1 0 >>>>>> /usr/local/lib/libclamunrar_iface.so.5.4 >>>>>> 010a0000 210a5000 rlib 0 2 0 >>>>>> /usr/local/lib/libclamunrar.so.5.4 >>>>>> 06d89000 26d8d000 rlib 0 1 0 /usr/local/lib/libbz2.so.10.4 >>>>>> 091a8000 291af000 rlib 0 1 0 >>>>>> /usr/local/lib/libgmp.so.7.1 >>>>>> 0a04b000 2a12a000 rlib 0 1 0 /usr/local/lib/libiconv.so.5.0 >>>>>> 02484000 2248d000 rlib 0 1 0 >>>>>> /usr/lib/libpthread.so.11.0 >>>>>> 05a7c000 25a84000 rlib 0 3 0 /usr/lib/libz.so.4.1 >>>>>> >>>>>> Manuals says to use -pthread. >>>>>> http://www.openbsd.org/cgi-bin/man.cgi?query=pthreads&sektion=3 >>>>>> >>>>>> My question are: >>>>>> What is the difference between those two libs ? >>>>>> And why with -lpthread it's working and without not? >>>> >>>> -pthread won't link libpthread into shared objects, while -lpthread >>>> will. use -pthread when linking the executables that will load >>>> libclamav. >>>> >>> Thanks, >>> >>> The only one reason why i did it, is that i want to use perl module >>> mail-clamav witch is depending pthreads libraries. >>> >>> When i am compiling libclamav with -pthread instead of -lpthread: >>> The following error exists: >>> >>> Mail-ClamAV-0.22# make test >>> PERL_DL_NONLAZY=1 /usr/bin/perl "-MExtUtils::Command::MM" "-e" >>> "test_harness(0, 'blib/lib', 'blib/arch')" t/*.t >>> t/Mail-ClamAV..../usr/bin/perl:/usr/local/lib/libclamav.so.5.4: >>> undefined symbol 'pthread_create' >>> /usr/bin/perl:/usr/local/lib/libclamav.so.5.4: undefined symbol >>> 'pthread_getspecific' >>> /usr/bin/perl:/usr/local/lib/libclamav.so.5.4: undefined symbol >>> 'pthread_key_delete' >>> /usr/bin/perl:/usr/local/lib/libclamav.so.5.4: undefined symbol >>> 'pthread_once' >>> /usr/bin/perl:/usr/local/lib/libclamav.so.5.4: undefined symbol >>> 'pthread_key_create' >>> /usr/bin/perl:/usr/local/lib/libclamav.so.5.4: undefined symbol >>> 'pthread_mutex_unlock' >>> /usr/bin/perl:/usr/local/lib/libclamav.so.5.4: undefined symbol >>> 'pthread_mutex_lock' >>> /usr/bin/perl:/usr/local/lib/libclamav.so.5.4: undefined symbol >>> 'pthread_join' >>> /usr/bin/perl:/usr/local/lib/libclamav.so.5.4: undefined symbol >>> 'pthread_setspecific' >>> >>> I am aware that you maybe not familiar with mail-clamav, but libclamav >>> at least should work fine with pthreads (-pthread) correctly ? >> >> no, because libclmav is a shared object, so -pthread doesn't pull >> in libpthread. >> >>> Please, if any of you can help me understand it, it will be much >>> helpful. (Or at least can you give me some directions where to search to.) >> >> I *think* you need to change ClamAV.pm to have -pthread in LIBS like >> >> use Inline C => Config => >> VERSION => $VERSION, >> PREFIX => 'clamav_perl', >> NAME => "Maile::ClamAV", >> LIBS => "-lclamav -pthread"; >> >> but I honestly don't know much about how perl modules are supposed to >> be built. >> > > I've tried yours solution, and i stuck with similar problem: > LIBS => "-lclamav -pthread"; > Gives me this error while creating Makefile. > Unrecognized argument in LIBS ignored: '-pthread' > > And with: > LIBS => "-lclamav -lpthread"; > Is going fine and working, at least now i don't need to modify libclamav. > But still it's -lpthread
Yes. -pthread is a compiler option that tells it to include -Defines etc during the preprocessor stage and the proper -libs (e.g., -lpthread) during linker stage. My original reply was meant to indicate this, based on my understanding of what you were asking: what is the difference between -pthread and -lpthread. I don't know how the module you are trying to build is attempting to be compiled and linked. But it seems (maybe) openbsd's gcc is doing things a bit different. Here is a quick and dirty example: linux$ cc -pthread -c a.c linux$ cc -pthread a.o -shared -o liba.so -v Using built-in specs. Target: i386-redhat-linux Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-libgcj-multifile --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --enable-plugin --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre --with-cpu=generic --host=i386-redhat-linux Thread model: posix gcc version 4.1.2 20070626 (Red Hat 4.1.2-14) /usr/libexec/gcc/i386-redhat-linux/4.1.2/collect2 --eh-frame-hdr -m elf_i386 --hash-style=gnu -shared -o liba.so /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../crti.o /usr/lib/gcc/i386-redhat-linux/4.1.2/crtbeginS.o -L/usr/lib/gcc/i386-redhat-linux/4.1.2 -L/usr/lib/gcc/i386-redhat-linux/4.1.2 -L/usr/lib/gcc/i386-redhat-linux/4.1.2/../../.. a.o -lgcc --as-needed -lgcc_s --no-as-needed -lpthread -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/i386-redhat-linux/4.1.2/crtendS.o /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../crtn.o linux$ ldd liba.so linux-gate.so.1 => (0x0087c000) libpthread.so.0 => /lib/libpthread.so.0 (0x0069d000) libc.so.6 => /lib/libc.so.6 (0x00505000) /lib/ld-linux.so.2 (0x00461000) obsd$ cc -pthread -c a.c obsd$ cc -pthread a.o -shared -o liba.so -v Reading specs from /usr/lib/gcc-lib/powerpc-unknown-openbsd4.4/3.3.5/specs Configured with: Thread model: single gcc version 3.3.5 (propolice) ld --eh-frame-hdr -shared -o liba.so /usr/lib/crtbeginS.o -L/usr/lib/gcc-lib/powerpc-unknown-openbsd4.4/3.3.5 a.o -lgcc -lgcc /usr/lib/gcc-lib/powerpc-unknown-openbsd4.4/3.3.5/crtsavres.o /usr/lib/crtendS.o obsd$ ldd liba.so liba.so: Start End Type Open Ref GrpRef Name 314bc000 3151e000 dlib 1 0 0 /tmp/liba.so Note the missing -lpthread in the linker argument list in obsd. However, if we try to make an executable -lpthread is added to the linker argument list. obsd$ cc -pthread -c b.c obsd$ cc -pthread b.o -L. -la -v Reading specs from /usr/lib/gcc-lib/powerpc-unknown-openbsd4.4/3.3.5/specs Configured with: Thread model: single gcc version 3.3.5 (propolice) ld --eh-frame-hdr -dynamic-linker /usr/libexec/ld.so /usr/lib/crt0.o /usr/lib/crtbegin.o -L. -L/usr/lib/gcc-lib/powerpc-unknown-openbsd4.4/3.3.5 b.o -la -lgcc -lpthread -lc -lgcc /usr/lib/gcc-lib/powerpc-unknown-openbsd4.4/3.3.5/crtsavres.o /usr/lib/crtend.o obsd$ env LD_LIBRARY_PATH=. ldd a.out a.out: Start End Type Open Ref GrpRef Name 01800000 01862000 exe 1 0 0 a.out 30ccd000 30d2f000 rlib 0 1 0 ./liba.so 2208b000 2210a000 rlib 0 1 0 /usr/lib/libpthread.so.11.1 29430000 29569000 rlib 0 1 0 /usr/lib/libc.so.50.1 2d7e0000 2d7e0000 rtld 0 1 0 /usr/libexec/ld.so There is obviously a difference in the two compiler versions and also archs, but I'm not sure if that accounts for the missing -lpthread in the linker stage when creating a .so. --patrick