[Regex]static compilation problems

Dear users, to start using regular expressions I tried a very simple program only declaring one regular expression. #include <boost/regex.hpp> int main(int , char* []) { boost::regex re("\\d+"); return 0; } Linking and compiling this with the command: g++ test.cpp -o test -L ~/libs/boost/lib/ -l boost_regex-gcc43-mt works without problems, but running it then leads to the following: error while loading shared libraries: libboost_system-gcc43-mt-1_37.so.1.37.0: cannot open shared object file: No such file or directory But the directory clearly shows its existence: -rw-rw-r-- 1 engineer engineer 1587006 2008-11-21 07:53 /home/engineer/libs/boost/lib/libboost_regex-gcc43-mt-1_37.a lrwxrwxrwx 1 engineer engineer 38 2008-11-21 07:50 /home/engineer/libs/boost/lib/libboost_regex-gcc43-mt-1_37.so -> libboost_regex-gcc43-mt-1_37.so.1.37.0 -rwxrwxr-x 1 engineer engineer 722184 2008-11-21 07:50 /home/engineer/libs/boost/lib/libboost_regex-gcc43-mt-1_37.so.1.37.0 lrwxrwxrwx 1 engineer engineer 30 2008-11-21 07:53 /home/engineer/libs/boost/lib/libboost_regex-gcc43-mt.a -> libboost_regex-gcc43-mt-1_37.a lrwxrwxrwx 1 engineer engineer 38 2008-11-21 07:52 /home/engineer/libs/boost/lib/libboost_regex-gcc43-mt.so -> libboost_regex-gcc43-mt-1_37.so.1.37.0 Then I tried doing the same using static libraries: g++ -static test.cpp -o test -L ~/libs/boost/lib/ -l boost_regex-gcc43-mt but got an extremely long list of errors: /home/engineer/libs/boost/lib//libboost_regex-gcc43-mt.a(static_mutex.o): In function `boost::scoped_static_mutex_lock::unlock()': static_mutex.cpp:(.text+0x16): undefined reference to `pthread_mutex_unlock' /home/engineer/libs/boost/lib//libboost_regex-gcc43-mt.a(static_mutex.o): In function `boost::scoped_static_mutex_lock::lock()': static_mutex.cpp:(.text+0x46): undefined reference to `pthread_mutex_lock' /home/engineer/libs/boost/lib//libboost_regex-gcc43-mt.a(static_mutex.o): In function `boost::scoped_static_mutex_lock::~scoped_static_mutex_lock()': static_mutex.cpp:(.text+0x76): undefined reference to `pthread_mutex_unlock' /home/engineer/libs/boost/lib//libboost_regex-gcc43-mt.a(static_mutex.o): In function `boost::scoped_static_mutex_lock::~scoped_static_mutex_lock()': static_mutex.cpp:(.text+0xa6): undefined reference to `pthread_mutex_unlock' /home/engineer/libs/boost/lib//libboost_regex-gcc43-mt.a(static_mutex.o): In function `boost::scoped_static_mutex_lock::scoped_static_mutex_lock(boost::static_mutex&, bool)': static_mutex.cpp:(.text+0xdd): undefined reference to `pthread_mutex_lock' /home/engineer/libs/boost/lib//libboost_regex-gcc43-mt.a(static_mutex.o): In function `boost::scoped_static_mutex_lock::scoped_static_mutex_lock(boost::static_mutex&, bool)': static_mutex.cpp:(.text+0x10d): undefined reference to `pthread_mutex_lock' /usr/lib/gcc/i386-redhat-linux/4.3.0/libstdc++.a(locale.o): In function `__gnu_cxx::__scoped_lock::~__scoped_lock()': (.text._ZN9__gnu_cxx13__scoped_lockD1Ev[__gnu_cxx::__scoped_lock::~__scoped_lock()]+0x18): undefined reference to `pthread_mutex_unlock' /usr/lib/gcc/i386-redhat-linux/4.3.0/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+0x2d): undefined reference to `pthread_mutex_lock' /usr/lib/gcc/i386-redhat-linux/4.3.0/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+0x59): undefined reference to `pthread_mutex_unlock' /usr/lib/gcc/i386-redhat-linux/4.3.0/libstdc++.a(locale_init.o): In function `std::locale::locale()': (.text._ZNSt6localeC1Ev+0x2a): undefined reference to `pthread_mutex_lock' /usr/lib/gcc/i386-redhat-linux/4.3.0/libstdc++.a(locale_init.o): In function `std::locale::locale()': (.text._ZNSt6localeC1Ev+0x52): undefined reference to `pthread_mutex_unlock' /usr/lib/gcc/i386-redhat-linux/4.3.0/libstdc++.a(locale_init.o): In function `std::locale::global(std::locale const&)': (.text._ZNSt6locale6globalERKS_+0x2a): undefined reference to `pthread_mutex_lock' /usr/lib/gcc/i386-redhat-linux/4.3.0/libstdc++.a(locale_init.o): In function `std::locale::global(std::locale const&)': (.text._ZNSt6locale6globalERKS_+0x9a): undefined reference to `pthread_mutex_unlock' /usr/lib/gcc/i386-redhat-linux/4.3.0/libstdc++.a(locale_init.o): In function `std::locale::locale()': (.text._ZNSt6localeC2Ev+0x2a): undefined reference to `pthread_mutex_lock' /usr/lib/gcc/i386-redhat-linux/4.3.0/libstdc++.a(locale_init.o): In function `std::locale::locale()': (.text._ZNSt6localeC2Ev+0x52): undefined reference to `pthread_mutex_unlock' /usr/lib/gcc/i386-redhat-linux/4.3.0/libstdc++.a(eh_alloc.o): In function `__cxa_free_exception': (.text.__cxa_free_exception+0x6b): undefined reference to `pthread_mutex_lock' /usr/lib/gcc/i386-redhat-linux/4.3.0/libstdc++.a(eh_alloc.o): In function `__cxa_free_exception': (.text.__cxa_free_exception+0x86): undefined reference to `pthread_mutex_unlock' /usr/lib/gcc/i386-redhat-linux/4.3.0/libstdc++.a(eh_alloc.o): In function `__cxa_allocate_exception': (.text.__cxa_allocate_exception+0x6f): undefined reference to `pthread_mutex_lock' /usr/lib/gcc/i386-redhat-linux/4.3.0/libstdc++.a(eh_alloc.o): In function `__cxa_allocate_exception': (.text.__cxa_allocate_exception+0xd7): undefined reference to `pthread_mutex_unlock' /usr/lib/gcc/i386-redhat-linux/4.3.0/libgcc_eh.a(unwind-dw2-fde-glibc.o): In function `__register_frame_info_bases': (.text+0x60): undefined reference to `pthread_mutex_lock' /usr/lib/gcc/i386-redhat-linux/4.3.0/libgcc_eh.a(unwind-dw2-fde-glibc.o): In function `__register_frame_info_bases': (.text+0x77): undefined reference to `pthread_mutex_unlock' /usr/lib/gcc/i386-redhat-linux/4.3.0/libgcc_eh.a(unwind-dw2-fde-glibc.o): In function `__register_frame_info_table_bases': (.text+0x12a): undefined reference to `pthread_mutex_lock' /usr/lib/gcc/i386-redhat-linux/4.3.0/libgcc_eh.a(unwind-dw2-fde-glibc.o): In function `__register_frame_info_table_bases': (.text+0x141): undefined reference to `pthread_mutex_unlock' /usr/lib/gcc/i386-redhat-linux/4.3.0/libgcc_eh.a(unwind-dw2-fde-glibc.o): In function `_Unwind_Find_FDE': (.text+0x18a8): undefined reference to `pthread_mutex_lock' /usr/lib/gcc/i386-redhat-linux/4.3.0/libgcc_eh.a(unwind-dw2-fde-glibc.o): In function `_Unwind_Find_FDE': (.text+0x18f8): undefined reference to `pthread_mutex_unlock' /usr/lib/gcc/i386-redhat-linux/4.3.0/libgcc_eh.a(unwind-dw2-fde-glibc.o): In function `__deregister_frame_info_bases': (.text+0x1aaa): undefined reference to `pthread_mutex_lock' /usr/lib/gcc/i386-redhat-linux/4.3.0/libgcc_eh.a(unwind-dw2-fde-glibc.o): In function `__deregister_frame_info_bases': (.text+0x1b2f): undefined reference to `pthread_mutex_unlock' collect2: ld returned 1 exit status If anyone could point me to a solution of this problem, or give one here I'd very much appreciate it. Thank you. Best, Moritz

