public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: xclaesse@gmail.com
To: LIU Hao <lh_mouse@126.com>, gcc@gcc.gnu.org
Subject: Re: Issue with dllexport/dllimport inline function
Date: Tue, 11 Oct 2022 14:37:53 -0400	[thread overview]
Message-ID: <6c5778d2edfaa8b5196ef142ad0339ac6233b641.camel@gmail.com> (raw)
In-Reply-To: <13cbf2ec-4027-3df7-aa76-3d680afc075b@126.com>

Le mercredi 12 octobre 2022 à 01:42 +0800, LIU Hao a écrit :
> 在 2022-10-11 22:26, xclaesse@gmail.com 写道:
> > #ifdef GLIB_COMPILATION
> > #  define _GLIB_API _GLIB_EXPORT
> > #  define GLIB_INLINE __attribute__((__dllexport__))
> > __attribute__((__gnu_inline__)) extern inline
> 
> This is not correct. Typically, `dllexport` indicates that 'I want an
> external definition' but 
> `gnu_inline` indicates that 'I do not want an external definition',
> so it's a contradiction: you get 
> either multiple definitions, or none (which causes undefined
> references).

Sorry, that was a wrong copy/paste when writing the email (leftover of
things I tried previously). I can confirm the multiple definition error
I have is when that line is `#  define GLIB_INLINE _GLIB_EXPORT extern
inline`, which expands to `__declspec(dllexport) extern inline`.

> To user code which imports such a function, it should be seen as
> 
>     ```
>     __attribute__((__gnu_inline__))
>     extern inline
>     int g_strcmp0(const char*, const char*)
>     ```
> 
> This has the desired effect: The function can be inlined where
> appropriate. And if not, a call to 
> the external thunk is emitted; no weak definition is emitted in
> either case.
> 
> 
> To the library itself which exports it, it should be seen as
> 
>     ```
>     __attribute__((__dllexport__))
>     extern inline
>     int g_strcmp0(const char*, const char*)
>     ```
> 
> There is no `gnu_inline` in this case. GCC always generates a
> COMDAT/weak/linkonce definition, which 
> will not cause multiple definition errors.

Right, that's what I do and it fails. I made a simplified example:
https://gitlab.gnome.org/xclaesse/inline-example

Build it with:
  meson setup builddir --cross-file cross_file_mingw64.txt
  ninja -C builddir/

And it fails with:
```
x86_64-w64-mingw32-gcc  -o libfoo.dll libfoo.dll.p/foo.c.obj
libfoo.dll.p/bar.c.obj -Wl,--allow-shlib-undefined -shared -Wl,--start-
group -Wl,--out-implib=libfoo.dll.a -fstack-protector -lkernel32 -
luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -
lcomdlg32 -ladvapi32 -Wl,--end-group
/usr/bin/x86_64-w64-mingw32-ld: libfoo.dll.p/bar.c.obj: in function
`g_strcmp0':
/home/xclaesse/programmation/inline-example/builddir/../foo.h:5:
multiple definition of `g_strcmp0';
libfoo.dll.p/foo.c.obj:/home/xclaesse/programmation/inline-
example/builddir/../foo.h:5: first defined here
```

Thanks for your help!

  reply	other threads:[~2022-10-11 18:37 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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
  -- strict thread matches above, loose matches on Subject: below --
2022-10-10 16:32 xclaesse

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6c5778d2edfaa8b5196ef142ad0339ac6233b641.camel@gmail.com \
    --to=xclaesse@gmail.com \
    --cc=gcc@gcc.gnu.org \
    --cc=lh_mouse@126.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).