Search code examples
c++objective-cboostobjective-c++boost-thread

Linking Boost in Objective C and C++ combined xcode project


I am working on a project which combines both C++ classes using Boost and objective C classes. I am able to build it when I write a wrapper for using the Objective C classes in C++ but when I write a wrapper for C++ class in objective C, the project fails to build with Semantic error in boost/thread.hpp. More specifically in boost/type_traits/detail/mp_defer.hpp

I am using LLVM C++ with C++11 support

I am following the below link to wrap cross language classes. http://philjordan.eu/article/mixing-objective-c-c++-and-objective-c++

I referred to the below post but did not resolve my problem. Use boost library in cocoa project

Below are the list of errors:

struct mp_valid_impl
{
template<template<class...> class G, class = G<T...>>
static boost::true_type check(int); //use of undeclared identifier check

template<template<class...> class>
static boost::false_type check(...);

using type = decltype(check<F>(0));//Cannot refer to class template F without template argument list
};

template<template<class...> class F, class... T>
using mp_valid = typename mp_valid_impl<F, T...>::type; //No type named boost in 'boost::type_traits_detail::m_valid_impl< ...... >

additional failure logs:

  • /usr/local/boost/include/boost/type_traits/detail/mp_defer.hpp:37:1: No type named 'type' in 'boost::type_traits_detail::mp_valid_impl'

  • /usr/local/boost/include/boost/type_traits/detail/mp_defer.hpp:37:1: No type named 'type' in 'boost::type_traits_detail::mp_valid_impl'

  • /usr/local/boost/include/boost/thread/pthread/timespec.hpp:52:42: Invalid operands to binary expression ('const chrono::nanoseconds' (aka 'const duration >') and 'typename boost::enable_if > >, duration > >::type' (aka 'boost::chrono::duration >'))

  • /usr/local/boost/include/boost/chrono/duration.hpp:405:62: No type named 'type' in 'boost::common_type'

  • /usr/local/boost/include/boost/thread/pthread/condition_variable_fwd.hpp:239:38: Invalid operands to binary expression ('time_point' (aka 'time_point') and 'steady_clock::time_point' (aka 'time_point'))

  • /usr/local/boost/include/boost/chrono/duration.hpp:559:17: Cannot convert 'const duration >' to 'CD' (aka 'int') without a conversion operator

  • /usr/local/boost/include/boost/type_traits/detail/mp_defer.hpp:37:1: No type named 'type' in 'boost::type_traits_detail::mp_valid_impl'

I have been reading online and trying for hours, please help. Thanks


Solution

  • The boost thread library in version 1.61 seems to be not compatible with Objective C++ in LLVM-clang. I switched to use the native C++ Thread to replace by thread class based on Boost-thread.