I intend to provide simple wrappers to the operating system API, which throw exceptions when errors happen. These wrappers are simple, and are all defined as inline functions in a header file. Since system API is supposed to be large, the header file is supposed to be huge as well, containing a large number of tiny inline functions. The problem is, if a shared library (.so) is compiled with the header file included, will all these tiny wrappers be compiled into the resulting binary, resulting in a large binary file, even when only a small part of the wrappers are actually used? What about the case with executables, will it be different? If it is the case, will splitting the wrappers into multiple header files be the only solution? Or should I make the wrappers internal linkage by specifying static
?
Here is what I think. The wrappers may be ODR-used (e.g., taking its address). And on Linux platforms, functions with external linkage are exported by default (i.e., linkable by other binary modules). So I guess it may be necessary for the linker to actually generate outline definitions for them. Please refer to bullet point 3) in the Description section here.
A simple example wrapping CloseHandle()
in Windows API:
inline void close_handle(HANDLE handle) {
if (!CloseHandle(handle)) {
throw std::system_error(GetLastError(), std::system_category(), "CloseHandle");
}
}