关于c ++:找不到XCode 4.5’tr1 / type_traits’文件

XCode 4.5 'tr1/type_traits' file not found

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

1
2
3
4
5
6
7
8
9
#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 ++标准库"设置为" libc ++"。 在这种情况下,您需要,而不是。 libc ++为您提供了C ++ 11库,而libstdc ++(这也是Xcode 4.5中的默认库)为您提供了一个具有tr1支持的C ++ 03库。

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

1
2
3
4
5
6
7
8
#include <ciso646>  // detect std::lib
#ifdef _LIBCPP_VERSION
// using libc++
#include <type_traits>
#else
// using libstdc++
#include <tr1/type_traits>
#endif

或者就您而言:

1
2
3
4
5
6
7
8
#include <ciso646>  // detect std::lib
#ifdef _LIBCPP_VERSION
// using libc++
#define HAVE_TYPE_TRAITS
#else
// using libstdc++
#define HAVE_TR1_TYPE_TRAITS
#endif


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

1
2
3
4
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

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

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

1
2
3
4
5
6
7
8
9
10
11
12
#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