building a run-time static version

Hi I was trying to build a static version of the regex library (boost 1.39), issuing this command: ./bjam --build-dir=build_static --layout=system threading=single runtime-link=static link=static but I always get this error: error: link=shared together with runtime-link=static is not allowed error: such property combination is either impossible error: or too dangerious to be of any use but why is it trying to use link=shared when I explicitly specified link=static? 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

Lorenzo Bettini wrote:
Hi
I was trying to build a static version of the regex library (boost 1.39), issuing this command:
./bjam --build-dir=build_static --layout=system threading=single runtime-link=static link=static
but I always get this error:
error: link=shared together with runtime-link=static is not allowed error: such property combination is either impossible error: or too dangerious to be of any use
but why is it trying to use link=shared when I explicitly specified link=static?
You must have an ICU installed, and Boost.Regex tries to use that automatically. ICU only comes as shared library. You might wish to remove the ICU_PATH setting in project-config.jam or whenever it's is made. - Volodya

Vladimir Prus wrote:
Lorenzo Bettini wrote:
Hi
I was trying to build a static version of the regex library (boost 1.39), issuing this command:
./bjam --build-dir=build_static --layout=system threading=single runtime-link=static link=static
but I always get this error:
error: link=shared together with runtime-link=static is not allowed error: such property combination is either impossible error: or too dangerious to be of any use
but why is it trying to use link=shared when I explicitly specified link=static?
You must have an ICU installed, and Boost.Regex tries to use that automatically. ICU only comes as shared library. You might wish to remove the ICU_PATH setting in project-config.jam or whenever it's is made.
Hi I removed the ICU reference from the project-config.jam, and managed to build the library; however when I statically link to boost regex library, I get libtool: link: g++ -g -O2 -static -o check-regexp check-regexp_cmd.o check-regexp.o -L/opt/boost/lib -lboost_regex-gcc43-mt-1_39 ../gl/.libs/libgnu.a /opt/boost/lib/libboost_regex-gcc43-mt-1_39.a(static_mutex.o): In function `boost::scoped_static_mutex_lock::unlock()': static_mutex.cpp:(.text+0x16): undefined reference to `pthread_mutex_unlock' /opt/boost/lib/libboost_regex-gcc43-mt-1_39.a(static_mutex.o): In function `boost::scoped_static_mutex_lock::lock()': thus the library was not linked with runtime-link=static, was it? Or at least, it builds a multi-threaded version while I requested, with threading=single a single threaded version... I actually need to build a static version of boost which does not depend on any other dynamic library (because, in turn, I need to build a completely static binary that uses boost)... where am I going wrong? 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

Lorenzo Bettini wrote:
Vladimir Prus wrote:
Lorenzo Bettini wrote:
Hi
I was trying to build a static version of the regex library (boost 1.39), issuing this command:
./bjam --build-dir=build_static --layout=system threading=single runtime-link=static link=static
but I always get this error:
error: link=shared together with runtime-link=static is not allowed error: such property combination is either impossible error: or too dangerious to be of any use
but why is it trying to use link=shared when I explicitly specified link=static?
You must have an ICU installed, and Boost.Regex tries to use that automatically. ICU only comes as shared library. You might wish to remove the ICU_PATH setting in project-config.jam or whenever it's is made.
Hi
I removed the ICU reference from the project-config.jam, and managed to build the library; however when I statically link to boost regex library, I get
libtool: link: g++ -g -O2 -static -o check-regexp check-regexp_cmd.o check-regexp.o -L/opt/boost/lib -lboost_regex-gcc43-mt-1_39 ../gl/.libs/libgnu.a /opt/boost/lib/libboost_regex-gcc43-mt-1_39.a(static_mutex.o): In function `boost::scoped_static_mutex_lock::unlock()': static_mutex.cpp:(.text+0x16): undefined reference to `pthread_mutex_unlock' /opt/boost/lib/libboost_regex-gcc43-mt-1_39.a(static_mutex.o): In function `boost::scoped_static_mutex_lock::lock()':
thus the library was not linked with runtime-link=static, was it?
I don't think this conclusion is right -- nothing above suggests any dependency on any shared library. Rather, the errors above mean that you have: 1. Failed to linked with boost.thread library 2. Failed to pass -pthreads to the compiler
Or at least, it builds a multi-threaded version while I requested, with threading=single a single threaded version...
To begin with, you are requesting multithreaded library: -lboost_regex-gcc43-mt-1_39 Here, "mt" stands for multithreaded. Then, it's is fairly unlikely that such a library would be produced if you say threading=single. I would guess that -L/opt/boost/lib has something you previously installed, and if you run: ./bjam --build-dir=build_static --layout=system threading=single runtime-link=static link=static it puts new libraries in stage/lib. Did you copy non-MT versions to /opt/boost/lib? If so, you should be using -l option without "mt".
I actually need to build a static version of boost which does not depend on any other dynamic library (because, in turn, I need to build a completely static binary that uses boost)... where am I going wrong?
Hopefully the above explains this? - Volodya

