C++, Mac OS X, Xcode 8 : Compile Boost : Set deplo

2019-03-02 04:51发布

问题:

I am trying to use Boost CPP library on Mac OS X 10.11.6. I downloaded the 1.62 version of Boost from official SourceForge repository. 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

Basically, I went to the directory and ran the "bootstrap.sh" and "b2" scripts.

Then I created a simple C++ program :

#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_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. It seems that while building Boost it sets the deployment target to OS X 10.12.

So the question is:

How can I set the deployment target to OS X 10.11 while building Boost?

回答1:

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. Hence, if you used toolset=darwin you would need to build as:

b2 macosx-version-min=10.11 ...

As that toolset has special handling of the OSX min version. Or, if you used toolset=clang you would need to build as:

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


标签: c++ macos boost