tags:

views:

147

answers:

3

Hi all,

I'm developing a shared library, and since the code is big, I've decided to split it in many headers and source files, like any normal program :).

The problem is that most of these headers are for internal use, i.e. I don't want them to be accessible from outside of my library. So I'm thinking to move them all to a big source file and only provide headers for what is going to be visible.

It's a good idea do that? Should I worry on visibility?

Thanks

+11  A: 

Instead of merging the headers, just keep them alongside your source files and don't "publish" them as a part of your development package. As an example of this, the linux kernel has many headers in the source tree, but only certain headers are exposed to applications (in the include structure).

jheddings
I see. It's a good point and I should have figured it lol. TY
scooterman
You bet... It's not always an obvious approach to use headers internally only, but it is certainly a reasonable one. Of course, you cannot have your "public" headers rely on internal ones...
jheddings
A: 

Yes you should worry about symbol visibility. On Windows, set up to use DLLEXPORT. On Linux, define DLLEXPORT to set default symbol visibility, but compile everything with -fvisibility=hidden. There's an Ulrich Drepper article on it that is useful.

For the include files, you can separate them into directories and/or you can use your packaging system to just copy the public files.

Zan Lynx
+2  A: 

You should approach it from a "cleanliness" angle; don't ship headers which include functions you aren't intending people to call. Don't document functions which you aren't shipping headers for.

If someone really wants to call a function in your library, they can, but you should try to make it clear that that's an unsupported use case and it's their problem if it all goes wrong.

MarkR