Vladimir Prus wrote:
Lorenzo Bettini wrote:
Vladimir Prus wrote:
Lorenzo Bettini wrote:
Hi
I was trying to build a static version of the regex library (boost 1.39), issuing this command:
./bjam --build-dir=build_static --layout=system threading=single runtime-link=static link=static
but I always get this error:
error: link=shared together with runtime-link=static is not allowed error: such property combination is either impossible error: or too dangerious to be of any use
but why is it trying to use link=shared when I explicitly specified link=static? You must have an ICU installed, and Boost.Regex tries to use that automatically. ICU only comes as shared library. You might wish to remove the ICU_PATH setting in project-config.jam or whenever it's is made. Hi
I removed the ICU reference from the project-config.jam, and managed to build the library; however when I statically link to boost regex library, I get
libtool: link: g++ -g -O2 -static -o check-regexp check-regexp_cmd.o check-regexp.o -L/opt/boost/lib -lboost_regex-gcc43-mt-1_39 ../gl/.libs/libgnu.a /opt/boost/lib/libboost_regex-gcc43-mt-1_39.a(static_mutex.o): In function `boost::scoped_static_mutex_lock::unlock()': static_mutex.cpp:(.text+0x16): undefined reference to `pthread_mutex_unlock' /opt/boost/lib/libboost_regex-gcc43-mt-1_39.a(static_mutex.o): In function `boost::scoped_static_mutex_lock::lock()':
thus the library was not linked with runtime-link=static, was it?
I don't think this conclusion is right -- nothing above suggests any dependency on any shared library. Rather, the errors above mean that you have:
1. Failed to linked with boost.thread library 2. Failed to pass -pthreads to the compiler
Or at least, it builds a multi-threaded version while I requested, with threading=single a single threaded version...
To begin with, you are requesting multithreaded library:
-lboost_regex-gcc43-mt-1_39
Here, "mt" stands for multithreaded. Then, it's is fairly unlikely that such a library would be produced if you say threading=single.
actually, I built regex with above bjam command line, and then run sudo ./bjam install warning: Building Boost.Regex with the optional Unicode/ICU support disabled. note: Please refer to the Boost.Regex documentation for more information note: this is a strictly optional feature. ...patience... ...found 14569 targets... ...updating 5 targets... common.copy /opt/boost/lib/libboost_regex-gcc43-mt-1_39.so.1.39.0 ln-UNIX /opt/boost/lib/libboost_regex-gcc43-mt.so common.copy /opt/boost/lib/libboost_regex-gcc43-mt-1_39.a ln-UNIX /opt/boost/lib/libboost_regex-gcc43-mt.a ln-UNIX /opt/boost/lib/libboost_regex-gcc43-mt-1_39.so ...updated 5 targets... thus, bjam install seems to install the -mt version, while I requested to build the non threaded version... probably I'm doing something wrong with bjam build/install?
I would guess that -L/opt/boost/lib has something you previously installed, and if you run:
mh... no: I removed the /opt/boost/lib contents before running bjam install, and as shown above, 'bjam install' installs the -mt version, which shouldn't have been built, should it?
./bjam --build-dir=build_static --layout=system threading=single runtime-link=static link=static
it puts new libraries in stage/lib. Did you copy non-MT versions to /opt/boost/lib? If so, you should be using -l option without "mt".
no I didn't because I thought 'bjam install' should have, but probably I got the usage of bjam wrong... I'm used to autotools 'configure && make && make install', and probably bjam does not behave the same?
I actually need to build a static version of boost which does not depend on any other dynamic library (because, in turn, I need to build a completely static binary that uses boost)... where am I going wrong?
Hopefully the above explains this?
I found stage/lib/libboost_regex.a and copied it into /opt/boost/lib, but again I get g++ -static -I /opt/boost/include/ regex_use.cpp /opt/boost/lib/libboost_regex.a -o regex_use_static /opt/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' /opt/boost/lib/libboost_regex.a(static_mutex.o): In function `boost::scoped_static_mutex_lock::lock()': so is libboost_regex.a still built using multithreading? 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

