简体   繁体   English

如何在XCode中正确包含Boost文件(C ++第三方库)?

[英]How do you properly include Boost files (C++ third party library) in XCode?

I'm running Mac OSX 10.9.2 (Mavericks) and I use Xcode 5.1. 我正在运行Mac OSX 10.9.2(Mavericks),并且使用Xcode 5.1。

I've been doing tons of researching into how to properly include Boost files in my program, but I simply can't do it. 我一直在研究如何在程序中正确包含Boost文件,但是我做不到。 I currently have boost saved at /usr/local/include/boost/. 我目前将boost保存在/ usr / local / include / boost /中。 Whenever I tried to include boost files, it either doesn't compile, or it can't find the file, or if it does find the file, it collides with some other file that already exists (that's what it seems like to me). 每当我尝试包含boost文件时,它要么无法编译,要么无法找到文件,或者如果确实找到了文件,它就会与已经存在的其他文件发生冲突(这对我来说就是这样) 。 Can someone please provide a detailed explanation of how to do this properly and preferably provide a code snippet of some sort? 有人可以提供有关如何正确执行此操作的详细说明,并且最好提供某种代码段吗? Please include several different boost files (ie, ones that exist at the top level of the boost directory, but also those that exist within subdirectories, like algorithm files). 请包括几个不同的boost文件(即存在于boost目录顶层的文件,也包括存在于子目录中的文件,例如算法文件)。

There are essentially two types of inclusions when using boost library: 使用boost库时,本质上包含两种类型的包含:

  1. Libraries 图书馆
  2. Include only templates 仅包含模板

For example, array is a template only include, so when compiling you need to send this flag to your clang: -I/usr/local/include/ 例如,array是仅包​​含的模板,因此在编译时,需要将此标志发送给您的clang:-I / usr / local / include /

this way when including the array you would do it like this: 这样,当包含数组时,您将像这样:

#include "boost/array.hpp"

When including a library you must build boost on your system, using the b2 batch files. 包含库时,必须使用b2批处理文件在系统上构建boost。 Then you build using the bjam system. 然后,使用bjam系统进行构建。

When the libs are build you have to link them to your clang, the flags are a bit different than mere include files, for example lets suppose you want to include the boost regex library which on your system will be named libboost_regex.so, thus you need to tell your compiler the following two flags: 构建库时,必须将它们链接到您的clang,标志与仅包含文件有点不同,例如,假设您要包含boost regex库,该库在您的系统上将命名为libboost_regex.so,因此您需要告诉您的编译器以下两个标志:

-L/usr/local/{boost_build_place}/lib -lboost_regex

The -L tells your compiler about a folder of libraries you are including to your project and the -l flag tells about the specific library you want, as you can see, when using the -l flag you must remove the lib preamble and the .so . 如您所见, -L告诉编译器您要包含到项目中的库的文件夹, -l标志告诉您要使用的特定库,如所见,使用-l标志时,必须删除lib前言和.so

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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