2012-11-04 55 views
5

我使用wxwidget库,我有以下问题:的XCode 4.5 'TR1/type_traits' 找不到文件

#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能够找到?

任何帮助将非常感激。

回答

12

我猜你已将“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 
+0

谢谢,这个问题解决了 – Aranir

+0

谢谢 - 有同样的问题,并更改为GNU库解决了这个问题对我来说:-) –

0

稍加修改上面的代码,以避免编译器投诉:

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

#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 
0

这是我用来构建针对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