【问题标题】:Linking Boost in Objective C and C++ combined xcode project在 Objective C 和 C++ 结合的 xcode 项目中链接 Boost
【发布时间】:2017-02-17 01:33:54
【问题描述】:

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

我正在使用支持 C++11 的 LLVM C++

我按照下面的链接来包装跨语言类。 http://philjordan.eu/article/mixing-objective-c-c++-and-objective-c++

我参考了以下帖子,但没有解决我的问题。 Use boost library in cocoa project

以下是错误列表:

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_defer.hpp:37:1:'boost::type_traits_detail::mp_valid_impl'中没有名为'type'的类型

  • /usr/local/boost/include/boost/type_traits/detail/mp_defer.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:239:38:二进制表达式 ('time_point' (aka '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_defer.hpp:37:1:'boost::type_traits_detail::mp_valid_impl'中没有名为'type'的类型

我一直在网上阅读并尝试了几个小时,请帮助。 谢谢

【问题讨论】:

  • 我回答了您的问题,但您应该在此处发布完整的错误日志以确保该答案正确。
  • @NulledPointer 我的文件扩展名是 .mm,我还指定了文件类型为 Objective C++ Source

标签: c++ objective-c boost objective-c++ boost-thread


【解决方案1】:

A) 文件扩展名

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

将您的文件重命名为 .mm 扩展名。

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

CXXLAGS += -x objective-c++

B) 标题包括

如果您缺少包含标题,那么您需要添加以下内容

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

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

【讨论】:

    【解决方案2】:

    1.61 版本的 boost 线程库似乎与 LLVM-clang 中的 Objective C++ 不兼容。我转而使用原生 C++ Thread 来替换为基于 Boost-thread 的线程类。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-10
      • 2018-08-19
      • 1970-01-01
      • 1970-01-01
      • 2011-01-31
      • 1970-01-01
      相关资源
      最近更新 更多