48

is it possible to get the source code for standard c++ library?

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
Southsouth
  • 2,659
  • 6
  • 32
  • 39
  • 21
    Keep in mind you're misleading yourself by saying "*the* source code". The C++ language is only described by the standard, as is the behavior of the standard library. What you can find is *a single implementation* of the standard library, not *the* single. – GManNickG Jan 05 '10 at 06:31
  • @GManNickG: Also, it's at least partially built into the compiler itself. In fact, it's not required to have any separate code at all. – Mooing Duck Oct 23 '14 at 17:54
  • 1
    And here is how you hack up the GCC libstdc++ source and rebuild it: https://stackoverflow.com/questions/21872229/editing-and-building-libstdc-source/51946224#51946224 – Ciro Santilli OurBigBook.com Aug 21 '18 at 10:07

10 Answers10

25

The GNU project is Free and Open Source software, and contains an implementation of the C++ standard library.

http://gcc.gnu.org/libstdc++/

Grant Paul
  • 5,852
  • 2
  • 33
  • 36
  • i followed the link to http://mirror.clarkson.edu/gnu/... still no idea which one is standard c++ lib – Southsouth Jan 05 '10 at 04:56
  • Really? Any of the tarballs in here should extract to the standard c++ lib source: http://mirror.clarkson.edu/gnu/libstdc++/ – Michael Greene Jan 05 '10 at 05:05
  • if you have git installed try this git init git remote add origin git://gcc.gnu.org/git/gcc.git git config --add remote.origin.fetch 'refs/remotes/*:refs/remotes/svn/*' git fetch git checkout -b trunk svn/trunk – human.js Jan 24 '15 at 07:32
  • Any idea in which source file SET is implemented? – Dean Jan 21 '18 at 10:21
  • The above link now takes you to the main GNU gcc page, and source must be downloaded with git. A class like std::set appears to be mostly defined in ./gcc/libstdc++-v3/include/bits/stl_set.h. – JPhi1618 Apr 29 '20 at 20:13
17

You should already have the sources in your compiler installation. If you are using an IDE with a "jump to include file" command, select any STL header and jump to it. If you are using some kind of UNIX, look in /usr/include/c++. See where that STL header includes other headers and recurse :v) .

Potatoswatter
  • 134,909
  • 25
  • 265
  • 421
  • 3
    `/usr/lib/gcc/$CTARGET/$VERSION/include/g++-v4/` on my standard Linux system. – ephemient Jan 05 '10 at 05:39
  • 2
    Huh, the GCC manpage seems to indicate that is a more likely location, but it has only a few random low-level things (no STL) in standard OS X. Maybe `locate iostream` is a good solution. – Potatoswatter Jan 05 '10 at 06:45
16

If you have Visual Studio Professional, it has source code in

X:\Microsoft Visual Studio 9.0\VC\crt\src

wallyk
  • 56,922
  • 16
  • 83
  • 148
11

This is it :

https://github.com/gcc-mirror/gcc/tree/master/libstdc%2B%2B-v3

As a part of gcc source code

https://github.com/gcc-mirror/gcc

that's the std library for c++

i think this is the only answer with the direct one click link

Hassen Dhia
  • 555
  • 4
  • 11
7

libc++ is the C++ Standard Library of LLVM.

All of the code in libc++ is dual licensed under the MIT license and the UIUC License (a BSD-like license).

  • Correctness as defined by the C++11 standard.
  • Fast execution.
  • Minimal memory use.
  • Fast compile times.
  • ABI compatibility with gcc's libstdc++ for some low-level features such as exception objects, rtti and memory allocation.
  • Extensive unit tests.
aggsol
  • 2,343
  • 1
  • 32
  • 49
6

Since today 16th September 2019 the Microsoft MSVC's STL is available on GitHub.

Luca Cappa
  • 1,925
  • 1
  • 13
  • 23
4

For Win10x64 with VS2017 default install paths,the source code are here:

part1:VCRuntime,which include code that will change for every version of Visual Studio,it contains function like the CRT entry point "mainCRTStartup",the code are here:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.16.27023\crt\src

part2:C standard library,which include code that is stable over generations of Visual Studio,like the function fopen,and it also contains stable CRT functions like _initterm,the code are here:

C:\Program Files (x86)\Windows Kits\10\Source\10.0.17763.0\ucrt

i.e. this part has been moved to Windows SDK,distributed with Windows instead of Visual Studio.

references:

https://devblogs.microsoft.com/cppblog/introducing-the-universal-crt/

jw_
  • 1,663
  • 18
  • 32
2

Apache has one available.

Max Lybbert
  • 19,717
  • 4
  • 46
  • 69
1

Don't forget STLPort & the SGI ones.

Eugen Constantin Dinca
  • 8,994
  • 2
  • 34
  • 51
1

In Visual Studio if you interesting in concrete(specific) STL-element implementation (for example, any function), right click on its mention in your code and chose "Go to Definition" in context menu. (Or place cursor on this mention and push "F12")

user1234567
  • 3,991
  • 3
  • 19
  • 25