Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Whats the design rationale between GCC exporting all symbols by default vs MSVC not exporting anything by default?

One of the many key differences between C++ Compilers GCC & MSVC is that in the first all symbols from a shared library are exported by default, while MSVC exports nothing.

Some implications are that in, In MSVC, you have to export explict instantiated template classes.

While I have accepted this as a fact of life, I was wondering what are the design implications, trade offs, from a compiler designer perspective, etc. of each approach?

like image 575
Fernando Gonzalez Sanchez Avatar asked Mar 13 '15 17:03

Fernando Gonzalez Sanchez


1 Answers

It probably has something to do with what executables and libraries are in their respective OS's.

On Windows, both libraries (DLL) and executables are the same thing. Literally, you can rename a .dll to .exe and it will run the protected mode stub and output some error (again, protected mode, so it will only work on a 16-bit system). Given that they're the same, and you can (and do!) export symbols from actual executables, you'd expect the default to be to export nothing right?

On Linux however, executables are their own thing, and code libraries (shared objects, .so) are something else. In fact .so files are closer to archives (.a, sort of gcc libraries -- but are not actually archives) if I recall correctly. There's no need for a .lib to be included to use the shared library like in Windows because it is a library file of sorts. Given that you're explicitly compiling your output as this shared library, I don't really see anything weird with it just exporting everything by default.

like image 161
Blindy Avatar answered Nov 03 '22 23:11

Blindy