Hi,

I'm trying to dllexport/dllimport an inline function, but I get this
warning:

```
inline function ‘g_strcmp0’ declared as dllimport: attribute ignored [-
Wattributes]
```

This is when cross compiling my code on Linux for Windows using mingw.
The relevant code is

```
GLIB_API inline
int     g_strcmp0                       (const char     *str1,
                                         const char     *str2)
{
  if (!str1)
    return -(str1 != str2);
  if (!str2)
    return str1 != str2;
  return strcmp (str1, str2);
}

```

Where GLIB_API is defined to `__declspec(dllexport)` when compiling the
DLL and `__declspec(dllimport)` when including the header from
application.

The goal is to get that function inlined when doing `if (g_strcmp0(a,
b))`, but get address from instance in the DLL when doing
`do_sort(array, g_strcmp0)`.

I believe dllimport of inline function should be supported, it compiles
fine with MSVC. It is even documented there:
https://learn.microsoft.com/en-us/cpp/cpp/defining-inline-cpp-functions-with-dllexport-and-dllimport?view=msvc-170

I believe (but not tested myself) that clang had the same issue but got
fixed years ago: https://reviews.llvm.org/D3772

For context, I'm hitting this issue when working on that GLib patch:
https://gitlab.gnome.org/GNOME/glib/-/merge_requests/2926

Is there a trick to get that working with GCC? Or should that issue be
reported somewhere?

Regards,
Xavier Claessens

Reply via email to