[英]How do I add the boost library to Xcode 11? C++
I cannot find a way to add boost in Xcode 11.2.1.我找不到在 Xcode 11.2.1 中添加 boost 的方法。 I found a setting under the target called "Frameworks and Libraries".我在目标下找到了一个名为“框架和库”的设置。 I dragged the boost directory there, and it got added to the "Frameworks" section of the project.我将 boost 目录拖到那里,它被添加到项目的“框架”部分。 However, in building the project, it says "file not found".但是,在构建项目时,它说“找不到文件”。 For example:例如:
#include <boost/lambda/lambda.hpp>
results in a "file not found" error.导致“找不到文件”错误。 Instead of adding boost, I dragged the entire include area of Macports.我没有添加 boost,而是拖动了 Macports 的整个包含区域。 It took a while for Xcode to parse through that, but I get the same error. Xcode 花了一段时间来解析它,但我得到了同样的错误。 So, under Frameworks it has "include", but it cannot find the relevant hpp file, even though I checked and it's there in the boost tree.所以,在框架下它有“包含”,但它找不到相关的 hpp 文件,即使我检查过它在 boost 树中。
I have installed boost via Macports.我已经通过 Macports 安装了 boost。 It resides in /opt/local/include/boost.它位于 /opt/local/include/boost 中。
In the Xcode documentation, I saw a reference to "USER_HEADER_SEARCH_PATHS".在 Xcode 文档中,我看到了对“USER_HEADER_SEARCH_PATHS”的引用。 I figured how to set that in a configuration file, so I added a configuration file to the project.我想出了如何在配置文件中设置它,所以我在项目中添加了一个配置文件。 I added this to the configuration file: USER_HEADER_SEARCH_PATHS = /opt/local/include/boost but that does not work either.我将此添加到配置文件中: USER_HEADER_SEARCH_PATHS = /opt/local/include/boost 但这也不起作用。 (If I remove the boost, that does not work either). (如果我取消提升,那也不起作用)。
When I select "include" in the Frameworks location of the project, I see that there are different settings "Identity and Type" for that object (right side of Xcode window).当我在项目的框架位置选择“包含”时,我看到该对象(Xcode 窗口的右侧)有不同的设置“身份和类型”。 I selected "absolute path" and it shows the full path as /opt/local/include which is correct.我选择了“绝对路径”,它将完整路径显示为 /opt/local/include,这是正确的。 However, this does not solve the problem either.然而,这也不能解决问题。
Do I need to create a link in a pre-defined area so that Xcode can find it?我是否需要在预定义区域中创建链接以便 Xcode 可以找到它?
I did find a rather ugly work-around: create a soft link to the boost library in the same area where the STL resides (within the Xcode.app directory structure).我确实找到了一个相当丑陋的解决方法:在 STL 所在的同一区域(在 Xcode.app 目录结构中)创建一个到 boost 库的软链接。
Using the setting only works with individual files.使用该设置仅适用于单个文件。 I can add individual file to the setting (via drag and drop), but it won't follow nested directories, so clearly this will not work for a library implemention such as boost.我可以将单个文件添加到设置中(通过拖放),但它不会遵循嵌套目录,所以很明显这不适用于诸如 boost 之类的库实现。
I prefer to keep dependent libraries inside project area.我更喜欢将依赖库保留在项目区域内。 So here is how I just do it for test:所以这就是我如何进行测试:
Create new TestBoost project in Xcode from macOS Command-line App
C++ template从macOS Command-line App
C++ 模板在 Xcode 中创建新的 TestBoost 项目
(now there is TestBoost folder where TestBoost.xcodeproj is located) (现在有 TestBoost.xcodeproj 所在的 TestBoost 文件夹)
Download latest boost
boost_1_72_0.tar.gz and unarchive it下载最新的boost
boost_1_72_0.tar.gz并解压
(now there boost_1_72_0
folder with boost) (现在有boost_1_72_0
文件夹与 boost)
Copy boost_1_72_0
folder inside project TestBoost
folder, so it is located aside of TestBoost.xcodeproj将boost_1_72_0
文件夹复制到项目TestBoost
文件夹中,因此它位于 TestBoost.xcodeproj 旁边
In Xcode Project Navigator select TestBoost
project > select TestBoost
target > select Build Settings
tab在 Xcode 项目导航器中选择TestBoost
项目 > 选择TestBoost
目标 > 选择Build Settings
选项卡
In Search Paths
section select Header Search Path
, double click on value area and enter ${SRCROOT}/boost_1_72_0
(leave non-recursive
flag)在Search Paths
部分选择Header Search Path
,双击值区域并输入${SRCROOT}/boost_1_72_0
(保留non-recursive
标志)
Delete default main.cpp
from TestBoost
target (to avoid main function confusing) and add some example from boost for testing, eg.从TestBoost
目标中删除默认main.cpp
(以避免主函数混淆)并从 boost 中添加一些示例进行测试,例如。 boost_1_72_0/libs/algorithm/example/search_example.cpp
Build & Run > Success构建和运行 > 成功
Output:输出:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.