Lorenzo Bettini wrote:
Vladimir Prus wrote:
Lorenzo Bettini wrote:
Vladimir Prus wrote:
Lorenzo Bettini wrote:
Hi
I was trying to build a static version of the regex library (boost 1.39), issuing this command:
./bjam --build-dir=build_static --layout=system threading=single runtime-link=static link=static
but I always get this error:
error: link=shared together with runtime-link=static is not allowed error: such property combination is either impossible error: or too dangerious to be of any use
but why is it trying to use link=shared when I explicitly specified link=static? You must have an ICU installed, and Boost.Regex tries to use that automatically. ICU only comes as shared library. You might wish to remove the ICU_PATH setting in project-config.jam or whenever it's is made. Hi
I removed the ICU reference from the project-config.jam, and managed to build the library; however when I statically link to boost regex library, I get
libtool: link: g++ -g -O2 -static -o check-regexp check-regexp_cmd.o check-regexp.o -L/opt/boost/lib -lboost_regex-gcc43-mt-1_39 ../gl/.libs/libgnu.a /opt/boost/lib/libboost_regex-gcc43-mt-1_39.a(static_mutex.o): In function `boost::scoped_static_mutex_lock::unlock()': static_mutex.cpp:(.text+0x16): undefined reference to `pthread_mutex_unlock' /opt/boost/lib/libboost_regex-gcc43-mt-1_39.a(static_mutex.o): In function `boost::scoped_static_mutex_lock::lock()':
thus the library was not linked with runtime-link=static, was it?
I don't think this conclusion is right -- nothing above suggests any dependency on any shared library. Rather, the errors above mean that you have:
1. Failed to linked with boost.thread library 2. Failed to pass -pthreads to the compiler
Or at least, it builds a multi-threaded version while I requested, with threading=single a single threaded version...
To begin with, you are requesting multithreaded library:
-lboost_regex-gcc43-mt-1_39
Here, "mt" stands for multithreaded. Then, it's is fairly unlikely that such a library would be produced if you say threading=single.
actually, I built regex with above bjam command line, and then run
sudo ./bjam install warning: Building Boost.Regex with the optional Unicode/ICU support disabled. note: Please refer to the Boost.Regex documentation for more information note: this is a strictly optional feature. ...patience... ...found 14569 targets... ...updating 5 targets... common.copy /opt/boost/lib/libboost_regex-gcc43-mt-1_39.so.1.39.0 ln-UNIX /opt/boost/lib/libboost_regex-gcc43-mt.so common.copy /opt/boost/lib/libboost_regex-gcc43-mt-1_39.a ln-UNIX /opt/boost/lib/libboost_regex-gcc43-mt.a ln-UNIX /opt/boost/lib/libboost_regex-gcc43-mt-1_39.so ...updated 5 targets...
thus, bjam install seems to install the -mt version, while I requested to build the non threaded version... probably I'm doing something wrong with bjam build/install?
Unlike autotool, 'install' is not something completely unrelated to the regular build process. It's basically an ordinary target, and therefore is affected by the properties you specify. You shoul be using: ./bjam --build-dir=build_static --layout=system threading=single runtime-link=static link=static install That is, passing all the same options. And, you don't need separate build and install steps. The above command will both build and install everything necessary.
I would guess that -L/opt/boost/lib has something you previously installed, and if you run:
mh... no: I removed the /opt/boost/lib contents before running bjam install, and as shown above, 'bjam install' installs the -mt version, which shouldn't have been built, should it?
./bjam --build-dir=build_static --layout=system threading=single runtime-link=static link=static
it puts new libraries in stage/lib. Did you copy non-MT versions to /opt/boost/lib? If so, you should be using -l option without "mt".
no I didn't because I thought 'bjam install' should have, but probably I got the usage of bjam wrong... I'm used to autotools 'configure && make && make install', and probably bjam does not behave the same?
I actually need to build a static version of boost which does not depend on any other dynamic library (because, in turn, I need to build a completely static binary that uses boost)... where am I going wrong?
Hopefully the above explains this?
I found stage/lib/libboost_regex.a and copied it into /opt/boost/lib, but again I get
g++ -static -I /opt/boost/include/ regex_use.cpp /opt/boost/lib/libboost_regex.a -o regex_use_static /opt/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' /opt/boost/lib/libboost_regex.a(static_mutex.o): In function `boost::scoped_static_mutex_lock::lock()':
so is libboost_regex.a still built using multithreading?
Apparently. Presumably, that's because it was built this way. I would suggest you remove both /opt/boost and stage directories and then either: 1. Run: ./bjam --layout=system threading=single runtime-link=static link=static install (Note that I have omitted --build-dir, since it's not really necessary). 2. Run ./bjam --layout=system threading=single runtime-link=static link=static and then manually copy stage/lib and the headers. - Volodya

