lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 01.07.22 14:42, tehtmi wrote:
> By default, Windows will not export/share
> global variables between modules, but Linux will. Windows has separate notions
> for symbols that are shared between modules (ie dllimport/dllexport) versus
> variables that are just global (external linkage) within a module; but I guess
> Linux doesn't distinguish these, so everything with external linkage is subject
> to dynamic linking.

there are similar features in Linux for gcc >= 4, but as you wrote: the default
in Linux is to make non static symbols of shared module externally visible.

To have the same behaviour for Linux/Mac as under Windows you can put something
like the following before you are declaring your own functions but after
including system headers:

#if defined _WIN32 || defined __CYGWIN__
  #define DLL_PUBLIC __declspec(dllexport)
#else
  #if __GNUC__ >= 4
    #pragma GCC visibility push (hidden)
    #define DLL_PUBLIC __attribute__ ((visibility ("default")))
  #else
    #define DLL_PUBLIC
  #endif
#endif

(this also works with clang)

This makes any function declaration after "visibility push (hidden)" only
visible to the shared module, except DLL_PUBLIC is put before the function
declaration for making the function externally visible outside the module:

LUALIB_API int luaopen_reader (lua_State *L) {...}

Under Linux you can check the the externally visible symbols that are defined in
your_module.so by:

$ nm -gD --defined-only your_module.so

Best regards,
Oliver