Hunter
Hunter

Reputation: 67

undefined reference to `boost::this_thread:

I am trying to build to Doge coin headless wallet (similar to bitcoind) it seems to be Boost causing the error but I have no idea on how to fix it.

(Ubuntu 12.04)

When I execute "make -f makefile.unix USE_UPNP=-" I get this error:

/bin/sh ../share/genbuild.sh obj/build.h
g++ -O2 -pthread -Wall -Wextra -Wformat -Wformat-security -Wno-unused-parameter -g -DUSE_IPV6 -DBOOST_SPIRIT_THREADSAFE -I/root/dogecoin/src -I/root/dogecoin/src/obj -DHAVE_BUILD_INFO -fno-stack-protector -fstack-protector-all -Wstack-protector -D_FORTIFY_SOURCE=2  -o dogecoind obj/version.o obj/checkpoints.o obj/netbase.o obj/addrman.o obj/crypter.o obj/key.o obj/db.o obj/init.o obj/irc.o obj/keystore.o obj/main.o obj/net.o obj/protocol.o obj/bitcoinrpc.o obj/rpcdump.o obj/rpcnet.o obj/rpcrawtransaction.o obj/script.o obj/scrypt.o obj/sync.o obj/util.o obj/wallet.o obj/walletdb.o obj/noui.o -Wl,-z,relro -Wl,-z,now   -Wl,-Bdynamic -l boost_system -l boost_filesystem -l boost_program_options -l boost_thread -l db_cxx -l ssl -l crypto -Wl,-Bdynamic -l z -l dl -l pthread
obj/db.o: In function `CAddrDB::Write(CAddrMan const&)':
/root/dogecoin/src/db.cpp:764: undefined reference to `RenameOver(boost::filesystem3::path, boost::filesystem3::path)'
obj/init.o: In function `AppInit2()':
/root/dogecoin/src/init.cpp:450: undefined reference to `CreatePidFile(boost::filesystem3::path const&, int)'
obj/main.o: In function `operator/':
/usr/local/include/boost/filesystem/path.hpp:648: undefined reference to `boost::filesystem::path::operator/=(boost::filesystem::path const&)'
obj/main.o: In function `sleep':
/usr/local/include/boost/thread/pthread/thread_data.hpp:249: undefined reference to `boost::this_thread::hiden::sleep_until(timespec const&)'
obj/main.o: In function `space':
/usr/local/include/boost/filesystem/operations.hpp:520: undefined reference to `boost::filesystem::detail::space(boost::filesystem::path const&, boost::system::error_code*)'
obj/main.o: In function `sleep':
/usr/local/include/boost/thread/pthread/thread_data.hpp:249: undefined reference to `boost::this_thread::hiden::sleep_until(timespec const&)'
obj/main.o: In function `boost::thread::start_thread()':
/usr/local/include/boost/thread/detail/thread.hpp:180: undefined reference to `boost::thread::start_thread_noexcept()'
obj/bitcoinrpc.o: In function `sleep':
/usr/local/include/boost/thread/pthread/thread_data.hpp:249: undefined reference to `boost::this_thread::hiden::sleep_until(timespec const&)'
obj/bitcoinrpc.o: In function `boost::filesystem::path::has_root_directory() const':
/usr/local/include/boost/filesystem/path.hpp:444: undefined reference to `boost::filesystem::path::root_directory() const'
obj/bitcoinrpc.o: In function `operator/':
/usr/local/include/boost/filesystem/path.hpp:648: undefined reference to `boost::filesystem::path::operator/=(boost::filesystem::path const&)'
obj/bitcoinrpc.o: In function `exists':
/usr/local/include/boost/filesystem/operations.hpp:289: undefined reference to `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
obj/bitcoinrpc.o: In function `boost::filesystem::path::has_root_directory() const':
/usr/local/include/boost/filesystem/path.hpp:444: undefined reference to `boost::filesystem::path::root_directory() const'
obj/bitcoinrpc.o: In function `operator/':
/usr/local/include/boost/filesystem/path.hpp:648: undefined reference to `boost::filesystem::path::operator/=(boost::filesystem::path const&)'
obj/bitcoinrpc.o: In function `exists':
/usr/local/include/boost/filesystem/operations.hpp:289: undefined reference to `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
obj/bitcoinrpc.o: In function `call_once<void (*)()>':
/usr/local/include/boost/thread/pthread/once_atomic.hpp:145: undefined reference to `boost::thread_detail::enter_once_region(boost::once_flag&)'
/usr/local/include/boost/thread/pthread/once_atomic.hpp:157: undefined reference to `boost::thread_detail::commit_once_region(boost::once_flag&)'
/usr/local/include/boost/thread/pthread/once_atomic.hpp:153: undefined reference to `boost::thread_detail::rollback_once_region(boost::once_flag&)'
/usr/local/include/boost/thread/pthread/once_atomic.hpp:145: undefined reference to `boost::thread_detail::enter_once_region(boost::once_flag&)'
/usr/local/include/boost/thread/pthread/once_atomic.hpp:157: undefined reference to `boost::thread_detail::commit_once_region(boost::once_flag&)'
/usr/local/include/boost/thread/pthread/once_atomic.hpp:153: undefined reference to `boost::thread_detail::rollback_once_region(boost::once_flag&)'
obj/util.o: In function `operator/':
/usr/local/include/boost/filesystem/path.hpp:648: undefined reference to `boost::filesystem::path::operator/=(boost::filesystem::path const&)'
obj/util.o: In function `path<char*>':
/usr/local/include/boost/filesystem/path.hpp:139: undefined reference to `boost::filesystem::path::codecvt()'
obj/util.o: In function `system_complete':
/usr/local/include/boost/filesystem/operations.hpp:531: undefined reference to `boost::filesystem::detail::system_complete(boost::filesystem::path const&, boost::system::error_code*)'
obj/util.o: In function `is_directory':
/usr/local/include/boost/filesystem/operations.hpp:294: undefined reference to `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
obj/util.o: In function `create_directory':
/usr/local/include/boost/filesystem/operations.hpp:405: undefined reference to `boost::filesystem::detail::create_directory(boost::filesystem::path const&, boost::system::error_code*)'
obj/util.o: In function `GetDataDir(bool)':
/root/dogecoin/src/util.cpp:1029: undefined reference to `boost::filesystem::path::operator/=(char const*)'
obj/util.o: In function `operator/':
/usr/local/include/boost/filesystem/path.hpp:648: undefined reference to `boost::filesystem::path::operator/=(boost::filesystem::path const&)'
obj/util.o: In function `boost::filesystem::path::has_root_directory() const':
/usr/local/include/boost/filesystem/path.hpp:444: undefined reference to `boost::filesystem::path::root_directory() const'
obj/util.o: In function `operator/':
/usr/local/include/boost/filesystem/path.hpp:648: undefined reference to `boost::filesystem::path::operator/=(boost::filesystem::path const&)'
obj/util.o: In function `boost::filesystem::path::has_root_directory() const':
/usr/local/include/boost/filesystem/path.hpp:444: undefined reference to `boost::filesystem::path::root_directory() const'
obj/util.o: In function `operator/':
/usr/local/include/boost/filesystem/path.hpp:648: undefined reference to `boost::filesystem::path::operator/=(boost::filesystem::path const&)'
/usr/local/include/boost/filesystem/path.hpp:648: undefined reference to `boost::filesystem::path::operator/=(boost::filesystem::path const&)'
/usr/local/include/boost/filesystem/path.hpp:648: undefined reference to `boost::filesystem::path::operator/=(boost::filesystem::path const&)'
obj/walletdb.o: In function `sleep':
/usr/local/include/boost/thread/pthread/thread_data.hpp:249: undefined reference to `boost::this_thread::hiden::sleep_until(timespec const&)'
obj/walletdb.o: In function `operator/':
/usr/local/include/boost/filesystem/path.hpp:648: undefined reference to `boost::filesystem::path::operator/=(boost::filesystem::path const&)'
obj/walletdb.o: In function `is_directory':
/usr/local/include/boost/filesystem/operations.hpp:294: undefined reference to `boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)'
obj/walletdb.o: In function `copy_file':
/usr/local/include/boost/filesystem/operations.hpp:381: undefined reference to `boost::filesystem::detail::copy_file(boost::filesystem::path const&, boost::filesystem::path const&, boost::filesystem::copy_option::enum_type, boost::system::error_code*)'
obj/walletdb.o: In function `sleep':
/usr/local/include/boost/thread/pthread/thread_data.hpp:249: undefined reference to `boost::this_thread::hiden::sleep_until(timespec const&)'
obj/walletdb.o: In function `operator/=<std::basic_string<char> >':
/usr/local/include/boost/filesystem/path.hpp:302: undefined reference to `boost::filesystem::path::codecvt()'
obj/walletdb.o: In function `boost::filesystem::path& boost::filesystem::path::append<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::codecvt<wchar_t, char, __mbstate_t> const&)':
/usr/local/include/boost/filesystem/path.hpp:707: undefined reference to `boost::filesystem::path::m_append_separator_if_needed()'
/usr/local/include/boost/filesystem/path.hpp:710: undefined reference to `boost::filesystem::path::m_erase_redundant_separator(unsigned long)'
collect2: ld returned 1 exit status
make: *** [dogecoind] Error 1

Upvotes: 2

Views: 13282

Answers (4)

Random Cloud
Random Cloud

Reputation: 91

If you are sure your linker is given the -lboost_... flags (see Maxim Egorushkin's answer) but you are still having the linker errors, there are a few other things to check:

  1. Ensure you are linking against the correct version of boost

If you are using or have had multiple versions of boost on your system, it is possible there is a version discrepancy between the headers you are building against and the libraries you are attempting to link against. You will want to check the version that your libboost_*.so symlinks are linking to by running ls -l your_lib_path/lib/libboost_*.so. If these symlinks aren't pointing to the version of boost you want, you can modify the links.

You may also want to install boost in a unique location separate from your other libraries to ensure version consistency. If you do this, make sure to put the new path first in your LD_LIBRARY_PATH along with giving GCC the new -I include path flag (also should be first).

  1. Check your pre-processor definitions

Especially if you are using a custom-built version of boost, you will want to ensure you are using the correct pre-processor definitions (-D flag) when trying to build and link against the libraries. As an example, in the header boost/thread/pthread/header_data.hpp:

#ifdef BOOST_THREAD_USES_CHRONO
#ifdef BOOST_THREAD_SLEEP_FOR_IS_STEADY

        inline
        void BOOST_SYMBOL_VISIBLE sleep_for(const chrono::nanoseconds& ns)
        {
            return boost::this_thread::hiden::sleep_for(boost::detail::to_timespec(ns));
        }
#endif
#endif // BOOST_THREAD_USES_CHRONO

If the libraries were built without BOOST_THREAD_USES_CHRONO, the function void BOOST_SYMBOL_VISIBLE sleep_for(const chrono::nanoseconds& ns) will not be in the shared object library. If you were to build against this boost library with the BOOST_THREAD_USES_CHRONO definition, you may end up getting a linker error.

Upvotes: 0

pizzaani
pizzaani

Reputation: 332

I had the same problems using boost 1.62.

However, in my case, as I have installed several boost versions on my Ubuntu 16.04, pointing the libraries and the include directory to the correct folders did help.

I made symbolic links for the include folder and the library folder (automatically done by boost installation):

/usr/include/boost -> /usr/local/boost_1_62_0/boost

and

/usr/local/lib/libboost_thread.so -> libboost_thread.so.1.62.0

Upvotes: 0

Walt Howard
Walt Howard

Reputation: 8208

I was having the same problem, using boost 1.55.0.

I used nm on the boost libraries and none contained any symbol containing filesystem3

I am assuming that boost 1.55.0 removed filesystem3, possibly putting it into header only template but that's just a guess. I was linking the mongodbclient.a and I didn't want to recompile mongo from source (lots of setup required for that)

Moving to boost 1.49.0 fixed the problem. Those libraries had filesystem3 in them.

Upvotes: 1

Maxim Egorushkin
Maxim Egorushkin

Reputation: 136485

You need to link against those boost libraries, i.e. add -lboost_thread -lboost_filesystem -lboost_system to your linker command lines.

See Link Your Program to a Boost Library for more details.

Upvotes: 6

Related Questions