still problems (please read below) Vladimir Prus wrote:
sudo ./bjam install warning: Building Boost.Regex with the optional Unicode/ICU support disabled. note: Please refer to the Boost.Regex documentation for more information note: this is a strictly optional feature. ...patience... ...found 14569 targets... ...updating 5 targets... common.copy /opt/boost/lib/libboost_regex-gcc43-mt-1_39.so.1.39.0 ln-UNIX /opt/boost/lib/libboost_regex-gcc43-mt.so common.copy /opt/boost/lib/libboost_regex-gcc43-mt-1_39.a ln-UNIX /opt/boost/lib/libboost_regex-gcc43-mt.a ln-UNIX /opt/boost/lib/libboost_regex-gcc43-mt-1_39.so ...updated 5 targets...
thus, bjam install seems to install the -mt version, while I requested to build the non threaded version... probably I'm doing something wrong with bjam build/install?
Unlike autotool, 'install' is not something completely unrelated to the regular build process. It's basically an ordinary target, and therefore is affected by the properties you specify. You shoul be using:
./bjam --build-dir=build_static --layout=system threading=single runtime-link=static link=static install
That is, passing all the same options. And, you don't need separate build and install steps. The above command will both build and install everything necessary.
OK, I see
g++ -static -I /opt/boost/include/ regex_use.cpp /opt/boost/lib/libboost_regex.a -o regex_use_static /opt/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' /opt/boost/lib/libboost_regex.a(static_mutex.o): In function `boost::scoped_static_mutex_lock::lock()':
so is libboost_regex.a still built using multithreading?
Apparently. Presumably, that's because it was built this way. I would suggest you remove both /opt/boost and stage directories and then either:
1. Run:
./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: 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()': ... /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' 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) If I add the -static flag to g++ I get the same above errors... what am I doing wrong? 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

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.
./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...
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. - Volodya

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

Lorenzo Bettini wrote:
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...
I was surely doing something wrong (see my other answer): ./bjam --layout=system threading=single runtime-link=static link=static define=BOOST_DISABLE_THREADS=1 install works, but define=BOOST_DISABLE_THREADS=1 is required... this looks like a bug? cheers 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

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.
./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...
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.
Hi OK, so I managed to build it :-) this is the two command lines I've used: ./bootstrap.sh --prefix=$HOME/boost --libdir=$HOME/boost/lib --with-libraries=regex --without-icu ./bjam --build-dir=build_static --layout=system threading=single runtime-link=static link=static define=BOOST_DISABLE_THREADS=1 install I can confirm that define=BOOST_DISABLE_THREADS=1 is required, because even with threading=single the multi threading code is still built and added to the library (and this makes the library itself to depend on threads, and thus it cannot be used to build completely static binaries). Is this a bug, or the intentional behavior? If so, what does threading=single mean? thanks again Lore -- 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
participants (2)
-
Lorenzo Bettini
-
Vladimir Prus