[RFC] algol68: Use correct library file extension on macos and windows
Jose E. Marchesi
jemarch@gnu.org
Fri Jun 5 08:27:30 GMT 2026
Hi Pietro.
> Sending as RFC because I haven't been able to test on a mac yet.
> --8<--
>
> Macos uses .dylib as extension for libraries. And Windows uses .dll.
> Use those extensions when opening library files to search for imports.
>
> Signed-off-by: Pietro Monteiro <pietro@sociotechnical.xyz>
> ---
> gcc/algol68/a68-imports.cc | 25 +++++++++++++++++++++++++
> 1 file changed, 25 insertions(+)
>
> diff --git a/gcc/algol68/a68-imports.cc b/gcc/algol68/a68-imports.cc
> index 8b77bbf0b76..7c5ef826274 100644
> --- a/gcc/algol68/a68-imports.cc
> +++ b/gcc/algol68/a68-imports.cc
> @@ -363,6 +363,30 @@ a68_try_suffixes (std::string *pfilename)
> return fd;
> }
>
> +#if defined (__APPLE__)
> + /* Macos uses .dylib as extension for libraries. */
> + const char* basename = lbasename (pfilename->c_str());
> + size_t basename_pos = basename - pfilename->c_str ();
> + filename = pfilename->substr (0, basename_pos) + "lib" + basename + ".dylib";
> + fd = open (filename.c_str (), O_RDONLY | O_BINARY);
> + if (fd >= 0)
> + {
> + *pfilename = filename;
> + return fd;
> + }
> +#elsif defined (_WIN32)
> + /* Windows uses .dll. */
> + const char* basename = lbasename (pfilename->c_str());
> + size_t basename_pos = basename - pfilename->c_str ();
> + filename = pfilename->substr (0, basename_pos) + "lib" + basename + ".dll";
I think in Windows DLLs are usually called FOO.dll, not libFOO.dll.
That said, mingw32 uses libFOO.dll.
We probably want to try for both, first libFOO.dll then FOO.dll?
> + fd = open (filename.c_str (), O_RDONLY | O_BINARY);
> + if (fd >= 0)
> + {
> + *pfilename = filename;
> + return fd;
> + }
> +#else
> + /* Other supported systems use .so. */
> const char* basename = lbasename (pfilename->c_str());
> size_t basename_pos = basename - pfilename->c_str ();
> filename = pfilename->substr (0, basename_pos) + "lib" + basename + ".so";
> @@ -372,6 +396,7 @@ a68_try_suffixes (std::string *pfilename)
> *pfilename = filename;
> return fd;
> }
> +#endif
>
> filename = pfilename->substr (0, basename_pos) + "lib" + basename + ".a";
> fd = open (filename.c_str (), O_RDONLY | O_BINARY);
>
> base-commit: 5dc5dd6ed9b4759d278a07f95949c3f241626651
More information about the Algol68
mailing list