问题描述
所以我们说要打造提升入门的例子,并链接到他们使用X code项目,而不是在命令行建设。您尝试唯一的头选项,它工作正常。
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;
}
}
和你做以下内容:
- 使用./bjam安装构建Boost库
- 开启X code和创建一个新的C ++命令行实用程序的项目。
- 将libboost_regex.dylib入组&放大器的产品文件夹;文件树视图(检查,允许它复制文件的选项)
- 设置项目选项,使头搜索路径指向升压包含文件夹
- 构建和运行项目!
不幸的是,如果你打开控制台(运行|控制台),你会看到一个错误,它无法找到dylib:
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
所以,不知道有更好的方式来获得X code到做到这一点,你复制到dylib your_project /编译/调试/它运行!万岁!
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
和则出现segfaults。
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.
推荐答案
这里的问题是,提升的默认版本不与您的项目的调试版本中打出好成绩。您需要使用调试版本,也就是这样做是为了打造提升:
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
实际上是在导致冲突在X code项目的选项。
_GLIBCXX_DEBUG
is actually the option in the Xcode project that is causing the conflict.
然后,你可以用你的调试X code ++项目链接库的调试版本。 (我认为这是MacPorts的precompiled二进制文件是如何产生的。)
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.)
请记住,你可以使用的bjam变量同时建立多个目标。
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!
另外:相反,它可能工作,去掉你的调试配置中的 _GLIBCXX_DEBUG
定义。在目标双击可执行文件打开项目选项,然后从preprocessor宏删除 _GLIBCXX_DEBUG
。
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.
希望这有助于。
这篇关于如何构建升压&QUOT;入门&QUOT;利用X code的例子吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!