Undefined Symbols on MacOS 10.9 Mavericks from db.o and util.o #3228

issue gthiruva opened this issue on November 10, 2013
  1. gthiruva commented at 6:03 AM on November 10, 2013: none

    I'm running MacOS 10.9 (13A598) with the latest Boost, BerkeleyDB, and libqrencode installed via MacPorts. Compilation goes fine. But linking seems to fail due to undefined symbols in util.o and db.o.

    See full output here: https://gist.github.com/gthiruva/10d8b1e46e4598ca1328

    Error output: Undefined symbols for architecture x86_64: "Db::verify(char const_, char const_, std::ostream_, unsigned int)", referenced from: CDBEnv::Verify(std::string, bool (_)(CDBEnv&, std::string)) in db.o CDBEnv::Salvage(std::string, bool, std::vector<std::pair<std::vector<unsigned char, std::allocator<unsigned char> >, std::vector<unsigned char, std::allocator<unsigned char> > >, std::allocator<std::pair<std::vector<unsigned char, std::allocator<unsigned char> >, std::vector<unsigned char, std::allocator<unsigned char> > > > >&) in db.o "boost::program_options::to_internal(std::string const&)", referenced from: boost::program_options::detail::basic_config_file_iterator<char>::getline(std::string&) in util.o "boost::program_options::detail::common_config_file_iterator::common_config_file_iterator(std::set<std::string, std::lessstd::string, std::allocatorstd::string > const&, bool)", referenced from: boost::program_options::detail::basic_config_file_iterator<char>::basic_config_file_iterator(std::istream&, std::set<std::string, std::lessstd::string, std::allocatorstd::string > const&, bool) in util.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) make: *** [Bitcoin-Qt.app/Contents/MacOS/Bitcoin-Qt] Error 1

  2. fanquake commented at 6:06 AM on November 10, 2013: member

    @gthiruva Which version of Boost are you using, 1.54.0 ?

  3. laanwj commented at 2:24 PM on November 11, 2013: member

    Did you do a make clean / and or make sure all the object files were gone before building?

  4. gthiruva commented at 9:14 PM on November 13, 2013: none

    @fanquake Yep, 1.50.0 from macports:

    The following ports are currently installed:
      boost [@1](/bitcoin-bitcoin/contributor/1/).54.0_0+no_single+no_static+python27 (active)
    

    @laanwj And, yes. make clean and even make distclean.

  5. taoeffect commented at 3:41 AM on November 28, 2013: none

    you can probably fix it by changing the compiler to g++, i.e. adding these to qmake when generating the makefile: QMAKE_CC=gcc QMAKE_CXX=g++

  6. theuni commented at 3:29 PM on November 30, 2013: member

    I don't see any of our new interim libs being linked in. Am I to assume this is a pre-autotools build?

    If so, it's not really relevant since we don't build this way anymore.

  7. imbolo commented at 9:16 AM on December 7, 2013: none

    I found out how to solve that problem. OSX 10.9 change the default stdlib to libc++. You may need to compile with libstdc++ to prevent some errors. At the same time, boost should be compiled use a cxxflag '-stdlib=libstdc++'( eg: ./b2 cxxflags="-stdlib=libstdc++" ...blablabla )

  8. theuni commented at 12:27 AM on December 10, 2013: member

    This indeed seems to be an issue with boost and/or clang and/or macports' coping with the combination. I'll need to look a bit closer to verify. It's possible that we can mitigate if it isn't properly fixed soonish.

  9. Elijen commented at 4:38 PM on January 23, 2014: none

    Got the same problem. Recompiling boost with libstdc++ didn't help. I also added CFLAGS += -stdlib=libstdc++ into makefile.osx. Still getting the ld: symbol(s) not found for architecture x86_64 error on make -f makefile.osx

    Any suggestions?

  10. dwasyluk commented at 7:15 PM on January 26, 2014: none

    I fixed the issue in the makefile.osx by commenting out that line CFLAGS += -stdlib=libstdc++ - now I can build properly on Mavericks. Still having issues compiling the QT client on Mavericks though, trying to update the .pro file so it builds as it should...

  11. gubatron commented at 3:47 AM on February 1, 2014: contributor

    having a similar issue here. Made sure my homebrew dependencies were all up to date, started of a clean make several times. Running on OSX 10.9.1.

    I don't have a 'makefile.osx' (I remember seeing one when building Litecoin though), after autogen.sh and ./configure, I end up with a regular 'Makefile' file.

    My errors seem to start around here during the build:

    /usr/bin/ar -rs libleveldb.a db/builder.o db/c.o db/db_impl.o db/db_iter.o db/dbformat.o db/filename.o db/log_reader.o db/log_writer.o db/memtable.o db/repair.o db/table_cache.o db/version_edit.o db/version_set.o db/write_batch.o table/block.o table/block_builder.o table/filter_block.o table/format.o table/iterator.o table/merger.o table/table.o table/table_builder.o table/two_level_iterator.o util/arena.o util/bloom.o util/cache.o util/coding.o util/comparator.o util/crc32c.o util/env.o util/env_posix.o util/env_win.o util/filter_policy.o util/hash.o util/histogram.o util/logging.o util/options.o util/status.o port/port_posix.o
    ar: creating archive libleveldb.a
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: libleveldb.a(env_win.o) has no symbols
      CXXLD    bitcoind
    clang: warning: argument unused during compilation: '-pthread'
    clang: warning: argument unused during compilation: '-pie'
    Undefined symbols for architecture x86_64:
      "boost::thread_detail::commit_once_region(boost::once_flag&)", referenced from:
          LogPrintStr(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libbitcoin_common.a(util.o)
          LockedPageManager::Instance() in libbitcoin_server.a(init.o)
          boost::spirit::classic::impl::object_with_id_base<boost::spirit::classic::impl::grammar_tag, unsigned long>::acquire_object_id() in libbitcoin_cli.a(rpcclient.o)
    
  12. hackervera commented at 9:57 AM on February 3, 2014: none

    Getting the same error

  13. gubatron commented at 1:31 PM on February 3, 2014: contributor

    Fixed it by specifying the boost lib dir location, in my case I'm working with Homebrew and this did it. (Never in the process I had to deal with a file named "makefile.osx", I just had a Makefile)

    $ ./configure --with-boost-libdir=/usr/local/Cellar/boost/1.55.0/lib

    Also, to make sure boost was linked properly I unlinked it and linked it back before building bitcoin doing brew unlink boost && brew link boost (maybe this didn't help, but it was just a step to be sure I had no boost linking issues)

  14. SimonKaluza commented at 6:49 PM on March 13, 2014: none

    If you're using Homebrew, the easiest way to workaround this issue is to compile the Boost library from source using the brew command. This will create clang/libc++ compatible Boost binaries to link against and automatically add them to the appropriate directory so you don't have to manually add them.

    First uninstall the gcc/libstdc++ compiled Boost binaries by running brew uninstall boost, then run brew install boost --build-from-source --HEAD to download the latest Boost source code, compile it, and add the binaries to your classpath.

    You should now be able to successfully run make -f makefile.osx, just remember to clean the build if you've already failed a compilation.

  15. sylvainblot commented at 1:37 PM on March 17, 2014: none

    @SimonKaluza didn't work for me for bitcoin-qt :(

  16. mikehearn commented at 4:22 PM on March 17, 2014: contributor

    To fix this I uninstalled db4 and boost with brew, and then updated and reinstalled.

  17. simonhard commented at 6:04 PM on March 17, 2014: none

    Still no success on building QT-Client on Mavericks :(

    Project MESSAGE: Building with UPNP supportUndefined symbols for architecture x86_64: "boost::program_options::to_internal(std::string const&)", referenced from: boost::program_options::detail::basic_config_file_iterator<char>::getline(std::string&) in util.o "boost::program_options::detail::common_config_file_iterator::common_config_file_iterator(std::set<std::string, std::lessstd::string, std::allocatorstd::string > const&, bool)", referenced from: boost::program_options::detail::basic_config_file_iterator<char>::basic_config_file_iterator(std::istream&, std::set<std::string, std::lessstd::string, std::allocatorstd::string > const&, bool) in util.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

  18. laanwj added the label Build system on Apr 2, 2014
  19. laanwj added the label Mac on Apr 2, 2014
  20. laanwj added the label Priority Low on Apr 2, 2014
  21. indolering commented at 7:26 AM on May 5, 2014: none

    @mikehearn are you saying you able to get QT working by simply by uninstall and reinstalling db4 and boost? Did you build both from the source or?

  22. mikehearn commented at 8:50 AM on May 5, 2014: contributor

    Reinstalling the dependencies via brew uninstall/install worked for me. The problem is every MacOS X or XCode upgrade breaks things at the moment.

  23. ghost commented at 7:18 PM on June 11, 2014: none

    Still no luck building (--without-gui) with macports. Is there a plan of action in effect to fix this?

  24. theuni commented at 9:20 PM on June 11, 2014: member

    @BugAndNewsReporter Could you please post (at pastebin or similar) your complete build output and config.log ?

  25. gavinandresen commented at 10:22 PM on June 11, 2014: contributor

    RE: plan of action: the plan of action will be to drop support for MacPorts unless somebody using MacPorts steps forward and volunteers to fix things as they break. I used to use MacPorts, but have switched to brew.

  26. ghost commented at 1:08 AM on June 12, 2014: none
  27. neverpanic commented at 9:10 PM on June 15, 2014: none

    All the reports in this ticket look like C++ runtime library mismatches. With the release of OS X Mavericks, Apple removed all GCC compilers (there's a g++ symlink, but it points to clang++) and switched clang++'s default C++ runtime to libc++.

    You will get these problems when trying to link against a library built against a different C++ runtime library than your binary uses – and the link error is actually a good thing, because the alternative would be hard-to-debug crashes at runtime.

    So, you need to decide which C++ runtime library to use: Apple's new libc++, or GCC's libstdc++. In my opinion the only sane choice is clear, because Apple will no longer support GCC/libstdc++, and this combination is stuck in a version that's multiple years outdated. Especially if bitcoin wants to use C++11 at some point, the use of libc++ cannot be avoided.

    Long story short: Make sure your boost lib uses the same C++ runtime as bitcoin.

    MacPorts uses the same defaults as Apple's compilers, i.e. libstdc++ on systems below Mavericks, and libc++ on Mavericks and beyond. If you're compiling on Mavericks against MacPorts libraries you don't have to do anything with the autotools-based build system, because your compiler will already default to libc++. Note that this isn't the case if you have the MACOSX_DEPLOYMENT_TARGET environment variable set to anything below 10.9 (because that implicitly switches the compiler's default).

    So, in conclusion:

    • if you're on 10.9 and compile against MacPorts libs, ensure MACOSX_DEPLOYMENT_TARGET is unset. You cannot use the libs from MacPorts to build bitcoin for older systems by setting it.
    • if you're on 10.8 and below and compile against MacPorts libs, libstdc++ will be used automatically and you shouldn't have any problems.
    • if you use boost or any other dependency from a different source, check which C++ runtime it uses using otool -L. If it's libc++ and you're on <= 10.8, you need to compile with clang++ -stdlib=libc++. If it's libstdc++ and you're on 10.9 or later, you need to compile with clang++ -stdlib=libstdc++.
    • if the C++ runtimes used by your dependencies differ, you will have problems.

    From a MacPorts POV, there doesn't seem to by anything to fix here?

  28. ghost commented at 9:45 AM on June 16, 2014: none

    @neverpanic, can you clarify if the devs have to change something in the bitcoin build system, or that it should just work for users as long they have no external libs and everything comes from macports?

    I'm on 10.9 with a fresh macports install and MACOSX_DEPLOYMENT_TARGET is unset. All dependencies come from macports, yet I still experience the linking errors described above.

  29. neverpanic commented at 10:30 AM on June 16, 2014: none

    @BugAndNewsReporter Your config.log shows that configure picks up /opt/local/bin/g++ as C++ compiler. It seems to be a symlink to MacPorts' GCC 4.8. You cannot use this compiler to compile C++ code on Mavericks and beyond, because it does not compile against libc++[1]. Please use clang++ as compiler instead.

    [1] The truth is a little more complicated than that, but unless you're ready to dive into the gory details, this rule of thumb will serve you well and you can stop reading here. For those in the know: If you're sure you won't have problems with runtime incompatibilities you can still use g++. You can also make g++ use libc++ using http://stackoverflow.com/questions/22228208/using-g-with-libc. Note that g++ is not able to use AVX instructions on OS X, only clang++ can do that due to the outdated GNU assembler shipped by Apple, so that's another good reason to avoid GCC.

  30. mikehearn commented at 11:54 AM on June 16, 2014: contributor

    Another cause for this error can be if you're switching between old and new Xcode's and forgot which one you have. Use xcode-select to ensure you're using the latest Xcode and then if still encountering such errors (with brew) you can just uninstall and reinstall the dependencies that are failing to link.

  31. ghost commented at 3:35 PM on June 16, 2014: none

    ok, after what @neverpanic said and some googling I figured out that I had to do port select --set gcc none to reset clang++ as the default compiler. the linking errors disappeared after that.

  32. steaerox commented at 7:50 AM on June 26, 2014: none

    @BugAndNewsReporter i tried it, but i receive this: -bash: port: command not found What should i do now?

  33. DirkyJerky commented at 9:08 PM on June 29, 2014: none

    Got here from google, thanks for the links @taoeffect

    Um, as for @steaerox , you dont have Macports installed.... And why are you here on a building issue if you don't know the simplest bash errors? ;P

  34. simondlr commented at 5:14 PM on July 26, 2014: contributor

    What I did to make it work.

    1. Like Mike's recommendations. Uninstall/install db48/boost with brew.
    2. I deleted db48 from macports (just to be sure).
    3. relinked boost and db48 (brew unlink/link). Don't think it's entirely needed.
    4. make clean. <-- Absentmindedly, left this out.
  35. neverpanic commented at 2:40 PM on August 10, 2014: none

    I think this ticket should be closed. There's nothing wrong here from a bitcoin POV, since this only happens when somebody tries to use the wrong compiler or an incompatible boost.

    If anything, documentation could be improved to suggest using CXX=clang++ as argument to ./configure on OS X. The configure script could also be modified to default to that.

    Of course, somebody could modify configure.ac to link a test C++ binary, use otool -L $binary | grep -E lib(std)?c++ to figure out which C++ runtime is being used and check the boost library to be used for the same runtime – I'm just not sure that would be a good use of your time.

  36. midnightradio commented at 12:41 PM on August 20, 2014: none

    I had the same problem of getting the message "Undefined symbols for architecture x86_64" but with building different project, and got here from google, then finally solved my problem.

    From my past troubles with homebrew, I had got rid of it and just have been stuck only with macports. So none of things that are related to homebrew in this thread were helpful, but I got some hints that I haven't tried. And actually it is very simple way to try, so better to share it with hoping that someone would solve their problem with an easy action.

    In the past, some of my libraries were not familiar with clang++ and had to build other gcc ports. And my finding is that what I only need to do is switching back to Apple from GNU. I have three versions available for gcc, which are "apple-gcc42", "llvm-gcc42", and "mp-gcc48" which was in active. By running "port select --set gcc "apple-gcc42", I succeed linking with boost 1.55.0.

  37. laanwj closed this on Dec 30, 2014

  38. skaht commented at 4:12 AM on February 9, 2015: none

    FBSA,

    For OSX 10.9 environment using Homebrew, the latest "brew install boost" bottle fixed the pasted issue below. The boost brew a few months back is definitely sour...

    /usr/bin/ar -rs libleveldb.a db/builder.o db/c.o db/db_impl.o db/db_iter.o db/dbformat.o db/filename.o db/log_reader.o db/log_writer.o db/memtable.o db/repair.o db/table_cache.o db/version_edit.o db/version_set.o db/write_batch.o table/block.o table/block_builder.o table/filter_block.o table/format.o table/iterator.o table/merger.o table/table.o table/table_builder.o table/two_level_iterator.o util/arena.o util/bloom.o util/cache.o util/coding.o util/comparator.o util/crc32c.o util/env.o util/env_posix.o util/env_win.o util/filter_policy.o util/hash.o util/histogram.o util/logging.o util/options.o util/status.o port/port_posix.o ar: creating archive libleveldb.a /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: libleveldb.a(env_win.o) has no symbols

  39. deadalnix commented at 8:03 AM on February 2, 2016: none

    I get the exact same issue as in the first post on OSX, up to date, using brew.

    I think the problem come from some disagreement between gcc and clang, and I'm not sure this is actually fixable at this level.

  40. ironsniper commented at 5:58 PM on April 10, 2016: none

    im getting the same issue on 10.11.4 and for a while i had a working compiler, but someone asked if i could figure out how to compile for older versions of os x and so i did some research and uninstalled and reinstalled everything but now i cant get anything to compile due to the error in the op, does anyone have any advice? i am using macports

  41. markmark1 commented at 7:10 PM on August 17, 2017: none

    whats solution

  42. bibz0r commented at 7:24 PM on June 15, 2018: none

    Still have this problem

  43. MarcoFalke commented at 7:36 PM on June 15, 2018: member

    Is this fixed by building from depends?

    https://github.com/bitcoin/bitcoin/tree/master/depends

  44. DesWurstes commented at 2:12 PM on August 7, 2018: contributor

    @MarcoFalke Yes, I had the same issue and building from depends works. Thanks for the solution.

    In addition, I found the cause. Homebrew's and Macports's bottles are created using Clang. Since it's not interoperable with GCC, compiling Bitcoin Core with (either new or old) Clang should work.

  45. Bushstar referenced this in commit dc07a0c5e1 on Apr 8, 2020
  46. DrahtBot locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-21 18:16 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me