Silversonic
Silversonic

Reputation: 1329

Where is the standard library?

I have searched Google but haven't found quite a direct answer to my queries.

I have been reading C++ Primer and I'm still quite new to the language, but despite how good the book is it discusses the use of the standard library but doesn't really describe where it is or where it comes from (it hasn't yet anyway). So, where is the standard library? Where are the header files that let me access it? When I downloaded CodeBlocks, did the STL come with it? Or does it automatically come with my OS?

Somewhat related, but what exactly is MinGW that came with Cobeblocks? Here it says

MinGW is a C/C++ compiler suite which allows you to create Windows executables without dependency on such DLLs

So at the most basic level is it just a collection of "things" needed to let me make C++ programs?

Apologies for the quite basic question.

Upvotes: 4

Views: 24813

Answers (3)

Dietmar Kühl
Dietmar Kühl

Reputation: 153820

When you have installed a C++ implementation you'll have something which implements everything necessary to use C++ source files and turn them into something running. How that is done exactly depends on the specific C++ implementation. Most often, there is a compiler which processes individual source file and translates them into object files which are then combined by a linker to produce an actual running program. That is by no means required and, e.g., cling directly interprets C++ code without compiling.

All this is just to clarify that there is no one way how C++ is implemented although the majority of contemporary C++ implementations follow the approach of compiler/linker and provide libraries as a collection of files with declarations and library files providing implementations of these declarations.

Where the C++ standard library is located and where its declarations are to be found entirely depends on the C++ implementations. Oddly, all C++ implementations I have encountered so far except cling do use a compiler and all these compilers support a -E option (although it is spelled /E for MSVC++) which preprocesses a C++ file. The typically quite large output shows locations of included files pointing at the location of the declarations. That is, something like this executed on a command line yields a file with the information about the locations:

compiler -E input.cpp > input.ii

How the compiler compiler is actually named entirely depends on the C++ implementation and is something like g++, clang++, etc. The file input.cpp is supposed to contain a suitable include directive for one of the standard C++ library headers, e.g.

#include <iostream>

Searching in the output input.ii should reveal the location of this header. Of course, it is possible that the declarations are made available by the compiler without actually including a file but just making declarations visible. There used to be a compiler like this (TenDRA) but I'm not aware of any contemporary compiler doing this (with modules being considered for standardization these may come back in the future, though).

Where the actual library file with the objects implementing the various declarations is located is an entirely different question and locating these tends to be a bit more involved.

The C++ implementation is probably installed somehow when installing CodeBlocks. I think it is just one package. On systems with a package management system like dpkg on some Linuxes it would be quite reasonable to just have the IDE have a dependency on the compiler (e.g., gcc for CodeBlocks) and have the compiler have a dependency on the standard C++ library (libstdc++ for gcc) and have the package management system sort out how things are installed.

Upvotes: 7

πάντα ῥεῖ
πάντα ῥεῖ

Reputation: 1

"When I downloaded CodeBlocks, did the STL come with it?"

Despite it's not called the STL, but the C++ standard library, it comes with your c++ compiler implementation (and optionally packaged with the CodeBlocks IDE).

You have to differentiate IDE and compiler toolchain. CodeBlocks (the Integrated Development Environment) can be configured to use a number of different compiler toolchains (e.g. Clang or MSVC).

"Or does it automatically come with my OS?"

No, usually not. Especially not for Windows OS

"So, where is the standard library? Where are the header files that let me access it?"

They come with the compiler toolchain you're currently using for your CodeBlocks project.
Supposed this is the MinGW GCC toolchain and it's installed in the default directory, you'll find the libraries under a directory like (that's what I have)

C:\MinGW\lib\gcc\mingw32\4.8.1

and the header files at

C:\MinGW\lib\gcc\mingw32\4.8.1\include\c++

"So at the most basic level is it just a collection of "things" needed to let me make C++ programs?"

It's the Minimalist GNU toolchain for Windows. It usually comes along with the GCC (GNU C/C++ compiler toolchain), plus the MSYS minimalist GNU tools environment (including GNU make, shell, etc.).

Upvotes: 8

user3920237
user3920237

Reputation:

There are several implementations of the C++ standard library. Some of the more popular ones are libstdc++, which comes packaged with GCC, libc++, which can be used with Clang, or Visual Studio's implementation by Microsoft. They use a licensed version of Dinkumware's implementation. MinGW contains a port of GCC. CodeBlocks, an IDE, allows you to choose a setup which comes packaged with a version of MinGW, or one without. Either way, you can still set up the IDE to use a different compiler if you choose. Part of the standard library implementation will also be header files, not just binaries, because a lot of it is template code (which can only be implemented in header files.)

I recommend you read the documentation for the respective technologies because they contain a lot of information, more than a tutorial or book would:

libstdc++ faq

MinGW faq

MSDN

Upvotes: 0

Related Questions