rrthomas / lrexlib

A Lua (5.1 and later) binding of various regex library APIs (POSIX, PCRE, PCRE2, GNU, Oniguruma and TRE)
Other
161 stars 29 forks source link

Cannot compile with luarocks under Windows #44

Open oktoberfest6 opened 2 years ago

oktoberfest6 commented 2 years ago

Hi,

I'm trying to install Lrexlib-PCRE with luarocks under Windows (with the help of vcpkg).

When running 'luarocks install Lrexlib-PCRE' I get the following message:

src/pcre/lpcre.c(451): error C2491: 'luaopen_rex_pcre': definition of dllimport function not allowed

The line 451 is:

REX_API int REX_OPENLIB (lua_State *L) {

REX_API is defined as a synonym for LUALIB_API (common.h)

#ifndef REX_API
#  define REX_API LUALIB_API
#endif

LUALIB_API is a synonym for LUA_API (luaconf.h):

#define LUALIB_API  LUA_API

The problem is that (under Windows) LUA_API is a conditional define (luaconf.h):

#if defined(LUA_CORE) || defined(LUA_LIB)       /* { */
#define LUA_API __declspec(dllexport)
#else                                           /* }{ */
#define LUA_API __declspec(dllimport)
#endif                                          /* } */

Lua compiled modules should define LUA_LIB before including any lua header file so that LUA_API is correctly defined (__declspec(dllexport) will export the entry point)

With a very small change in the rockspec I managed to compile before:

      defines = {
        "VERSION=\"2.9.1\"",
        "PCRE2_CODE_UNIT_WIDTH=8",
      },

after:

      defines = {
    "LUA_LIB=",
        "VERSION=\"2.9.1\"",
        "PCRE2_CODE_UNIT_WIDTH=8",
      },

Can you update the rockspec ?