Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best practice for a shared library primary header file in C++?

When I create shared libraries, I have a header file (but with no file name extension) in the root of the library source named the same as the library.

So for example, if my library was called libirock.so, then I'd have a file called irock in the project root. This file will include all of the most important headers in the library, so that when the library is to be implemented, all you need to do is use this include line:

#include <irock> // Instead of <irock.h>

I got the idea from when I saw a compiler warning similar to:

#include <string.h> is obsolete, use #include <string> instead

Two questions:

  1. Is using irock instead of irock.h best practice?
  2. Is is correct to use a single header file instead of many headers?

Course of action

Thanks for your answers! From the answers, I've decided:

  1. Will use <irock.h> instead of <irock>.
  2. I will continue to use a 'primary' header file.
like image 790
Nick Bolton Avatar asked Sep 03 '25 03:09

Nick Bolton


1 Answers

In a single word, no. You'll want to explicitly use irock.h

With the extension in place, it's clear that this is a header file, and any application that uses files based on file extension will correctly know how to interpret your header file.

like image 117
Alan Avatar answered Sep 04 '25 17:09

Alan