LuaSnip icon indicating copy to clipboard operation
LuaSnip copied to clipboard

jsregexp failed build on windows

Open gmr458 opened this issue 2 years ago • 17 comments

error

gmr458 avatar Aug 24 '23 16:08 gmr458

Ouh, I have not seen that one before... Could you try running make manually, and check if passing the full path to deps in -I works?

L3MON4D3 avatar Aug 25 '23 09:08 L3MON4D3

I think this worked:

gcc -IC:\Users\gdmr\AppData\Local\nvim-data\lazy\LuaSnip\deps\lua51_include\ -O2 -fPIC -c .\deps\jsr
egexp\jsregexp.c -o jsregexp.o

compiled without errors.

gmr458 avatar Aug 27 '23 01:08 gmr458

Oooh, okay took a look at the makefile, we do try to build the full path, but $(shell pwd) returned an empty path in your case. IIRC, there have been windows-users without this issue in the past, could you try to figure out what is missing on your system?

L3MON4D3 avatar Aug 27 '23 06:08 L3MON4D3

I stumbled upon this as well.

In my case it seems that Make runs with CMD as shell, which doesn't have the pwd executable. I installed make from scoop instead of through something like mingw, cygwin or git bash, all of which runs in something closer to a POSIX shell.

I added this to the Makefile:

ifeq ($(OS),Windows_NT)
	PWD := $(shell cd)
else
	PWD := $(shell pwd)
endif

and then substituted $(shell pwd) with ${PWD} in the rest of the Makefile.

I then ran into some other errors (gcc is also from scoop but it seems to package mingw):

process_begin: CreateProcess(NULL, uname, ...) failed.
Makefile:37: pipe: Bad file descriptor
git submodule init
git submodule update
make "INCLUDE_DIR=-IC:\Users\oscar\AppData\Local\nvim-data\lazy\LuaSnip/deps/lua51_include/" LDLIBS="" -C deps/jsregexp
make[1]: Entering directory 'C:/Users/oscar/AppData/Local/nvim-data/lazy/LuaSnip/deps/jsregexp'
gcc -IC:\Users\oscar\AppData\Local\nvim-data\lazy\LuaSnip/deps/lua51_include/ -O2 -fPIC -c jsregexp.c -o jsregexp.o
gcc -IC:\Users\oscar\AppData\Local\nvim-data\lazy\LuaSnip/deps/lua51_include/ -O2 -fPIC -c cutils.c -o cutils.o
gcc -IC:\Users\oscar\AppData\Local\nvim-data\lazy\LuaSnip/deps/lua51_include/ -O2 -fPIC -c libregexp.c -o libregexp.o
gcc -IC:\Users\oscar\AppData\Local\nvim-data\lazy\LuaSnip/deps/lua51_include/ -O2 -fPIC -c libunicode.c -o libunicode.o
gcc -shared jsregexp.o cutils.o libregexp.o libunicode.o  -o jsregexp.so
c:/users/oscar/scoop/apps/gcc/current/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: jsregexp.o:jsregexp.c:(.text+0x17): undefined reference to `luaL_checkudata'
c:/users/oscar/scoop/apps/gcc/current/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: jsregexp.o:jsregexp.c:(.text+0x7f): undefined reference to `lua_pushfstring'
c:/users/oscar/scoop/apps/gcc/current/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: jsregexp.o:jsregexp.c:(.text+0xb9): undefined reference to `luaL_checkudata'

[... errors truncated]

This is a bit above my level, but could it be due to similar problems that were noted on macos? i.e. LUA_LDLIBS=-undefined dynamic_lookup -all_load, which if I understand it correctly makes it so the darwin linker is more lax on undefined symbols? I tried looking for similar things to do on windows/mingw but couldn't find anything.

owallb avatar Aug 28 '23 00:08 owallb

I added this to the Makefile: ...

Oh, yeah that's nice, unfortunately I don't think we can include it as-is, since it (should?) cause issues with more POSIX-like shells (I'll assume that $(OS) is not adjusted for those)

About the undefined symbols, no idea as well, I did some googling, but nothing looks promising :(

Another way of getting jsregexp is as a luarock, maybe that will work better? You'd only have to remove the make jsregexp-part from your config, and install this rock (not the latest version!)

L3MON4D3 avatar Aug 28 '23 06:08 L3MON4D3

(you can check if it's available via :lua = require("luasnip.util.util").jsregexp), it should print a non-nil value.

L3MON4D3 avatar Aug 28 '23 06:08 L3MON4D3

I am having the same issues on Windows 11 and have tried absolutely everything. Tried installing every version of lua, luarocks, jsregexp etc.Tried installing directly, using choco, etc. No success. Did anyone get to the bottom of this and/or find any workarounds?

I got to the exact same point as @owallb above with all those undefined reference to... errors.

GitMurf avatar Mar 25 '24 21:03 GitMurf

met the same problem on win11 too.

alexya avatar Apr 14 '24 11:04 alexya

A way to work using MSYS2:

  1. install MSYS2
  2. open MSYS2 UCRT64 bash, install it's gcc and luajit toolchain. first do pacman -Syu, then pacman -S mingw-w64-ucrt-x86_64-luajit mingw-w64-ucrt-x86_64-make mingw-w64-ucrt-x86_64-gcc
  3. change jsregexp and jsregexp005 makefile, move the link ldflags command to the end:
diff --git a/Makefile b/Makefile
index 2dd9165..6ed5959 100644
--- a/Makefile
+++ b/Makefile
@@ -14,7 +14,7 @@ CC = gcc
 all: $(TARGET)

 $(TARGET): $(OBJECTS)
-       $(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@
+       $(CC) $^ $(LDLIBS) -o $@ $(LDFLAGS)

 %.o: %.c
        $(CC) $(CFLAGS) -c $^ -o $@
  1. make jsregexp, running the follwing command.
 mingw32-make CC=gcc CFLAGS="-I/ucrt64/include/luajit-2.1 -O2 -Wall -fPIC" LDFLAGS="-shared -lluajit-5.1" install_jsregexp

Another way is using luarocks, gcc (e.g. winlibs.com's distribution) and manually compiled luajit registered to luarocks, MSVC is not able to compile jsregexp. then copy the core.dll and its lua file manually. It's much more complicated.

atauzki avatar Apr 17 '24 05:04 atauzki

Hello. I tried the option above, but it didn't help((. No solution yet?

Barmaley0 avatar May 11 '24 21:05 Barmaley0