Boost logo

Boost :

Subject: Re: [boost] building a run-time static version
From: Lorenzo Bettini (bettini_at_[hidden])
Date: 2009-08-19 15:17:35


Vladimir Prus wrote:
> Lorenzo Bettini wrote:
>
>> still problems (please read below)
>
>> If I do (thus, using the .a file directly)
>>
>> g++ regex_use.o $HOME/boost/lib/libboost_regex.a -o regex_use_static
>>
>> I don't get errors, but the binary still uses dynamic libraries:
>>
>> ldd regex_use_static
>> linux-gate.so.1 => (0xb800e000)
>> libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0xb7eff000)
>> libm.so.6 => /lib/tls/i686/cmov/libm.so.6 (0xb7ed9000)
>> libgcc_s.so.1 => /lib/libgcc_s.so.1 (0xb7ec9000)
>> libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0xb7d66000)
>> /lib/ld-linux.so.2 (0xb800f000)
>
> This is expected. gcc does use shared libraries by default.
>

OK

>>> ./bjam --layout=system threading=single runtime-link=static link=static install
>>>
>>> (Note that I have omitted --build-dir, since it's not really necessary).
>>>
>> I did, and now get the library installed, but, again, I get:
>
>> /usr/lib/gcc/i486-linux-gnu/4.3.3/libstdc++.a(locale.o): In function
>> `std::locale::_Impl::_M_install_cache(std::locale::facet const*,
>> unsigned int)':
>> (.text._ZNSt6locale5_Impl16_M_install_cacheEPKNS_5facetEj+0x2a):
>> undefined reference to `pthread_mutex_lock'
>
> This may suggest that libstdc++ unconditionally uses threading...
>

but I suceed in build a simple hello program (that uses cout and no
thread) in a static way, so one should be able to compile a static
program if he doesn't use threads, should he?

>
>> g++ -static regex_use.o -I$HOME/boost/include -L$HOME/boost/lib
>> -lboost_regex -o regex_use_static
>> /home/bettini/boost/lib/libboost_regex.a(static_mutex.o): In function
>> `boost::scoped_static_mutex_lock::unlock()':
>> static_mutex.cpp:(.text+0x16): undefined reference to `pthread_mutex_unlock'
>> /home/bettini/boost/lib/libboost_regex.a(static_mutex.o): In function
>> `boost::scoped_static_mutex_lock::lock()':
>> ...
>
> ... and that causes Boost.Regex to make use of threads as well. Can you
> try removing everything again, and rebuild with the additional
>
> define=BOOST_DISABLE_THREADS=1 --without-thread
>
> options? If that does not help, it means that libstdc++ just needs threads,
> and there's no way around that.

I did

./bjam --layout=system threading=single runtime-link=static link=static
define=BOOST_DISABLE_THREADS=1 --without-thread install

the problem is the same (by the way, since I use --without-thread I
cannot use --with-regex, so it basically build all the libraries)...

but the problem looks like it's still due to the fact that regex code
compiles thread functionalities...

isn't there a way to avoid this? In particular I see in regex headers
parts like this

#ifdef BOOST_HAS_THREADS
#include <boost/regex/pending/static_mutex.hpp>
#endif

how could I undefine that variable? It looks like the compilation
process still defines that...

thanks in advance
        Lorenzo

-- 
Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
ICQ# lbetto, 16080134     (GNU/Linux User # 158233)
HOME: http://www.lorenzobettini.it MUSIC: http://www.purplesucker.com
http://www.myspace.com/supertrouperabba
BLOGS: http://tronprog.blogspot.com  http://longlivemusic.blogspot.com
http://www.gnu.org/software/src-highlite
http://www.gnu.org/software/gengetopt
http://www.gnu.org/software/gengen http://doublecpp.sourceforge.net

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk