简体   繁体   中英

How do I add the boost library to Xcode 11? C++

I cannot find a way to add boost in Xcode 11.2.1. 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. 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. It took a while for Xcode to parse through that, but I get the same error. 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.

I have installed boost via Macports. It resides in /opt/local/include/boost.

In the Xcode documentation, I saw a reference to "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. (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). I selected "absolute path" and it shows the full path as /opt/local/include which is correct. 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?

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).

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.

I prefer to keep dependent libraries inside project area. So here is how I just do it for test:

  1. Create new TestBoost project in Xcode from macOS Command-line App C++ template
    (now there is TestBoost folder where TestBoost.xcodeproj is located)

  2. Download latest boost boost_1_72_0.tar.gz and unarchive it
    (now there boost_1_72_0 folder with boost)

  3. Copy boost_1_72_0 folder inside project TestBoost folder, so it is located aside of TestBoost.xcodeproj

  4. In Xcode Project Navigator select TestBoost project > select TestBoost target > select Build Settings tab

  5. In Search Paths section select Header Search Path , double click on value area and enter ${SRCROOT}/boost_1_72_0 (leave non-recursive flag)

  6. Delete default main.cpp from TestBoost target (to avoid main function confusing) and add some example from boost for testing, eg. boost_1_72_0/libs/algorithm/example/search_example.cpp

  7. Build & Run > Success

Output:Xcode 11 增强集成

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM