1

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.

Community
  • 1
  • 1
Silversonic
  • 1,131
  • 1
  • 9
  • 20
  • 2
    If “hello, world” compiles and runs, you probably have the standard library. Where the header files are saved on disk is operating system and compiler specific. But you usually don't need to know that. Of course, you can try searching your file system for files named `iostream` or the like if you are interested. You can check [here](http://en.cppreference.com/w/) what the standard library includes. – 5gon12eder Mar 01 '15 at 18:26
  • The problem isn't that this question is "basic"; it's that it is "unfocused" and you do not appear to have done much prior research. – Lightness Races in Orbit Mar 01 '15 at 18:54
  • @Lightness Races in Orbit Not fair to assume I've not done the research. I know what I've researched and I wasn't getting the right pieces of information. Countless searches of "where is the standard library" don't produce exact answers, and when you're 30 minutes in to googling your problem you just think to yourself "You know what, I could spend 5 minutes asking my question, and someone could spend 5 minutes answering my exact question and I'd be done". – Silversonic Mar 01 '15 at 19:14
  • 1
    @Silversonic: It's not an assumption. It's an observation. You haven't read your C++ book yet and gathered knowledge about the subject. Just taking random potshots at Google is not "research"! We are not here to mop up constant no-research attempts to save _other_ people time, no matter whether it takes 5 minutes to answer or 30. It doesn't scale. Anyway, again, the bigger problem is the lack of focus - it's very chatty and I can't see it specifically helping anyone else in the future. – Lightness Races in Orbit Mar 01 '15 at 19:15
  • 1
    "We are not here to mop up constant no-research attempts to save other people time, " If it's really such a problem then the mods can feel free to delete my topic. I know the time I put in to my research, I can show pictures of my history. I gave up, I asked a direct question to save time. Is that such a horrible thing to do? – Silversonic Mar 01 '15 at 19:33

3 Answers3

5

"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.).

πάντα ῥεῖ
  • 83,259
  • 13
  • 96
  • 175
3

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.

Dietmar Kühl
  • 141,209
  • 12
  • 196
  • 356
-1

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