Why some include files only reside in tr1?
Asked Answered
R

3

7

When I try to include things like <unordered_map> it fails and says the file doesn't exist, while when I try to include <tr1/unordered_map> it works. however, the include files that are present also in c++03 are found, and are c++11 (like <vector> has move constructor). Also, headers that are only in c++11 and not in tr1 are found normally as well, like <thread>.
Its like everything that was new in tr1 was just thrown into tr1 folder and everything else into normal include.
Why is this happening? Is there any fix to it without modifying source files?
Passing -I/path/to/include/tr1 won't work because everything is in the tr1 namespace.
The compiler I'm using is

Apple clang version 3.0 (tags/Apple/clang-211.10.1) (based on LLVM 3.0svn)
Rawdon answered 24/10, 2011 at 2:50 Comment(3)
Have you considered that your compiler/standard library implementation simply may not be complete?Abednego
Echoing @NicolBolas, what standard library are you using? What version/revision number?Errata
Also, I'd suggest tagging the compiler and standard library you are using here to get a bit more focused attention from folks that work on them.Errata
Z
11

TR1 (technical report 1) is not a standard, but merely a report. It is an official way of letting people know that the committee is interested in this area. Any tr1 implementation is an experimental release aimed at getting field feedback for the purpose of bettering a future standard.

Using Apple's Xcode 4.2 you can choose a nearly complete C++11 library by searching your build settings for "libc++" and then choose "libc++" as the C++ Standard Library (it is not the default).

Or if you prefer the command line you can -stdlib=libc++.

libc++ does not contain any tr1 components, but does contain all of C++11 except for <atomic>.

Zenobia answered 24/10, 2011 at 13:9 Comment(1)
Thanks, I thought -lc++ was the switch for the new standard library. with -stdlib=libc++ its working great.Rawdon
O
7

Add both the following parameters to clang++:

-std=c++11 -stdlib=libc++ 
Osprey answered 21/8, 2013 at 21:7 Comment(3)
Sorry for being a noob, How do I add these parameters to clang++? <-- configuring macports...Earreach
@BeshoyGirgis I don't know about macports. But generally from a command line: clang++ somefile.cpp -std=c++11 -stdlib=libc++Osprey
+1; this worked for me in CMake: set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -stdlib=libc++")Rostov
A
1

Yes different compilers treat TR1 headers differently. GCC for example does the same thing that you experienced whereas MVS accepts <unordered_map>. One way to work around it is to use boost/tr1/unordered_map.hpp if cross platform or multiple compiler compilation is necessary for you.

Araliaceous answered 24/10, 2011 at 10:58 Comment(1)
MVS = Microsoft Visual Studio I guess.Patrizius

© 2022 - 2024 — McMap. All rights reserved.