0
votes

Problem was solved by adding .dylib files (boost) to project.

I'm trying connect Boost 1.55 to Xcode 5 through Homebrew. Brew installed it as it should. In /usr/local/include && /usr/local/lib appeared aliases on Boost headers and libraries.

Xcode "Search Path" settings: http://i.imgur.com/j5GJ0sh.png http://i.imgur.com/DXRxiyA.png

But when I tried compile simple example:

#include <cstdlib>
#include <iostream>
#include <cstring>
#include <boost/regex.hpp>

using namespace std;
using namespace boost;

    int main()
    {
        const regex expression( "How to re" );

        string string1 = "How to re";

        bool match=regex_match(string1,expression);

        if (match){
            cout<<"Yes"<<endl;
        }

        return 0;
    }

Errors:

Undefined symbols for architecture x86_64: "boost::basic_regex >

::do_assign(char const*, char const*, unsigned int)", referenced from: boost::basic_regex > >::assign(char const*, char const*, unsigned int) in main.o "boost::re_detail::get_mem_block()", referenced from: boost::re_detail::perl_matcher, std::__1::allocator > >, boost::regex_traits > ::extend_stack() in main.o boost::re_detail::save_state_init::save_state_init(boost::re_detail::saved_state**, boost::re_detail::saved_state**) in main.o
"boost::re_detail::put_mem_block(void*)", referenced from: boost::re_detail::save_state_init::~save_state_init() in main.o boost::re_detail::perl_matcher, std::__1::allocator > >, boost::regex_traits > ::unwind_extra_block(bool) in main.o "boost::re_detail::verify_options(unsigned int, boost::regex_constants::_match_flags)", referenced from: boost::re_detail::perl_matcher, std::__1::allocator > >, boost::regex_traits > ::match_imp() in main.o "boost::re_detail::raise_runtime_error(std::runtime_error const&)", referenced from: void boost::re_detail::raise_error > > (boost::regex_traits_wrapper > > const&, boost::regex_constants::error_type) in main.o
"boost::re_detail::get_default_error_string(boost::regex_constants::error_type)", referenced from: boost::re_detail::cpp_regex_traits_implementation::error_string(boost::regex_constants::error_type) const in main.o
"boost::re_detail::cpp_regex_traits_implementation::transform_primary(char const*, char const*) const", referenced from: boost::cpp_regex_traits::transform_primary(char const*, char const*) const in main.o
"boost::re_detail::cpp_regex_traits_implementation::transform(char const*, char const*) const", referenced from: boost::cpp_regex_traits::transform(char const*, char const*) const in main.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

Really tired with it, so, ask for your help.

Thank you, - Philipp

1
I didn't see it in the screenshots, but did you link in boost either with -l or manually in Xcode?sbooth
No. Can you tell me, how can I do this?RussDragon
I don't know what options homebrew uses for building boost, but see boost.org/doc/libs/1_55_0/more/getting_started/… for more help. If you post the contents of /usr/local/lib that will help also.sbooth
pastebin.com/RiXmwHGP All of these files — aliases. After I had added .dylib files of boost libraries, it started work. But, as I know, with brew installing I shouldn't add any files to project.RussDragon

1 Answers

2
votes

You have a few options but all of them involve adding the library libboost_regex to your project to resolve the link errors. Even though you installed boost using homebrew, you still need to add the library to your project because boost's regex code contains a compiled portion. If you don't add the library there is no way for the linker to resolve the symbols.

The first option is to add /usr/local/lib to Library Search Paths, and add -lboost_regex to Other Linker Flags. If you choose this option you may need to add /usr/local/lib to Runpath Search Paths also. This method will link against the dynamic library in /usr/local/lib.

If you want your program to be self-contained you can link against the static (.a) version of boost_regex. To do this add libboost_regex.a to your project in Build Settings - Link Binary With Libraries.