Suppose I have a dynamic library that exports three functions:
void lib_function(void);
void lib_extra_function(void);
int lib_runtime_version(int v);
And lib_extra_function
was added in version 2 of the library.
If an application that uses lib_extra_function
is built on a system with library version 2 installed, and then run on a system that provides only version 1, "symbol lookup error: ./main: undefined symbol: lib_extra_function
" dynamic linker error is raised once lib_extra_function
is called.
However, if application tries to use version information provided by library and call lib_extra_function
conditionally, no error is raised, even though lib_extra_function
is still undefined.
voif f()
{
if(lib_runtime_version() >= 2) {
lib_extra_function();
} else {
// try some workaround
}
}
Now, is this behavior mandated by any standard? If not, is it specific to Linux? How do linkers in other systems (OSX, BSD) behave?