libtool & pthread & ilmbase

Jeremy Messenger mezz7 at cox.net
Sat Aug 29 03:35:19 UTC 2009


On Fri, 28 Aug 2009 21:18:24 -0500, Dmitry Marakasov <amdmi3 at amdmi3.ru>  
wrote:

> Hi!
>
> I've asked about this issue before, but though Daniel Eischen nicely
> explained me some stuff regarding threads, I was haven't had a clear
> idea how to fix this. Now I've ran into this again, so I'll raise this
> once more. The problem:
>
> graphics/ilmbase is built with thread support by default (see port).
> However, while libs are linked with -pthread as they should:

Search for 'nostdlib pthread' in google and you will see many results.  
Linux even has the same problem.

> libtool: link: c++ -shared -nostdlib /usr/lib/crti.o  
> /usr/lib/crtbeginS.o  .libs/IlmThreadPool.o .libs/IlmThread.o  
> .libs/IlmThreadSemaphore.o .libs/IlmThreadMutex.o .libs/IlmThreadPosix.o  
> .libs/IlmThreadSemaphorePosix.o .libs/IlmThreadSemaphorePosixCompat.o  
> .libs/IlmThreadMutexPosix.o   -Wl,-rpath  
> -Wl,/usr/home/amdmi3/projects/freebsd/ports/graphics/ilmbase/work/ilmbase-1.0.1/Iex/.libs  
> -Wl,-rpath  
> -Wl,/usr/home/amdmi3/projects/freebsd/ports/graphics/ilmbase/prefix/lib  
> ../Iex/.libs/libIex.so -pthread -L/usr/lib -lstdc++ -lm -lc -lgcc_s  
> /usr/lib/crtendS.o /usr/lib/crtn.o  -march=prescott -pthread -pthread  
> -pthread   -pthread -Wl,-soname -Wl,libIlmThread.so.6 -o  
> .libs/libIlmThread.so.6
>
> the resulting libraries have no dependency on real threading lib (-lthr):
>
> % ldd /usr/local/lib/libIlmThread.so
> /usr/local/lib/libIlmThread.so:
> 	libIex.so.6 => /usr/local/lib/libIex.so.6 (0x281b0000)
> 	libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x28300000)
> 	libm.so.5 => /lib/libm.so.5 (0x281c1000)
> 	libc.so.7 => /lib/libc.so.7 (0x2808f000)
> 	libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x281da000)
>
> thus, I won't be able to link with this library directly:
>
> % gcc 1.c -lIlmThread -L/usr/local/lib
> /usr/local/lib/libIlmThread.so: undefined reference to `pthread_create'
>
> unless I specify -pthread.
>
> While this may be expected for libIlm_Thread_, there are other
> (essentially thread-unaware) libs that depend on it.
>
> OpenEXR:
> % gcc 1.c -lIlmImf -L/usr/local/lib
> /usr/local/lib/libIlmThread.so.6: undefined reference to `pthread_create'
>
> nvidia-texture-tools (depends on OpenEXR):
> % gcc 1.c -lnvimage -L/usr/local/lib
> /usr/local/lib/libIlmThread.so.6: undefined reference to `pthread_create'
>
> DevIL (conditionally depends on nvidia-texture-tools):
> % gcc 1.c -lIL -L/usr/local/lib
> /usr/local/lib/libIlmThread.so.6: undefined reference to `pthread_create'
>
> Now, when I build CEGUI (which depends on devil), it won't really build
> DevIL plugin, as configure check for link with DevIL will fail.
>
> Finally, because of that, secretmaryochronicles segfault on startup.
> This took some time to unwind, and I want this to be fixed once and
> forever.
>
> The solutions:
> 1) Add -pthread to linker flags in ALL dependent ports.
> I think this is a no-go, as we'll then be forcing threads in too
> many ports, which are essentially thread-unaware. Also, we'll be forcing
> threads regardless of whether ilmbase is built threaded or not, also
> regardless of whether we actually depend in ilmbase or not.
> 2) Fix it in ilmbase. I believe, like this:
>
> .if ${OSVERSION} < 700041
> PTHREAD_LIBS+=  -lpthread
> .else
> PTHREAD_LIBS+=  -lthr
> .endif

Best to copy GECKO_PTHREAD's way of get library. Grep for  
GECKO_PTHREAD_LIBS in ports/Mk/bsd.gecko.mk.

# cd /usr/ports/www/firefox3
# make -V GECKO_PTHREAD_LIBS
-lpthread

Cheers,
Mezz

> this may not be so good, as only libIlmThread should be linked to
> threads actually. So another solution:
>
> 3) Fix it in OpenEXR.
> The same way as above, as just CONFIGURE_ARGS="${PTHREAD_LIBS}"
> doesn't seem to have any effect.
>
> I'm for #3. I've submitted a PR for this in April ([1]), but
> nork@ didn't respond, so I'd like to commit this after some tinderboxing
> if no one sees any additionak caveats.
>
> [1] http://www.freebsd.org/cgi/query-pr.cgi?pr=ports/133291
>



-- 
mezz7 at cox.net  -  mezz at FreeBSD.org
FreeBSD GNOME Team
http://www.FreeBSD.org/gnome/  -  gnome at FreeBSD.org


More information about the freebsd-ports mailing list