[PATCH] algol68: Use correct library file extension on darwin and windows
Pietro Monteiro
pietro@sociotechnical.xyz
Mon Jun 8 14:46:41 GMT 2026
On Mon, Jun 8, 2026, at 9:44 AM, Iain Sandoe wrote:
>> On 8 Jun 2026, at 14:27, Andrew Pinski <pinskia@gmail.com> wrote:
>>
>>
>>
>> On Mon, Jun 8, 2026, 6:09 AM Pietro Monteiro <pietro@sociotechnical.xyz> wrote:
>> Darwin uses .dylib as extension for libraries. Windows uses .dll, and
>> sometimes doesn't prefix the library filename with "lib".
>>
>> Use those extensions when opening library files to search for imports
>> on thoses OSes. Search for file with both the lib prefix and withouti
>> on Windows.
>>
>> gcc/algol68/ChangeLog:
>>
>> * a68-imports.cc (a68_try_suffixes): Use .dylib suffix on Darwin.
>> Use .ddl suffix and optional lib prefix on Windows.
>>
>> Signed-off-by: Pietro Monteiro <pietro@sociotechnical.xyz>
>> ---
>> gcc/algol68/a68-imports.cc | 30 ++++++++++++++++++++++++++++++
>> 1 file changed, 30 insertions(+)
>>
>> diff --git a/gcc/algol68/a68-imports.cc b/gcc/algol68/a68-imports.cc
>> index 8b77bbf0b76..e0fe87368e5 100644
>> --- a/gcc/algol68/a68-imports.cc
>> +++ b/gcc/algol68/a68-imports.cc
>> @@ -365,6 +365,35 @@ a68_try_suffixes (std::string *pfilename)
>>
>> const char* basename = lbasename (pfilename->c_str());
>> size_t basename_pos = basename - pfilename->c_str ();
>> +
>> +#if defined (__APPLE__)
>> + /* Macos uses .dylib as extension for libraries. */
>> + 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;
>> + }
>> +#elif defined (_WIN32)
>> + /* Windows uses .dll. Maybe prefixed with lib. */
>> + filename = pfilename->substr (0, basename_pos) + "lib" + basename + ".dll";
>> + fd = open (filename.c_str (), O_RDONLY | O_BINARY);
>> + if (fd >= 0)
>> + {
>> + *pfilename = filename;
>> + return fd;
>> + }
>> + /* Maybe not prefixed with lib. */
>> + filename = pfilename->substr (0, basename_pos) + basename + ".dll";
>> + fd = open (filename.c_str (), O_RDONLY | O_BINARY);
>> + if (fd >= 0)
>> + {
>> + *pfilename = filename;
>> + return fd;
>> + }
>> +#else
>> + /* Other supported systems use .so. */
>> filename = pfilename->substr (0, basename_pos) + "lib" + basename + ".so";
>> fd = open (filename.c_str (), O_RDONLY | O_BINARY);
>> if (fd >= 0)
>> @@ -372,6 +401,7 @@ a68_try_suffixes (std::string *pfilename)
>> *pfilename = filename;
>> return fd;
>> }
>> +#endif
>>
>>
>> Hmm, i think this is wrong. I assume this for the target libraries that is being loaded up and not the host library.
>> The (__APPLE__)/_WIN32 defines here are for the host rather than the target.While that would work for a native compiler cross compilers from or to those targets would be wrong.
>
> I seems you have target.h included - so could use OBJECT_FORMAT_MACHO?
AFAIK only Darwin uses Mach-O so that would work.
Is the right way to identify windows as the target to use
TARGET_PECOFF?
There's a OBJECT_FORMAT_COFF, but the only mention of OBJECT_FORMAT_PE
is in a comment on gcc/varasm.cc.
I guess I could use TARGET_MACHO/TARGET_PECOFF to keep the symmetry.
> Iain
>
>>
>>
>> filename = pfilename->substr (0, basename_pos) + "lib" + basename + ".a";
>> fd = open (filename.c_str (), O_RDONLY | O_BINARY);
>> --
>> 2.43.0
More information about the Algol68
mailing list