On Sunday 15 February 2009 16:47:24 Moritz Beber wrote:
#include <boost/regex.hpp>
int main(int , char* []) { boost::regex re("\\d+"); return 0; }
Linking and compiling this with the command:
g++ test.cpp -o test -L ~/libs/boost/lib/ -l boost_regex-gcc43-mt
works without problems, but running it then leads to the following:
error while loading shared libraries: libboost_system-gcc43-mt-1_37.so.1.37.0: cannot open shared object file: No such file or directory
But the directory clearly shows its existence:
Indeed, but the dynamic linker (ldd) cannot find it when loading your ELF-file. There are several solutions to this, namely LD_LIBRARY_PATH, ldconfig, rpath and static linking. You can look them all up if you like. In brief, LD_LIBRARY_PATH is by far the easiest for test development, just set LD_LIBRARY_PATH (environment variable) to point to the right directory: EXPORT LD_LIBRARY_PATH=~/libs/boost/lib (bash syntax). rpath is neat if you use Cmake or autotools, which I would recommend as soon as you are past the toy stage --- it makes a pointer to the right library inside the ELF-file, and removes it again when installing. I wouldn't mess with ldconfig unless you are making distribution like work, and static linking usually gives more troubles than it is worth, besides wasting resources. Hope it helps. -- Kærlig hilsen, Esben
participants (2)
-
Esben Mose Hansen
-
Moritz Beber