Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does the C++ boost package only contain .hpp files?

Tags:

c++

boost

I'm new to C++. I just downloaded the Boost libraries to study. I wanted to look into some implementation details, so I looked for .cpp files. To my surprise, I haven't found any so far.

There seem only .hpp files out there. Where are the .cpp files?

like image 896
Terry Li Avatar asked Nov 22 '11 15:11

Terry Li


2 Answers

A lot of the Boost library are purely template. In the previous standard of C++ there was already the keyword export to allow the developer to separate the implementation from the interface.

The sad truth was that the keyword never worked completely (difficult to implement from the compiler vendor point of view and difficult to use it right for the developer). One way to fix the problem was provide interface and implementation in a header file and avoid the implementation file. By the way, there are several Boost libraries that you need to compile and link in order to use it, and I bet you will find implementation files in those libraries.

like image 114
Alessandro Teruzzi Avatar answered Oct 11 '22 05:10

Alessandro Teruzzi


From the Boost documentation:

Most Boost libraries are header-only: they consist entirely of header files containing templates and inline functions, and require no separately-compiled library binaries or special treatment when linking.

See that link for the list of libraries that are not header-only and must be built separately. For those libraries, the .cpp files are in the /libs directory of the Boost distribution. If you got the precompiled package, you'll instead find the already-compiled .lib files in the /lib directory.

like image 45
razlebe Avatar answered Oct 11 '22 07:10

razlebe