neorg icon indicating copy to clipboard operation
neorg copied to clipboard

Error compiling treesitter when updating

Open augustocdias opened this issue 10 months ago • 16 comments

Prerequisites

  • [x] I am using the latest stable release of Neovim
  • [x] I am using the latest version of the plugin

Neovim Version

NVIM v0.10.3 Build type: Release LuaJIT 2.1.1713484068 Run "nvim -V1 -v" for more info

Neorg setup

I'm getting an error when updating neorg. It is failing to compile the treesitter. I'm on MacOS 15.2.

Actual behavior

I'm having this error when updating:

nvim-treesitter[norg]: Error during compilation
error: invalid argument '-std=c11' not allowed with 'C++'

Expected behavior

I expect it to update

Steps to reproduce

Update it with lazy.

Potentially conflicting plugins

No response

Other information

No response

Help

None

Implementation help

No response

augustocdias avatar Jan 30 '25 21:01 augustocdias

https://github.com/nvim-neorg/tree-sitter-norg/issues/7#issuecomment-1291508121

benlubas avatar Jan 30 '25 23:01 benlubas

try this:

https://github.com/nvim-treesitter/nvim-treesitter/pull/7664/files

lost22git avatar Feb 18 '25 01:02 lost22git

any solution?

vidwade avatar Feb 22 '25 08:02 vidwade

error: invalid argument '-std=c11' not allowed with 'C++'
Failed to execute the following command:
{
  cmd = "clang++ -std=c++11",
  err = "Error during compilation",
  info = "Compiling...",
  opts = {
    args = { "-o", "parser.so", "-I./src", "src/parser.c", "src/scanner.cc", "-Os", "-std=c11", "-bundle", "-lstdc++", "-fPIC" },
    cwd = "/Users/user/.local/share/nvim/tree-sitter-norg"
  }
}

vidwade avatar Feb 22 '25 08:02 vidwade

any solution?

This worked for me: https://github.com/nvim-neorg/tree-sitter-norg/issues/7#issuecomment-2443983973

In the end I decided to uninstall because I didn't want to have to do this after every update. And overriding clang permanently was not an option for me.

augustocdias avatar Feb 23 '25 05:02 augustocdias

norg treesitter needs latest gcc compiler. This worked for me on mac

brew install gcc
CC=gcc-14 nvim -c "TSInstallSync norg"

nikhil-vemula avatar Mar 05 '25 05:03 nikhil-vemula

norg treesitter needs latest gcc compiler. This worked for me on mac

brew install gcc
CC=gcc-14 nvim -c "TSInstallSync norg"

For me the biggest problem is having to do that every time there's an update...

augustocdias avatar Mar 05 '25 07:03 augustocdias

the TS parser hasn't changed in a long time, and it's not planned to change for a little while either. The current parser is buggy, and there are efforts to write a new one for a slightly different norg spec.

But the result is that you don't actually have to do that every time there's an update :)

benlubas avatar Mar 09 '25 17:03 benlubas

the TS parser hasn't changed in a long time, and it's not planned to change for a little while either. The current parser is buggy, and there are efforts to write a new one for a slightly different norg spec.

But the result is that you don't actually have to do that every time there's an update :)

Every time neorg updates I got an error. I didn't read the code and I don't plan to. The plugin must be trying to download it after every update. Instead of asking or investigating you prefer to be sarcastic :)

augustocdias avatar Mar 10 '25 07:03 augustocdias

ah, sorry you read :) as sarcastic. But I can be a little snarky if that's more your speed.

Guessing you have build = ":Neorg sync-parsers" in your lazy config b/c you didn't actually share it like the issue template asks for. remove that, should fix the error when you update. You will have to run it manually with the fix discussed above any time you're on a new system/fresh install.

benlubas avatar Mar 12 '25 21:03 benlubas

norg treesitter needs latest gcc compiler. This worked for me on mac

brew install gcc
CC=gcc-14 nvim -c "TSInstallSync norg"

I tried this on my macOS with an M3 Pro Max chip, but neither this nor the other mentioned solution worked for me. Neorg was working fine earlier, but after recent updates I'm facing this issue.

kumarsuraj512 avatar Mar 13 '25 18:03 kumarsuraj512

I am also unable to get tree-sitter-norg. to compile on a M2 chip using MacOS system clang (17.0.0). Tree-sitter-norg-meta claims to compile successfully, however.

