XCode 4.5中找不到'tr1/type_traits'文件

7

我使用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未被找到。我使用的是带有c++11方言的Apple LLVM编译器4.1。 如果我切换到LLVM GCC 4.2编译器,那么就不会有错误,但主要问题是所有c++11包含都无法工作。

我应该如何使用GCC编译器,但标准为c++11或者使LLVM能够找到?

非常感谢任何帮助。

3个回答

13

我猜你将"C++标准库"设置为"libc++"。如果是这种情况,你需要使用<type_traits>而不是<tr1/type_traits>。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库解决了我的问题 :-) - Jon Cage

5

这是我用来针对libc++(LLVM C++标准库)构建wxWidgets的命令。应该适用于Yosemite及更高版本(至少在苹果再次破坏一切之前):

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

0
稍微修改了上面的代码,以避免编译器的投诉:
将以下内容粘贴到 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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接