LuaSnip icon indicating copy to clipboard operation
LuaSnip copied to clipboard

Can't install jsregexp

Open gabrielcarloto opened this issue 2 years ago • 34 comments

I get this error:

git submodule init
git submodule update
make INCLUDE_DIR=-I/c/Users/T-GAMER/AppData/Local/nvim-data/lazy/LuaSnip/deps/lua51_include/ LDLIBS="-lluajit-5.1" -C deps/jsregexp
make[1]: Entering directory 'C:/Users/T-GAMER/AppData/Local/nvim-data/lazy/LuaSnip/deps/jsregexp'
gcc -IC:/Users/T-GAMER/AppData/Local/nvim-data/lazy/LuaSnip/deps/lua51_include/ -O2 -fPIC -c jsregexp.c -o jsregexp.o
gcc -IC:/Users/T-GAMER/AppData/Local/nvim-data/lazy/LuaSnip/deps/lua51_include/ -O2 -fPIC -c cutils.c -o cutils.o
gcc -IC:/Users/T-GAMER/AppData/Local/nvim-data/lazy/LuaSnip/deps/lua51_include/ -O2 -fPIC -c libregexp.c -o libregexp.o
libregexp.c: In function 'lre_exec':
libregexp.c:2530:17: warning: implicit declaration of function 'alloca' [-Wimplicit-function-declaration]
     stack_buf = alloca(alloca_size);
                 ^~~~~~
libregexp.c:2530:17: warning: incompatible implicit declaration of built-in function 'alloca'
gcc -IC:/Users/T-GAMER/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 -lluajit-5.1 -o jsregexp.so
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe: cannot find -lluajit-5.1
collect2.exe: error: ld returned 1 exit status
make[1]: *** [Makefile:17: jsregexp.so] Error 1
make[1]: Leaving directory 'C:/Users/T-GAMER/AppData/Local/nvim-data/lazy/LuaSnip/deps/jsregexp'
make: *** [Makefile:21: jsregexp] Error 2

I think this is almost the same as #569, but I couldn't solve it (probably because I'm very new to neovim). Running ldd path/to/nvim.exe | grep luajit on the terminal does not find anything. But changing luajit to just lua finds lua51.dll => /c/Users/T-GAMER/scoop/apps/neovim/0.8.2/bin/lua51.dll. Don't know if it is what I need.

Info:

OS: Windows 11 NVIM v0.8.2 Build type: RelWithDebInfo LuaJIT 2.1.0-beta3

gabrielcarloto avatar Feb 03 '23 14:02 gabrielcarloto

Oh, I guess the libraries are resolved in yet another way on windows.. Do you have luajit.dll installed locally, somewhere?

L3MON4D3 avatar Feb 03 '23 16:02 L3MON4D3

I'm also a bit confused that neovim uses LuaJIT 2.1.0-beta3, but isn't linked against it

L3MON4D3 avatar Feb 03 '23 16:02 L3MON4D3

I tried searching for luajit.dll in my home path before but couldn't find it.

gabrielcarloto avatar Feb 03 '23 16:02 gabrielcarloto

I also have the same error. I'm on Ubuntu 22.04, and I installed neovim with appimage.

kiyoon avatar Mar 02 '23 15:03 kiyoon

@L3MON4D3 I still think we should just ship prebuilt .so maybe even assume luajit and use jsregexp via ffi.

leiserfg avatar Mar 02 '23 15:03 leiserfg

