actboy168 / lua-debug

Lua Debug Adapter for Visual Studio Code
MIT License
429 stars 92 forks source link

Cannot compile luajit due to `-std=c11` #294

Closed SlawekNowy closed 1 month ago

SlawekNowy commented 1 month ago

gcc -MMD -MT build/linux-x64/release/obj/lj_str_hash.c/lj_str_hash.obj -MF build/linux-x64/release/obj/lj_str_hash.c/lj_str_hash.obj.d -std=c11 -O2 -Wall -fvisibility=hidden -I3rd/lua/luajit/src -DLUAJIT_UNWIND_EXTERNAL -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -DLUA_MULTILIB="lib" -DLUAJIT_ENABLE_LUA52COMPAT -DLUAJIT_NUMMODE=2 -DNDEBUG -fno-stack-protector -U_FORTIFY_SOURCE -fPIC -msse4.2 -o build/linux-x64/release/obj/lj_str_hash.c/lj_str_hash.obj -c 3rd/lua/luajit/src/lj_str_hash.c
3rd/lua/luajit/src/lj_str_hash.c: In function ‘str_hash_init_random’:
3rd/lua/luajit/src/lj_str_hash.c:188:3: error: implicit declaration of function ‘srandom’; did you mean ‘srand’? [-Wimplicit-function-declaration]
  188 |   srandom(seed);
      |   ^~~~~~~
      |   srand
3rd/lua/luajit/src/lj_str_hash.c:197:24: error: implicit declaration of function ‘random’; did you mean ‘rand’? [-Wimplicit-function-declaration]
  197 |     random_pos[i][0] = random() & POW2_MASK(i+1);
      |                        ^~~~~~
      |                        rand
SlawekNowy commented 1 month ago

Both random and srandom are POSIX functions, which is not in C standard.

actboy168 commented 1 month ago

I don't have a test environment. Maybe need to define the _XOPEN_SOURCE macro.

SlawekNowy commented 1 month ago

Submitted the issue to submodule with the fix: https://github.com/openresty/luajit2/issues/232. The fix is in C file due to luamake not accepting gnu89 as valid value for luamake::c prop.

actboy168 commented 1 month ago

I've added gnu support to luamake, but I think just define _XOPEN_SOURCE, like lua51/lua52 does.

https://github.com/actboy168/lua-debug/blob/9e1f46502571c4f25eebfad681312d75399e4cda/compile/common/runtime.lua#L159-L163

SlawekNowy commented 1 month ago

I would add this to lj_str_hash target which was convienently sepatared from the rest.

SlawekNowy commented 1 month ago

Confirmed that adding _XOPEN_SOURCE=600 for defines is sufficient.