dmuensterer
dmuensterer

Reputation: 1885

Is there common practice to find required header files of libraries in C++?

I am fairly new to C++ and this might sound like a very dumb question, but is there any resource or common practice to find the headers that need to be included when using C/C++ libraries?

For example: I am currently doing a project using the OpenSSL library. How do I find out which headers I need to include for the sample codes on this page:

I had this issue many times and I am almost always struggling to find the right header files to include if the documentation doesn't provide a full working example.

Am I missing smoething when it comes to finding the required header files or is this lack of documentation the norm for examples?

Upvotes: 3

Views: 661

Answers (1)

Ingo Mi
Ingo Mi

Reputation: 1079

I am aware that you were hoping to find something like a fancy database or any secret documentation to get the header.

Like for the Qt framework in the Qt Creator would be positioning the cursor on a written class in the code and just pressing alt + enter is adding the necessary header on top of the code.

Sadly that functionality is just for Qt not for c/c++ implemented.

The correct answer to your question might be as simple and maybe basic as so and it is also the fastest way I found and probably most people use:

  • A search engine of your choice(Google, DuckDuckgo, Startpage.com ...)
  • library command (f.e. EVP_PKEY)
  • Programming language name (f.e. c++, Qt, ...)

Proof of concept f.e. for startpage.com: Search engine result

Maybe https://en.cppreference.com/w/cpp/header is an alternative - I just never found stuff real quick there.


The second best option I found and use regularly to find in addition to the header even good sample codes/examples is a program called Recoll (For Linux, Mac and Windows - or a similar desktop search engine)

Recoll is based on the very capable Xapian search engine library, for which it provides a powerful text extraction layer and a complete, yet easy to use, Qt graphical interface. (https://www.lesbonscomptes.com/recoll/)

It works like that:

  • I put a selection of the best 50 books to a special topic in a folder (f.e. c++, c, qt - just stay really specific) and let recoll crawl the folder.
  • Now use keywords like EVP_PKEY to find every topic in all of your most loved and respected pdf c++ books in nano- to milliseconds - depending on how much money you spend on your pdf library. (Sure, you have to get/buy them first)

(But its a freaking fast tool and even prioritized due to the Xapian search engine library)

Upvotes: 1

Related Questions