Couldn't there be (subtle?) issues with relying on a pre-built one, which doesn't necessarily match the system its executed on? Also, I don't want to spend too much time on that, using the luarock should work in all cases. But we could definitely collect some working libraries here, here's mine for example (zip since github won't accept .so) luajit_archlinux_x86_64.zip

L3MON4D3 avatar Mar 02 '23 21:03 L3MON4D3

I know some plugins like markdown-preview and coc ship with pre-built binaries, and if it works for most common architectures it may be better than nothing. It's up to you, and I don't know how big of a problem it is without it. Personally I prefer to not have too many dependencies in my config, so it makes it easier to install my dotfiles anywhere I go. For now it seems like this plugin works ok without it so I won't configure, but since I haven't experienced the lsp snippets thing I can't tell how important it would be.

Also I think it would be easy to change the makefile settings to detect the appimage version of neovim. However, it won't be consistent over the platforms, and that's why I wouldn't really configure my dotfiles that way.

kiyoon avatar Mar 02 '23 21:03 kiyoon

Couldn't there be (subtle?) issues with relying on a pre-built one

Not if they are linked against old versions of libc (and lua if not using the ffi route). telescope-fzy-native.nvim does that see https://github.com/romgrk/fzy-lua-native/tree/aa00feb01128c4d279c8471898e15898e75d5df5/static

leiserfg avatar Mar 02 '23 22:03 leiserfg

True, portability is also a good point The best way to do this seems to be a new target in the makefile, so there's make install_jsregexp (now unfortunately-named) and make install_prebuilt_jsregexp (which just moves some .so to the right place)

TBH I'm not all that motivated to get on this, if anybody else wants to deal with it, I'd appreciate it :sweat_smile:

L3MON4D3 avatar Mar 03 '23 07:03 L3MON4D3

Screenshot from Pop_OS!

image

Which I'm guessing is due to

image

briandipalma avatar May 02 '23 22:05 briandipalma

Mhm in that case you'll have to install the package which provides the library for luajit

L3MON4D3 avatar May 03 '23 05:05 L3MON4D3

I get this issue on Arch Linux as well. I do have luajit installed, however. image image

rosshadden avatar May 12 '23 06:05 rosshadden

Could you show paru -Ql luajit?

L3MON4D3 avatar May 12 '23 07:05 L3MON4D3

Certainly, fellow pacman enjoyer: image

Based on this it seems I have libraries for 5.1.2 and not 5.1. I cheated and created a symlink pointing libluajit-5.1.2 to libluajit-5.1 and that worked. Thanks for your help!

rosshadden avatar May 12 '23 15:05 rosshadden

Certainly, fellow pacman enjoyer:

:D

Ahh, you probably have nix installed, but not luajit with nix (100% unexpected), and then we pick the wrong version.. :( As an alternative, to not need the symlink, you can also make LUA_LDLIBS=-lluajit5.1 install_jsregexp instead, that way the bug is at least bypassed

L3MON4D3 avatar May 12 '23 18:05 L3MON4D3

@briandipalma Did you solve it? I'm using lazy.nvim as my plugin manager and see the same error message. I'm on macOS 13.5.

nyngwang avatar May 26 '23 07:05 nyngwang

I'm ignoring it as it's optional but as mentioned above you can fix it by installing the package that provides the luajit executable.

briandipalma avatar May 27 '23 13:05 briandipalma

I am on Opensuse

  Failed (1)
    ● LuaSnip 15.26ms ✔  build
        NOTE: jsregexp is optional, so not a big deal if it fails to build
        git submodule init
        git submodule update
        make INCLUDE_DIR=-I/home/aasu/.local/share/nvim/lazy/LuaSnip/deps/lua51_include/ LDLIBS="-lluajit-5.1" -C deps/jsregexp
        make[1]: Entering directory '/home/aasu/.local/share/nvim/lazy/LuaSnip/deps/jsregexp'
        gcc -I/home/aasu/.local/share/nvim/lazy/LuaSnip/deps/lua51_include/ -O2 -fPIC -c jsregexp.c -o jsregexp.o
        gcc -I/home/aasu/.local/share/nvim/lazy/LuaSnip/deps/lua51_include/ -O2 -fPIC -c cutils.c -o cutils.o
        gcc -I/home/aasu/.local/share/nvim/lazy/LuaSnip/deps/lua51_include/ -O2 -fPIC -c libregexp.c -o libregexp.o
        gcc -I/home/aasu/.local/share/nvim/lazy/LuaSnip/deps/lua51_include/ -O2 -fPIC -c libunicode.c -o libunicode.o
        gcc -shared jsregexp.o cutils.o libregexp.o libunicode.o -lluajit-5.1 -o jsregexp.so
        /usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: cannot find -lluajit-5.1: No such file or directory
        collect2: error: ld returned 1 exit status
        make[1]: *** [Makefile:17: jsregexp.so] Error 1
        make: *** [Makefile:53: jsregexp] Error 2
        make[1]: Leaving directory '/home/aasu/.local/share/nvim/lazy/LuaSnip/deps/jsregexp'

However I have luajit installed.

luajit -v       
LuaJIT 2.1.0-beta3 -- Copyright (C) 2005-2022 Mike Pall. https://luajit.org/

And I am using LazyVim default installation.

aasutossh avatar May 29 '23 02:05 aasutossh

Hi, could some of you try (especially the mac-users) try if the jsregexp-install works correctly with #922?

For this the previously generated files have to be removed, ie.

cd <luasnip-install-dir, probably in .local/share/nvim/lazy/>
make -C deps/jsregexp clean
make install_jsregexp

It should finish without errors, and something like :lua ls.lsp_expand("a${TM_LINE_INDEX/(.*)/asdf $1 asdf/g}a") should expand correctly

Thank you :)

L3MON4D3 avatar Jun 14 '23 19:06 L3MON4D3

I get an error about ls not being a global. Is there some other way for me to test this? I am on PopOS though.

briandipalma avatar Jun 16 '23 21:06 briandipalma

Ah srry, of course not everyone has that global set up. Use require("luasnip") instead of ls

L3MON4D3 avatar Jun 17 '23 06:06 L3MON4D3

I get aasdf 0 asdfasdf asdfa inserted into the buffer, is that correct?

briandipalma avatar Jun 17 '23 08:06 briandipalma

Yes, thank you!

L3MON4D3 avatar Jun 17 '23 09:06 L3MON4D3

I also am having this issue. After the initial error on install, things seem to work fine (at least I don't get any additional errors). I can run luajit just fine.

  Failed (1)
    ● LuaSnip 50.04ms   nvim-cmp
        git submodule init
        git submodule update
        make INCLUDE_DIR=-I/Users/lcrown/.local/share/nvim/lazy/LuaSnip/deps/lua51_include/ LDLIBS="" -C deps/jsregexp
        gcc -I/Users/lcrown/.local/share/nvim/lazy/LuaSnip/deps/lua51_include/ -O2 -fPIC -c jsregexp.c -o jsregexp.o
        gcc -I/Users/lcrown/.local/share/nvim/lazy/LuaSnip/deps/lua51_include/ -O2 -fPIC -c cutils.c -o cutils.o
        gcc -I/Users/lcrown/.local/share/nvim/lazy/LuaSnip/deps/lua51_include/ -O2 -fPIC -c libregexp.c -o libregexp.o
        gcc -I/Users/lcrown/.local/share/nvim/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
        Undefined symbols for architecture arm64:
          "_luaL_checklstring", referenced from:
              _jsregexp_compile in jsregexp.o
              _regexp_call in jsregexp.o
          "_luaL_checkudata", referenced from:
              _regexp_call in jsregexp.o
              _regexp_tostring in jsregexp.o
          "_luaL_newmetatable", referenced from:
              _luaopen_jsregexp in jsregexp.o
          "_luaL_register", referenced from:
              _luaopen_jsregexp in jsregexp.o
          "_lua_createtable", referenced from:
              _luaopen_jsregexp in jsregexp.o
              _regexp_call in jsregexp.o
          "_lua_getfield", referenced from:
              _jsregexp_compile in jsregexp.o
          "_lua_newuserdata", referenced from:
              _jsregexp_compile in jsregexp.o
          "_lua_pushfstring", referenced from:
              _regexp_tostring in jsregexp.o
          "_lua_pushlstring", referenced from:
              _regexp_call in jsregexp.o
          "_lua_pushnil", referenced from:
              _jsregexp_compile in jsregexp.o
              _regexp_call in jsregexp.o
          "_lua_pushnumber", referenced from:
              _regexp_call in jsregexp.o
          "_lua_pushstring", referenced from:
              _jsregexp_compile in jsregexp.o
              _regexp_call in jsregexp.o
          "_lua_rawseti", referenced from:
              _regexp_call in jsregexp.o
          "_lua_setfield", referenced from:
              _regexp_call in jsregexp.o
          "_lua_setmetatable", referenced from:
              _jsregexp_compile in jsregexp.o
          "_lua_settop", referenced from:
              _luaopen_jsregexp in jsregexp.o
          "_lua_touserdata", referenced from:
              _regexp_gc in jsregexp.o
          "_lua_type", referenced from:
              _jsregexp_compile in jsregexp.o
        ld: symbol(s) not found for architecture arm64
        clang: error: linker command failed with exit code 1 (use -v to see invocation)
        make[1]: *** [jsregexp.so] Error 1
        make: *** [jsregexp] Error 2

lcrownover avatar Jun 26 '23 23:06 lcrownover

Could you try doing the last gcc-invocation again, but replace -shared with -shared -Wl,-undefined,dynamic_lookup

L3MON4D3 avatar Jun 27 '23 14:06 L3MON4D3

After editing the deps/jsregexp/Makefile:

LDFLAGS = -shared -Wl,-undefined,dynamic_lookup
#LDFLAGS = -shared

The following command now returns with this:

➜  LuaSnip git:(master) make INCLUDE_DIR=-I/Users/lcrown/.local/share/nvim/lazy/LuaSnip/deps/lua51_include/ LDLIBS="" -C deps/jsregexp
gcc -shared -Wl,-undefined,dynamic_lookup jsregexp.o cutils.o libregexp.o libunicode.o  -o jsregexp.so

Not sure how to tell if that's success or not 😆

lcrownover avatar Jun 27 '23 14:06 lcrownover

I think so :D You can verify by doing the test above

L3MON4D3 avatar Jun 27 '23 18:06 L3MON4D3

Sorry, @lcrownover, what kind of OS are you on? I'd assumed MacOS, but then you should be getting different LDLIBS. What does uname -a print on your machine?

L3MON4D3 avatar Jun 28 '23 10:06 L3MON4D3

@L3MON4D3 I'm on mac. Running :lua require('luasnip').lsp_expand("a${TM_LINE_INDEX/(.*)/asdf $1 asdf/g}a") expanded to a0a, so I think it's working?

uname -a

Darwin UO-2010933 22.5.0 Darwin Kernel Version 22.5.0: Thu Jun  8 22:22:20 PDT 2023; root:xnu-8796.121.3~7/RELEASE_ARM64_T6000 arm64

lcrownover avatar Jun 28 '23 14:06 lcrownover

It's working, I'm just a bit confused why you did not get the flags we use for MacOS. uname -a looks correct though.. just uname is also Darwin, right?

L3MON4D3 avatar Jun 28 '23 14:06 L3MON4D3