Your question can be split in two:
1. "How can I hide global functions ?"
One simple way to do that, is NOT to put the header of the function into the header file:
//============================
// Filename: "mylibrary.hpp"
//============================
// Description:
// Utility functions.
//============================
#ifndef MYLIBRARY_H_INCLUDED
#define MYLIBRARY_H_INCLUDED
//============================
namespace MyLibrary
{
void DoSomething();
} // namespace MyLibrary
//============================
#endif // MYLIBRARY_H_INCLUDED
//============================
Full code file:
//============================
// Filename: "mylibrary.cpp"
//============================
// Description:
// Utility functions.
//============================
// self header include
#include "mylibrary.hpp"
//============================
namespace MyLibrary
{
void DoSomethingBefore()
{
// ...
}
void DoSomethingAfter()
{
// ...
}
void DoSomethingConfirmed()
{
// ...
}
void DoSomething()
{
DoSomethingBefore();
DoSomethingConfirmed();
DoSomethingAfter();
}
} // namespace MyLibrary
//============================
#endif // MYLIBRARY_H_INCLUDED
//============================
When this is compiled, you get a "mylibrary.o" or "mylibrary.obj" file. You may provide it, to other developers as: "mylibrary.hpp" plus "mylibrary.obj", but, without the "mylibrary.cpp" file. Most "plain c" / "c++" compilers can work this way.
There are other ways, read the next section.
2. "Are anonymous namespaces, a good technique to hide global functions ?"
The "Anonymous Namespaces" technique, is another way to hide global functions.
There is a similar question on:
Unnamed/anonymous namespaces vs. static functions
But, personally, I don't recommend this technique, as the "favorite" answer.
Namespaces are one of those things, that I wish existed since the start of "pure c" or "c++". But, "anonymous namespaces" or "unnamed namespaces", seems weird to use.
Its like trying to hide something, and, later, forget, where do you store it.
3 Additional suggestions
(a) I suggest to use a single main REQUIRED, not optional, non-anonymous namespace per file. It may have nested, additional inner namespaces. Each main namespace, should have the same id. as the filename, but, without the file extension or file suffix.
(b) Avoid anonymous namespaces. Its like storing things in a warehouse, without an index.
(c) Use a file extension, or file prefix, in your header files, maybe ".h", or ".hpp", even if if its a c++ file. The standard says c++ shouldn't use an file extension or file suffix on "c++" files, but are difficult to identify or find on the filesystem.
Good Luck.