GenerateExportHeader: how to use with inline functions on windows?
Hello, I am trying to work with A_EXPORT*
macroses provided by GenerateExportHeader
with inline
functions. Please review the following example (on windows only + -std=gnu18
):
export.h (created by cmake)
#ifndef A_EXPORT
# ifdef A_EXPORTS
# define A_EXPORT __declspec(dllexport)
# else
# define A_EXPORT __declspec(dllimport)
# endif
#endif
a.h
#include "export.h"
A_EXPORT inline void a () {};
a.c
#include "a.h"
A_EXPORT extern inline void a ();
b.c
#include "a.h"
Please try to create shared library from a.c
and b.c
: you will received multiple definition of a
, so we can see that A_EXPORT
macro is not user friendly for inline
functions and it breaks valid code. I think that dllexport
somehow implies extern
and breaks inline
declaration, not sure, but there is definitely some dark magic behind the scene.
Than please try to removed A_EXPORT
from a.h
, but keep A_EXPORT extern inline
as is. This manipulation fixes gcc
only, clang
linker don't like different attributes (attribute declaration must precede definition
) and finally fails with amazing error: undefined reference to __impl_a
.
I see no way to use A_EXPORT
macro with inline
functions. But there is a chance that function wont't be inlined and should be properly exported from shared library.
Do you know a way how to export inline functions (without dropping windows)? Thank you.