2

I am going to detail out a common hypothetical problem.

Problem:

I am provided with a static library say libX.a and the header files a.h and b.h. The header files a.h and b.h contain the APIs exported by the library. a.h includes a1.h and b.h includes b1.h. But a1.h and b1.h are not shipped by the owner of the library because a1.h and b1.h contain the data structures which are used privately by the library and the owner does not want to expose these data structures.

I have to write an application invoking the APIs exported by the library. So I have to include a.h and b.h which contains the declaration for the APIs.

Ok, fine. I write my application and include the header files a.h and b.h and invoke the APIs. But I will get a compiler error, because the compiler cannot find a1.h and b1.h which are internally included by a.h and b.h.

Questions:

  1. Is there a solution to this problem? If yes, seeking earnestly to know the solution :)

  2. Is it necessary that the library owner expose all the private header files he internally uses in his library?

Marc Mutz - mmutz
  • 24,485
  • 12
  • 80
  • 90
nitin_cherian
  • 6,405
  • 21
  • 76
  • 127

2 Answers2

2

I'll start with the last one. The owner of the library can conceal the headers containing private information, but he has to make sure the public headers do not depend on those private ones, i.e. they must not include them!

As for the first question, you can try to remove those include lines. It should compile, but if it doesn't, the creator has probably hid something important in the private headers, something that is vital to using his library by someone besides himself.

Marc Mutz - mmutz
  • 24,485
  • 12
  • 80
  • 90
unkulunkulu
  • 11,576
  • 2
  • 31
  • 49
0

1) You could look at the nm tool, see SO: how to list symbols in a so-file. Perhaps it works for static-libraries as well, i'm not sure.

2) The library owner could have used the techniques in Large scale C++ software design by John Lakos to prevent exposing the internal structure. Perhaps you can use the techniques in there to create the required parts of a1.h and b1.h without relying on information you don't have. Especially declaring structures/classes without defining their contents.

Community
  • 1
  • 1
Kasper van den Berg
  • 8,951
  • 4
  • 48
  • 70