Issue with dllexport/dllimport inline function

LIU Hao lh_mouse@126.com
Wed Nov 2 04:44:49 GMT 2022


在 2022/11/2 02:11, xclaesse@gmail.com 写道:
> Oh, that seems to be working now.
> 
> Still got a small issue, glib compiles with -Werror=missing-
> prototypes:
> 
> ../foo.h:7:5: error: no previous prototype for ‘g_strcmp0’ [-
> Werror=missing-prototypes]
> 
> I'm a bit lost with what the prototype would look like in this case.
> 
> I think `__attribute__((__dllexport__))` will be needed when building
> with MSVC at least. Seems gcc, clang and msvc each wants a different
> trick :/
> 
> 

GCC accepts a plain declaration (no `extern`, no `__attribute` whatsoever), but Clang usually warns 
about the inconsistency, and sometimes rejects it, so my suggestion is to copy the declaration from 
its definition verbatim.

It might look unnecessarily verbose, however, should be safe in practice. I don't know much about 
how MSVC handles such inconsistency, though.

    ```
    #ifndef INSIDE_FOO_C
    __attribute__((__gnu_inline__)) __inline__
    #endif
    extern
    int g_strcmp0(const char*str1, const char*str2);

    #ifndef INSIDE_FOO_C
    __attribute__((__gnu_inline__)) __inline__
    #endif
    extern
    int g_strcmp0(const char*str1, const char*str2) {
      ...
    ```



-- 
Best regards,
LIU Hao

-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature
Type: application/pgp-signature
Size: 840 bytes
Desc: OpenPGP digital signature
URL: <https://gcc.gnu.org/pipermail/gcc/attachments/20221102/a84a709e/attachment.sig>


More information about the Gcc mailing list