How to create a Getting Started example using Xcode?

So, let's say you want to create Boost “Getting Started” examples and link them using the Xcode project, rather than creating them on the command line. You are trying to use only the header and it works great.

But then you take an example:

#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:

  • Create boost libraries using. / bjam install
  • Open Xcode and create a new C ++ command-line utility project.
  • Drag the libboost_regex.dylib file into the Products folder in the Groups and Files tree (checking the option that allows you to copy the file).
  • Set the project parameters so that the header search paths point to the folder with the Boost extension
  • Create and run a project!

Unfortunately, if you open the console (Run | Console), you will see an error that dylib cannot find:

 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 the best way to get Xcode for this, you copy dylib to your_project / build / debug / and it starts! Hooray!

The detail-oriented person that you are, you enter some things into the standard version to try:

 > Subject: foo bar baz > foo bar baz 

And then these are the segfaults.

 Program received signal: "EXC_BAD_ACCESS". 

ACK!

But do not be afraid. I know what the problem is! And if no one succeeds, I will send a solution after lunch.

+7
boost regex xcode
source share
2 answers

The problem is that the default build for enhancement does not work very well with your project debugging. You need to build boost using the debug option, which runs as follows:

 ./bjam install variant=debug define=_GLIBCXX_DEBUG --with-regex 

_GLIBCXX_DEBUG is actually an option in an Xcode project that causes a conflict.

You can then link the debug version of the library to the debug Xcode project. (I think this is how MacPorts precompiled binaries are created.)

Keep in mind that you can use the bjam option to create multiple goals at the same time.

Also: If after rebuilding it doesn’t work, make sure that the version of the library you are linking to is actually the one you just rebuilt!

Also: instead, you may need to remove the _GLIBCXX_DEBUG definition from your debug configuration. Double-click your executable in "Objectives" to open the project options, and then remove _GLIBCXX_DEBUG from the preprocessor macros.

Hope this helps.

+2
source share

I had the same error. I forgot to create the "Copy Files" build phase and copy the framework.

Go to the first button in the project navigator to show your files.

Click on your project to change the project settings. Click the target that you are using boost lib in. Click the Add Build Step button in the lower right corner. Select Add Copy Files. Change the Destination in Popup to Frameworks. Drag the libboost_regex.dylib file from the project navigator to the copy file table.

The link to the image does not work, so for screenshots: http://imgur.com/a/8ojye#6

+1
source share

All Articles