链接Boost在Objective C和c++结合xcode项目

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

本文关键字:c++ 结合 xcode 项目 Boost Objective 链接      更新时间:2023-10-16

我正在做一个项目,它结合了使用Boost和objective C类的c++类。当我在c++中编写使用Objective C类的包装器时,我能够构建它,但是当我在Objective C中编写c++类的包装器时,该项目无法在boost/thread.hpp中构建语义错误。更具体地说,在boost/type_traits/detail/mp_deff .hpp

我正在使用LLVM c++与c++ 11支持

我正在跟随下面的链接来包装跨语言课程。http://philjordan.eu/article/mixing-objective-c-c + + -and-objective-c + +

我参考了下面的帖子,但没有解决我的问题。在cocoa项目中使用boost库

下面是错误列表:

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

附加故障日志:

  • /usr/local/boost/include/boost/type_traits/detail/mp_deff .hpp:37:1:在'boost::type_traits_detail::mp_valid_impl'中没有名为'type'的类型

  • /usr/local/boost/include/boost/type_traits/detail/mp_deff .hpp:37:1:在'boost::type_traits_detail::mp_valid_impl'中没有名为'type'的类型

  • /usr/local/boost/include/boost/thread/pthread/timespec.hpp:52:42:二进制表达式('const chrono::nanoseconds'(即'const duration>')和'typename boost::enable_if>>, duration>>::type'(即'boost::chrono::duration>')

  • /usr/local/boost/include/boost/chrono/duration.hpp:405:62: 'boost::common_type'中没有名为'type'的类型

  • /usr/local/boost/include/boost/thread/pthread/condition_variable_fwd.hpp: 2339:38:二进制表达式('time_point'(又名'time_point')和'steady_clock::time_point'(又名'time_point'))无效的操作数

  • /usr/local/boost/include/boost/chrono/duration.hpp:559:17:没有转换操作符

  • 无法将'const duration>'转换为'CD'(也称为'int')
  • /usr/local/boost/include/boost/type_traits/detail/mp_deff .hpp:37:1:在'boost::type_traits_detail::mp_valid_impl'中没有名为'type'的类型

我一直在网上阅读和尝试几个小时,请帮助。由于

A)文件扩展名

LLVM-clang会自动理解文件扩展名,并使用正确的参数clang编译程序。

将文件重命名为.mm扩展名

或者用-x objective-c++选项编译

CXXLAGS += -x objective-c++
B)标头包含

如果您缺少include头,那么您需要添加以下

CXXLAGS += -I/path/to/boost/

/path/to/boost是编译后的boost库目录。

1.61版本的boost线程库似乎与LLVM-clang中的Objective c++不兼容。我改用本地c++ Thread,用基于Boost-thread的线程类代替。