简体   繁体   English

C ++,Mac OS X,Xcode 8:编译Boost:将部署目标设置为OS X 10.11

[英]C++, Mac OS X, Xcode 8 : Compile Boost : Set deployment target to OS X 10.11

I am trying to use Boost CPP library on Mac OS X 10.11.6. 我正在尝试在Mac OS X 10.11.6上使用Boost CPP库。 I downloaded the 1.62 version of Boost from official SourceForge repository. 我从官方SourceForge存储库下载了1.62版本的Boost。 Extracted it and built is as per the docs here: http://www.boost.org/doc/libs/1_62_0/more/getting_started/unix-variants.html 提取并构建它的方法如下: http : //www.boost.org/doc/libs/1_62_0/more/getting_started/unix-variants.html

Basically, I went to the directory and ran the "bootstrap.sh" and "b2" scripts. 基本上,我进入目录并运行“ bootstrap.sh”和“ b2”脚本。

Then I created a simple C++ program : 然后,我创建了一个简单的C ++程序:

#include <iostream>
#include <string>

#include <boost/algorithm/string.hpp>
#include <boost/regex.hpp>

int main() {
  std::string str1(" hello world! ");
  boost::to_upper(str1);

  std::cout << str1 << std::endl;

  std::string s = " Boost Libraries ";
  boost::regex expr{"\\s"};
  std::string fmt{"_"};
  std::cout << boost::regex_replace(s, expr, fmt) << '\n';

  return 0;
}

And tried to build it with the following CMake file 并尝试使用以下CMake文件进行构建

cmake_minimum_required(VERSION 2.8.9)

set(CMAKE_CXX_FLAGS "-std=c++11 -stdlib=libc++")

project(app_project)

set(Boost_USE_STATIC_LIBS ON) 
set(Boost_USE_MULTITHREADED ON)  
set(Boost_USE_STATIC_RUNTIME ON) 

find_package(Boost 1.62.0 COMPONENTS regex) 

if(Boost_FOUND)
    include_directories(${Boost_INCLUDE_DIRS}) 
    add_executable(myapp main.cpp)
    target_link_libraries(myapp ${Boost_LIBRARIES})
endif()

When I make the program I get following warnings: 当我制作程序时,收到以下警告:

ld: warning: object file (/Users/pritam/opt/boost_1_62_0/stage/lib/libboost_regex.a(instances.o)) was built for newer OSX version (10.12) than being linked (10.11)
ld: warning: object file (/Users/pritam/opt/boost_1_62_0/stage/lib/libboost_regex.a(regex.o)) was built for newer OSX version (10.12) than being linked (10.11)
ld: warning: object file (/Users/pritam/opt/boost_1_62_0/stage/lib/libboost_regex.a(regex_traits_defaults.o)) was built for newer OSX version (10.12) than being linked (10.11)
ld: warning: object file (/Users/pritam/opt/boost_1_62_0/stage/lib/libboost_regex.a(regex_raw_buffer.o)) was built for newer OSX version (10.12) than being linked (10.11)
ld: warning: object file (/Users/pritam/opt/boost_1_62_0/stage/lib/libboost_regex.a(cpp_regex_traits.o)) was built for newer OSX version (10.12) than being linked (10.11)
ld: warning: object file (/Users/pritam/opt/boost_1_62_0/stage/lib/libboost_regex.a(static_mutex.o)) was built for newer OSX version (10.12) than being linked (10.11)

I have XCode 8 installed on this machine. 我在此计算机上安装了XCode 8。 It seems that while building Boost it sets the deployment target to OS X 10.12. 似乎在构建Boost时,它将部署目标设置为OS X 10.12。

So the question is: 所以问题是:

How can I set the deployment target to OS X 10.11 while building Boost? 构建Boost时如何将部署目标设置为OS X 10.11?

To target a minimum OSX version lower than your current OSX version you are building from you need to set the -mmacosx-version-min option. 要将最低OSX版本定位为低于当前要构建的OSX版本,您需要设置-mmacosx-version-min选项。 Hence, if you used toolset=darwin you would need to build as: 因此,如果使用toolset=darwin ,则需要构建为:

b2 macosx-version-min=10.11 ...

As that toolset has special handling of the OSX min version. 由于该工具集对OSX min版本具有特殊处理。 Or, if you used toolset=clang you would need to build as: 或者,如果您使用toolset=clang ,则需要构建为:

b2 cflags=-mmacosx-version-min=10.11 cxxflags=-mmacosx-version-min=10.11 mflags=-mmacosx-version-min=10.11 mmflags=-mmacosx-version-min=10.11 linkflags=-mmacosx-version-min=10.11 ...

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

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