pic11
pic11

Reputation: 14993

Shared libraries and language standards

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.

Upvotes: 2

Views: 195

Answers (3)

asveikau
asveikau

Reputation: 40264

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 dlopen et al. If you are targetting Windows you know where to find LoadLibrary/GetProcAddress. __declspec requirements 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.

Upvotes: 4

user184968
user184968

Reputation:

"How to write shared libraries" by Ulrich Drepper,
read the first page about them and their history.

Upvotes: 4

S.Lott
S.Lott

Reputation: 391992

Because a shared library is a feature of the OS.

Nothing to do with any particular language.

Upvotes: 6

Related Questions