I am writing a cross platform shared library (.so
in linux and .dll
in windows) using C. Currently when there is a error, library functions returns the
In general, you shouldn't be writing to stdout
at all from your library - even in a console application that could corrupt the output that the application is producing. stderr
is a little more forgivable, but you still shouldn't really use that unless the application requests it.
The OpenSSL is a cross-platform shared library that had much the same problem to solve. Their method has the library record detailed error information in an internal error queue, which the application can request when an error return value is seen and then present to the user in whichever way is appropriate. (It also provides a convenience function that dumps the entire error queue to a FILE *
).