2

I'm trying to include Boost in my Xcode project and it seems no matter what I do the project doesn't want to compile.

I get this error every time:

Undefined symbols for architecture x86_64:

"boost::log::v2s_mt_posix::record_view::public_data::destroy(boost::log::v2s_mt_posix::record_view::public_data const*)", referenced from:
      boost::log::v2s_mt_posix::record::reset() in Logger.o
  "boost::log::v2s_mt_posix::attribute_set::insert(boost::log::v2s_mt_posix::attribute_name, boost::log::v2s_mt_posix::attribute const&)", referenced from:
      boost::log::v2s_mt_posix::sources::basic_logger<char, boost::log::v2s_mt_posix::sources::severity_logger<boost::log::v2s_mt_posix::trivial::severity_level>, boost::log::v2s_mt_posix::sources::single_thread_model>::add_attribute_unlocked(boost::log::v2s_mt_posix::attribute_name const&, boost::log::v2s_mt_posix::attribute const&) in Logger.o

(Along with a bunch of others totally 108 errors.)

I've tried a lot to fix this, and read pretty much every question on StackOverflow that is relevant to this.

I am linking it in "Link Binary With Items", I've got libboost_serialization.a and libboost_system.a there (only things in that list).

After installing Boost manually with the ./b2 command, I dragged both of those files into the sidebar. Therefore, the files are in the same directory as my .xcodeproj.

Under Library Search Paths, I have $(PROJECT_DIR), so it should be able to find them.

Am I compiling it with the wrong flags or something?

Doug Smith
  • 29,668
  • 57
  • 204
  • 388
  • 1
    Are you sure you compiled your boost libraries for x86_64 and not just i386? How did you build boost? – Kristian Duske Feb 06 '14 at 20:23
  • I believe I ran these commands: http://stackoverflow.com/a/8497667/998117 Should I try something else? – Doug Smith Feb 06 '14 at 20:29
  • You should try and find out whether you built a x86_64 library and then you need to make sure that you link your project against libc++ instead of libstdc++, just as you did with boost. – Kristian Duske Feb 06 '14 at 21:14
  • How do I do the latter? – Doug Smith Feb 06 '14 at 21:14
  • Click on your project in Xcode, then, in the filter box of the project properties, enter libc. It will show you a Setting named "C++ Standard Library" which you can then change. – Kristian Duske Feb 06 '14 at 21:15
  • Then when I try to build I get "clang: error: invalid deployment target for -stdlib=libc++ (requires OS X 10.7 or later)" and how do I figure out if my boost library is 64 bit or 32? – Doug Smith Feb 06 '14 at 21:17
  • Use the file command: http://stackoverflow.com/questions/3207177/how-to-check-if-a-library-is-32bit-64bit-built-on-mac-os-x – Kristian Duske Feb 06 '14 at 21:18
  • "libboost_serialization.a: current ar archive random library" – Doug Smith Feb 06 '14 at 21:19
  • I suppose the problem is that you linked boost against libc++ and link your program to libstdc++. Since you can't change your program to link against libc++ (assuming you don't want to set the deployment target to OX X 10.7), you have to rebuild boost and link it against libstdc++. – Kristian Duske Feb 06 '14 at 21:20
  • My program was linked to "Compiler Default" per that setting you mentioned. How would I go about rebuilding boost and linking it against libstdc++? Would I have to remove the current version somehow? – Doug Smith Feb 06 '14 at 21:21
  • For linking boost against libstdc++, you could try running ./b2 clean and then ./b2 toolset=clang cxxflags="-stdlib=libstdc++" linkflags="-stdlib=libstdc++" – Kristian Duske Feb 06 '14 at 21:23
  • Then you can overwrite the boost .a libraries in your project directory with the newly built ones. – Kristian Duske Feb 06 '14 at 21:25
  • So it doesn't install anything at the system level I should be wary of? Just need to build new .a files in the `stage/lib` folder? – Doug Smith Feb 06 '14 at 21:25
  • I don't know. If all else fails, you could try installing boost with macports or homebrew. – Kristian Duske Feb 06 '14 at 21:25
  • Just repeat what you did earlier: "After installing Boost manually with the ./b2 command, I dragged both of those files into the sidebar. " – Kristian Duske Feb 06 '14 at 21:26
  • Same error as last time unfortunately. – Doug Smith Feb 06 '14 at 22:06
  • Sorry, then I don't know what else to do. – Kristian Duske Feb 06 '14 at 22:31
  • You may want to use this script https://gist.github.com/emersonxsu/7188a128c28485b2533e and create a framework. Read the starting comments in script carefully. – Pradip Vaghasiya Jul 26 '15 at 06:27

1 Answers1

1

This solved the problem for me:

Rather than adding libboost_log-mt.* to the ‘Link Binary With Libraries’ section under the ‘Build Phases’ tab, add a path to the archive file (i.e., the .a; dynamic library doesn't work) in ‘Other Linker Flags’ under the ‘Build Settings’ tab:

Other Linker Flags under Build Settings

I have no explanation for why this works; but I've noticed that this technique has worked for me in the past with other libraries ‘not linking’ as well.

  • Quite close, I managed to finally get my project built by using the .dylib version, not .a, of both libboost_log-mt and libboost_log_setup-mt on boost 1.72 – Razvan Axinie Apr 01 '20 at 17:23