So let's say you want to build the Boost "Getting Started" examples and link to them using an Xcode project rather than building at the command line. You try the header-only option and it works fine.
But then you take the example source:
#include <boost/regex.hpp>
#include <iostream>
#include <string>
int main()
{
std::string line;
boost::regex pat( "^Subject: (Re: |Aw: )*(.*)" );
while (std::cin)
{
std::getline(std::cin, line);
boost::smatch matches;
if (boost::regex_match(line, matches, pat))
std::cout << matches[2] << std::endl;
}
}
And you do the following:
Sadly, if you have the console open (Run | Console) you're going to see an error that it can't find the dylib:
dyld: Library not loaded: libboost_regex.dylib
Referenced from: /Users/matt/Documents/Boost/test/GettingStarted/build/Debug/GettingStarted
Reason: image not found
So, not knowing a better way to get Xcode to do this, you copy the dylib into your_project/build/debug/ and it runs! Hooray!
Detail-oriented person that you are, you type some stuff into standard in to try it out:
> Subject: foo bar baz
> foo bar baz
And then it segfaults.
Program received signal: “EXC_BAD_ACCESS”.
ACK!
But have no fear. I know what the problem is! And if nobody beats me to it, I'll post the solution after lunch.
To compile anything in Boost, you need a directory containing the boost/ subdirectory in your #include path. depending on your preference regarding the use of angle bracket includes. Don't be distracted by the doc/ subdirectory; it only contains a subset of the Boost documentation. Start with libs/index.
The problem here is that the default build of boost doesn't play well with your project's debug build. You need to build boost using the debug variant, which is done like this:
./bjam install variant=debug define=_GLIBCXX_DEBUG --with-regex
_GLIBCXX_DEBUG
is actually the option in the Xcode project that is causing the conflict.
Then you can link the debug version of the library with your debug Xcode project. (I think this is how the MacPorts precompiled binaries are produced.)
Keep in mind that you can use bjam variant to build multiple targets at the same time.
Also: If it doesn't work after the rebuild, check to be sure that the version of the library you're linking with is actually the one you just rebuilt!
Also: Instead, it might work to remove the _GLIBCXX_DEBUG
define from your debug configuration. Double-click your executable in Targets to open the project options, and then remove _GLIBCXX_DEBUG
from the preprocessor macros.
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With