Downloading tree-sitter-norg...
Creating temporary directory
Extracting tree-sitter-norg...
Compiling...
clang++: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecat
ed]
error: invalid argument '-std=c11' not allowed with 'C++'
error: invalid argument '-std=c11' not allowed with 'C++'
Error detected while processing command line:
Error during compilation
Failed to execute the following command:
{
  cmd = "clang++ -std=c++11",
  err = "Error during compilation",
  info = "Compiling...",
  opts = {
    args = { "-o", "parser.so", "-I./src", "src/parser.c", "src/scanner.cc", "-Os", "-std=c11", "-bundl
e", "-lstdc++", "-fPIC" },
    cwd = "/Users/tormaale/.local/share/nvim/tree-sitter-norg"
  }
}
Downloading tree-sitter-norg_meta...
Creating temporary directory
Extracting tree-sitter-norg_meta...
Compiling...
Treesitter parser for norg_meta has been installed

The following attempts have also not worked:

  • editing the treesitter shell_command_selection.lua (from https://github.com/nvim-treesitter/nvim-treesitter/pull/7664/files) (This results in the following:
Downloading tree-sitter-norg...
Creating temporary directory
Extracting tree-sitter-norg...
Compiling...
clang++: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecat
ed]
src/scanner.cc:1:10: fatal error: 'algorithm' file not found
    1 | #include <algorithm>
      |          ^~~~~~~~~~~
1 error generated.
Error detected while processing command line:
Error during compilation
Failed to execute the following command:
{
  cmd = "clang++ -std=c++11",
  err = "Error during compilation",
  info = "Compiling...",
  opts = {
    args = { "-o", "parser.so", "-I./src", "src/parser.c", "src/scanner.cc", "-Os", "-std=c11", "-bundl
e", "-lstdc++", "-std=c++17", "-fPIC" },
    cwd = "/Users/tormaale/.local/share/nvim/tree-sitter-norg"
  }
}
Downloading tree-sitter-norg_meta...
Creating temporary directory
Extracting tree-sitter-norg_meta...
Compiling...
Treesitter parser for norg_meta has been installed
  • macOS system clang (16.0.0)
  • clang 20.1.1 from https://github.com/llvm/llvm-project/releases/tag/llvmorg-20.1.1.
  • Clang 18.something version of clang (also from llvm github releases)

These errors happen even if I try compiling in a clean shell (no RC files sourced) using either nvim -c 'TSInstallSync norg' and nvim -c 'Neorg sync-parsers'.

Now to the crux of the issue with the suggestions: I don't have homebrew or macports (long story), so I'll have to build gcc if tree-sitter-norg can only be built with GCC and not Clang/LLVM. However, it seems I shouldn't need that based on this PR: https://github.com/nvim-neorg/neorg/pull/891

alextorma avatar Mar 20 '25 16:03 alextorma

I had the same issue on Windows. Workaround (compile manually):

cd ~/AppData/Local/nvim-data/tree-sitter-norg/
zig cc -c -o parser.o src/parser.c -Isrc -shared -Os -std=c11
zig c++ -c -o scanner.o src/scanner.cc -Isrc -shared -Os -std=c++17
zig c++ -o parser.so parser.o scanner.o -lc -shared -Os
cp parser.so ~/AppData/Local/nvim-data/lazy/nvim-treesitter/parser/norg.so

rayquaza912 avatar Mar 24 '25 09:03 rayquaza912

I also tried several approaches, but none worked for me. After some investigation, I found a solution that worked on both my work laptop (M1 Pro) and personal laptop (M3 Pro Max).

My Approach: I discovered that compiler options are taken from method select_compiler_args in .local/share/nvim/lazy/nvim-treesitter/lua/nvim-treesitter/shell_command_selectors.lua

By default, the same arguments were applied to all files. To fix this, I categorized .c and .cc files separately and explicitly assigned the -std option for each.

Modified Method:

function M.select_compiler_args(repo, compiler)
  if string.match(compiler, "cl$") or string.match(compiler, "cl.exe$") then
    return {
      "/Fe:",
      "parser.so",
      "/Isrc",
      repo.files,
      "-Os",
      "/std:c11",
      "/utf-8",
      "/LD",
    }
  elseif string.match(compiler, "zig$") or string.match(compiler, "zig.exe$") then
    return {
      "c++",
      "-o",
      "parser.so",
      repo.files,
      "-lc",
      "-Isrc",
      "-shared",
      "-Os",
      "-std=c11",
    }
  else
    local args = {
      "-o",
      "parser.so",
      "-I./src",
      repo.files,
      "-Os",
      -- "-std=c11",   -- remove "std=c11" from here. 
    }

    if fn.has "mac" == 1 then
      table.insert(args, "-bundle")
    else
      table.insert(args, "-shared")
    end

    -- Separate C and C++ files
    local c_files = {}
    local cpp_files = {}

    for _, file in ipairs(repo.files) do
      local ext = vim.fn.fnamemodify(file, ":e")
      if ext == "c" then
        table.insert(c_files, file)
      elseif ext == "cc" or ext == "cpp" or ext == "cxx" then
        table.insert(cpp_files, file)
      else
        table.insert(args, file) -- Keep other files unchanged
      end
    end

    -- Apply proper standards
    if #c_files > 0 then
      table.insert(args, "-std=c11")  
    end

    if #cpp_files > 0 then
      table.insert(args, "-std=c++17") 
      table.insert(args, "-lstdc++") 
    end

    if fn.has "win32" == 0 then
      table.insert(args, "-fPIC")
    end
    return args
  end
end

After making these changes, I ran nvim -c Neorg sync-parsers, and it worked successfully. I kept the changes in a separate branch and reverted them after confirming the sync was successful.

I don't know if this is a right approach but it worked for me 😄

kumarsuraj512 avatar Mar 24 '25 10:03 kumarsuraj512

This work for me too on MacOS Sequoia version 15.3.2 on Apple Mac Studio with Apple M2 Max

brew install gcc CC=gcc-14 nvim -c "TSInstallSync norg"

IpadDilectio avatar Mar 24 '25 10:03 IpadDilectio

I'm trying to reinstall neorg with a neovim configuration that relies on LazyVim, and unfortunately it no longer works. I've tried CC=gcc-14 nvim -c “TSInstall norg” again but I still get compile errors. This tells me that there's a problem with /Library/Developer/CommandLineTools/SDKs/MacOSX15.sdk What should I do now? I've gone back to my previous configuration with NvChad. But I'm afraid the next time I update Neorg, there'll be another problem.

IpadDilectio avatar Apr 19 '25 20:04 IpadDilectio