1

I learned recently that on Linux, all symbols of a library are exported by default, but on Windows, none are. It seems that for every symbol of a library you care about, you must do __declspec(dllexport) and pair it with a __declspec(dllimport) on the receiving end.

Doing this for every symbol sounds like a chore, and bloats the code, and hurts readability. Is it possible to just enable all symbols by default?

I have read Export all symbols when creating a DLL, but all of the answers there seem extremely laborious and hacky. I would like a linker flag or something of the sort, if it exists. The linked post was from over 10 years ago, so maybe things have improved since then?

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Makogan
  • 8,208
  • 7
  • 44
  • 112
  • Did you read this: [Export all symbols when creating a DLL](https://stackoverflow.com/questions/225432/export-all-symbols-when-creating-a-dll) ? – WhozCraig Jan 22 '22 at 09:44
  • Maybe edit your question to specify if you are using the Microsoft or GCC linker... – Anders Jan 22 '22 at 13:00
  • 1
    Why? Why on earth would you **ever** want that? *"maybe things ahve improved since then"* - having all symbols private by default is the correct solutions. There's no need to improve anything that's not broken. – IInspectable Jan 22 '22 at 16:41
  • Why would that be the correect solution? Neither clang nor gcc do this, Unix systems work just fine without this nonsense and it makes the programmer's life way more diffucult. – Makogan Jan 22 '22 at 19:51
  • Exported symbols are the **public** interface. It would seem somewhat random to just have **everything** be part of the public interface. Why would that be desirable? Why would it be a good idea to inconvenience developers that cautiously design their interfaces? – IInspectable Jan 23 '22 at 09:33
  • Why would it incoinvenience the ones that want to put in the effort to select public and private symbols? If anything it inconveniences those that don;t care. For those that do care it's basically the same amount of work, make a macro at the start that is by default not exporting a symbol and is swithc to enable a symbol for the few desired public ones. This works on Unix systems so tyhere is no argument to say it cannot be done that way. – Makogan Jan 23 '22 at 09:45
  • *"This works on Unix systems so tyhere is no argument to say it cannot be done that way."* - Of course it **can** be done. Then again, Linux doesn't even have an API, so controlling a public API surface is not something that Linux developers are generally exposed to. You'll also observe that LTO makes a significant difference on Linux. On Windows, it usually doesn't. A corollary of the correct decision to have symbols private by default. *"it's basically the same amount of work"* - So then, why do you even care? – IInspectable Jan 23 '22 at 15:23

0 Answers0