public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Issue with dllexport/dllimport inline function
@ 2022-10-10 16:32 xclaesse
  0 siblings, 0 replies; 14+ messages in thread
From: xclaesse @ 2022-10-10 16:32 UTC (permalink / raw)
  To: gcc

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

^ permalink raw reply	[flat|nested] 14+ messages in thread
* Issue with dllexport/dllimport inline function
@ 2022-10-10 16:39 xclaesse
  2022-10-11  5:00 ` LIU Hao
  0 siblings, 1 reply; 14+ messages in thread
From: xclaesse @ 2022-10-10 16:39 UTC (permalink / raw)
  To: gcc

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


^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2022-11-02  4:44 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-10 16:32 Issue with dllexport/dllimport inline function xclaesse
2022-10-10 16:39 xclaesse
2022-10-11  5:00 ` LIU Hao
2022-10-11 13:10   ` xclaesse
2022-10-11 13:28     ` LIU Hao
2022-10-11 13:35       ` LIU Hao
2022-10-11 14:26         ` xclaesse
2022-10-11 17:42           ` LIU Hao
2022-10-11 18:37             ` xclaesse
2022-10-12  3:03               ` LIU Hao
2022-11-01 15:38                 ` xclaesse
2022-11-01 16:06                   ` LIU Hao
2022-11-01 18:11                     ` xclaesse
2022-11-02  4:44                       ` LIU Hao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).