在 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). 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. -- Best regards, LIU Hao