Hi Bruno, I think this feature on MSVC tries to copy behavior of --export-all-symbols, which is default with mingw tools[1].
I believe this behavior, as well as --export-all-symbols are supposed to simplify porting existing project to Windows. With these features, you would not need to use __delcspec() to make library usable. This could help save a lot of time before project adopts to usage of __delcspec(). One issue with this feature on MSVC is that it may (and usually will) result in exporting undesired symbols. This particularly applies to projects which already use __declspec() to control which symbols to export from the DLL. Note that on mingw, unless explicitly used, --export-all-symbols will not be active if there are any symbols with __declspec(dllexport) in object files or a .def file is used. This prevents the issue with undesired symbols being exported on mingw. I think it would be useful if libtool allowed to explicitly disable this feature, while current behavior would remain default for backward compatibility. - Kirill Makurin [1] https://sourceware.org/binutils/docs/ld/WIN32.html ________________________________ From: Bruno Haible <br...@clisp.org> Sent: Thursday, June 5, 2025 1:45 AM To: libtool@gnu.org <libtool@gnu.org> Cc: Kirill Makurin <maiddais...@outlook.com> Subject: Re: exported symbols of shared libraries on MSVC Hi Kirill, > If you look at commands executed by libtool when it creates a DLL, > you may see that it runs $NM on all object files which go into DLL. > Then it uses some awk script to generate list of all `extern` symbols > defined in those object files. Libtool then appends each symbol with > `-link -export:` so link.exe will export all of them. > ... > I don't like how libtool handles this. This may result in unwanted > symbols to be exported. > > I wish we had some option to pass to LT_INIT() to disable this behavior, > but keep old behavior as default. I'm not the libtool maintainer, but I think the major reason for the behaviour of "libtool --mode=link" on MSVC is to be compatible with the behaviour on other platforms, in particular ELF-based ones. On these platforms, when you create a shared library ("gcc -shared ..."), it exports all global symbols. Which set of symbols would you want to be exported by default? Authors of shared libraries typically use one of various techniques [1] to decide which symbols to export. There is no single technique for all possible situations. Bruno [1] https://www.gnu.org/software/gnulib/manual/html_node/Exported-Symbols-of-Shared-Libraries.html