AFAIK, neither C99 nor C++ standards are aware of shared libraries. Why is that?
EDIT: What is a good practice of writing shared libs without duplicating Linux/Windows versions?
Thanks.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I can think of a few reasons why this makes sense in 1999 (as in the case of C99) or even 2011:
There are still systems where C and C++ are used that don’t have shared libraries. (Think embedded.) If the standard mandated something, life is needlessly difficult for compiler/library implementers who are targetting platforms where the question of shared libraries is irrelevant.
Different operating systems make different design choices with regard to shared libraries. If the standard mandated something, it would limit those choices. There is also a lot of icky legacy here to consider as shared library implementations have evolved over time.
As is the case with many things in C and C++, other, more platform-specific standards do a fine enough job here where the language itself has left things unspecified. According to manpages I just looked up, POSIX.1-2001 specifies
dlopenet al. If you are targetting Windows you know where to findLoadLibrary/GetProcAddress.__declspecrequirements for Windows can also be wrapped in a macro. If you care about both Windows and POSIXy systems it’s not too hard to write a layer that does the appropriate thing. I’m sure there are lots already written and available.