【问题标题】:XCode 4.5 'tr1/type_traits' file not foundXCode 4.5 'tr1/type_traits' 文件未找到
【发布时间】:2012-10-24 12:22:24
【问题描述】:

我使用 wxwidget 库,遇到以下问题:

#if defined(HAVE_TYPE_TRAITS)
    #include <type_traits>
#elif defined(HAVE_TR1_TYPE_TRAITS)
    #ifdef __VISUALC__
        #include <type_traits>
    #else
        #include <tr1/type_traits>
    #endif
#endif

这里找不到#include。我使用 Apple LLVM 编译器 4.1。 (使用 c++11 方言)。 如果我切换到 LLVM GCC 4.2 编译器,我没有错误,但主要问题是所有 c++11 包含都不起作用。

如何使用 GCC 编译器,但使用 c++11 标准,或者如何使 LLVM 可以找到?

任何帮助将不胜感激。

【问题讨论】:

    标签: c++ c++11 wxwidgets xcode4.5


    【解决方案1】:

    我猜您已将“C++ 标准库”设置为“libc++”。如果是这种情况,您需要&lt;type_traits&gt;,而不是&lt;tr1/type_traits&gt;。 libc++ 为您提供 C++11 库,而 libstdc++(也是 Xcode 4.5 中的默认库)为您提供支持 tr1 的 C++03 库。

    如果需要,您可以自动检测正在使用的库:

    #include <ciso646>  // detect std::lib
    #ifdef _LIBCPP_VERSION
    // using libc++
    #include <type_traits>
    #else
    // using libstdc++
    #include <tr1/type_traits>
    #endif
    

    或者在你的情况下:

    #include <ciso646>  // detect std::lib
    #ifdef _LIBCPP_VERSION
    // using libc++
    #define HAVE_TYPE_TRAITS
    #else
    // using libstdc++
    #define HAVE_TR1_TYPE_TRAITS
    #endif
    

    【讨论】:

    • 谢谢 - 有同样的问题,更改为 gnu 库为我解决了它:-)
    【解决方案2】:

    稍微修改了上面的代码,以避免编译器抱怨:

    将以下内容粘贴到 strvararg.h 的 #ifdefined (HAVE_TYPE_TRAITS) 之前

    #include <ciso646>  // detect std::lib
    #ifdef _LIBCPP_VERSION
    // using libc++
    #ifndef HAVE_TYPE_TRAITS
    #define HAVE_TYPE_TRAITS 1
    #endif
    #else 
    // using libstdc++
    #ifndef HAVE_TR1_TYPE_TRAITS
    #define HAVE_TR1_TYPE_TRAITS 1
    #endif
    #endif
    

    【讨论】:

      【解决方案3】:

      这是我用来针对 libc++(LLVM C++ 标准库)构建 wxWidgets 的命令。应该在优胜美地及以后工作(至少在苹果再次破坏一切之前):

      mkdir build-cocoa-debug
      cd build-cocoa-debug
      ../configure --enable-debug --with-macosx-version-min=10.10
      make -j8 #This allows make to use 8 parallel jobs
      

      【讨论】:

        猜你喜欢
        • 2012-12-31
        • 1970-01-01
        • 2012-10-17
        • 1970-01-01
        • 1970-01-01
        • 2020-02-02
        • 1970-01-01
        • 2017-01-23
        • 1970-01-01
        相关资源
        最近更新 更多