I’m trying to separate some of my code and put it in a shared library that I will be able to use from other places. In the documentation:
http://doc.qt.io/archives/qt-4.7/sharedlibrary.html
They say that you cannot link to other header files. How would I be able to include shared headers into my shared library?
Shared libraries in the context being discussed in the link you provided are .so (shared object) files (.dll, dynamic link library, on Windows), or static (.lib) libraries. Qt provides this kind of library; so do many other vendors/projects. To use them in another application (like yours, for example), you include the headers and link against the library.
What the article is warning about is
#includeing header files that a user may not have – i.e. ones that aren’t part of your project. Remember, for someone else to use your new “shared library”, they need to include the header file(s) that you provide. If that file includes other headers that they don’t have, they will get errors.To avoid this problem, do your
#includes in your implementation (.cpp) files; that way, they are hidden from future users. Qt recommends the “pointer-to-implementation” (pimpl) idiom – all the implementation details are hidden from the users of the class, including any and all header files that the implementation depends on.You can easily do the same thing, even if you don’t go all-out with pimpl. The goal is to
#includein your header only the absolutely required files, hopefully all of which you provide with your library.