Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compilation error during install #7

Open
tdjordan opened this issue Aug 31, 2021 · 47 comments
Open

Compilation error during install #7

tdjordan opened this issue Aug 31, 2021 · 47 comments

Comments

@tdjordan
Copy link

I have the following in my vim config

local parser_config = require 'nvim-treesitter.parsers'.get_parser_configs()

parser_config.norg = {
  install_info =
    { url    = 'https://github.com/vhyrro/tree-sitter-norg'
    , files  = { 'src/parser.c', 'src/scanner.cc' }
    , branch = 'main'
  }
}

When I run TSUpdate, I get this error:

nvim-treesitter[norg]: Error during compilation
src/scanner.cc:97:39: error: expected expression
        return std::vector<TokenType>({ lhs, static_cast<TokenType>(rhs) });
                                      ^
src/scanner.cc:100:27: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
    std::vector<TokenType>&& operator|(std::vector<TokenType>&& lhs, TokenType rhs)
                          ^
src/scanner.cc:100:62: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
    std::vector<TokenType>&& operator|(std::vector<TokenType>&& lhs, TokenType rhs)
                                                             ^
src/scanner.cc:327:41: error: expected ';' at end of declaration list
    std::vector<size_t>& get_tag_stack() noexcept { return m_TagStack; }
                                        ^
                                        ;
src/scanner.cc:556:27: warning: in-class initialization of non-static data member is a C++11 extension [-Wc++11-extensions]
    TokenType m_LastToken = NONE;
                          ^
src/scanner.cc:559:26: warning: in-class initialization of non-static data member is a C++11 extension [-Wc++11-extensions]
    size_t m_ParsedChars = 0, m_IndentationLevel = 0;
                         ^
src/scanner.cc:559:50: warning: in-class initialization of non-static data member is a C++11 extension [-Wc++11-extensions]
    size_t m_ParsedChars = 0, m_IndentationLevel = 0;
                                                 ^
src/scanner.cc:565:54: warning: in-class initialization of non-static data member is a C++11 extension [-Wc++11-extensions]
    const std::array<int32_t, 6> s_DetachedModifiers = { '*', '-', '>', '|', '=', '~' };
                                                     ^
src/scanner.cc:121:13: error: use of undeclared identifier 'advance'
            advance(lexer);
            ^
src/scanner.cc:131:13: error: use of undeclared identifier 'advance'
            advance(lexer);
            ^
src/scanner.cc:141:17: error: use of undeclared identifier 'advance'
                advance(lexer);
                ^
src/scanner.cc:148:21: error: use of undeclared identifier 'advance'
                    advance(lexer);
                    ^
src/scanner.cc:162:13: error: use of undeclared identifier 'advance'
            advance(lexer);
            ^
src/scanner.cc:167:48: error: use of undeclared identifier 'm_Current'
                if (lexer->lookahead == ']' && m_Current != '\\')
                                               ^
src/scanner.cc:169:21: error: use of undeclared identifier 'advance'
                    advance(lexer);
                    ^
src/scanner.cc:141:17: error: use of undeclared identifier 'advance'
                advance(lexer);
                ^
src/scanner.cc:148:21: error: use of undeclared identifier 'advance'
                    advance(lexer);
                    ^
src/scanner.cc:162:13: error: use of undeclared identifier 'advance'
            advance(lexer);
            ^
src/scanner.cc:167:48: error: use of undeclared identifier 'm_Current'
                if (lexer->lookahead == ']' && m_Current != '\\')
                                               ^
src/scanner.cc:169:21: error: use of undeclared identifier 'advance'
                    advance(lexer);
                    ^
src/scanner.cc:177:17: error: use of undeclared identifier 'advance'
                advance(lexer);
                ^
src/scanner.cc:184:20: error: use of undeclared identifier 'check_link'
            return check_link(lexer);
                   ^
src/scanner.cc:188:13: error: use of undeclared identifier 'advance'
            advance(lexer);
            ^
src/scanner.cc:206:17: error: use of undeclared identifier 'skip'
                skip(lexer);
                ^
src/scanner.cc:211:17: error: use of undeclared identifier 'advance'
                advance(lexer);
                ^
src/scanner.cc:217:21: error: use of undeclared identifier 'advance'
                    advance(lexer);
                    ^
src/scanner.cc:220:25: error: use of undeclared identifier 'advance'
                        advance(lexer);
                        ^
src/scanner.cc:223:29: error: use of undeclared identifier 'advance'
                            advance(lexer);
                            ^
src/scanner.cc:227:37: error: use of undeclared identifier 'advance'
                                    advance(lexer);
                                    ^
src/scanner.cc:252:25: error: use of undeclared identifier 'advance'
                        advance(lexer);
                        ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
6 warnings and 20 errors generated.

From :checkhealth nvim_treesitter

  health#nvim_treesitter#check
  ========================================================================
  ## Installation
    - OK: `tree-sitter` found  0.20.0 (parser generator, only needed for :TSInstallFromGrammar)
    - OK: `node` found v16.8.0 (only needed for :TSInstallFromGrammar)
    - OK: `git` executable found.
    - OK: `cc` executable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl" }
    - OK: Neovim was compiled with tree-sitter runtime ABI version 13 (required >=13). Parsers must be compatible with runtime ABI.

And cc --version

Apple clang version 12.0.5 (clang-1205.0.22.11)
Target: x86_64-apple-darwin20.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
@tdjordan
Copy link
Author

tdjordan commented Sep 1, 2021

it looks like it is coming from the tree-sitter test step that is being invoked during the yarn test portion.

❯ yarn test                                                                                                                                  20:08:02
yarn run v1.22.11
$ tree-sitter test
Parser compilation failed.
Stdout:
Stderr: /Users/tjordan/.local/share/nvim/tree-sitter-norg-old/src/scanner.cc:97:39: error: expected expression
        return std::vector<TokenType>({ lhs, static_cast<TokenType>(rhs) });
                                      ^
/Users/tjordan/.local/share/nvim/tree-sitter-norg-old/src/scanner.cc:100:27: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
    std::vector<TokenType>&& operator|(std::vector<TokenType>&& lhs, TokenType rhs)
                          ^
/Users/tjordan/.local/share/nvim/tree-sitter-norg-old/src/scanner.cc:100:62: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
    std::vector<TokenType>&& operator|(std::vector<TokenType>&& lhs, TokenType rhs)
                                                             ^
/Users/tjordan/.local/share/nvim/tree-sitter-norg-old/src/scanner.cc:327:41: error: expected ';' at end of declaration list
    std::vector<size_t>& get_tag_stack() noexcept { return m_TagStack; }
                                        ^
                                        ;
/Users/tjordan/.local/share/nvim/tree-sitter-norg-old/src/scanner.cc:556:27: warning: in-class initialization of non-static data member is a C++11 extension [-Wc++11-extensions]
    TokenType m_LastToken = NONE;
                          ^
/Users/tjordan/.local/share/nvim/tree-sitter-norg-old/src/scanner.cc:559:26: warning: in-class initialization of non-static data member is a C++11 extension [-Wc++11-extensions]
    size_t m_ParsedChars = 0, m_IndentationLevel = 0;
                         ^
/Users/tjordan/.local/share/nvim/tree-sitter-norg-old/src/scanner.cc:559:50: warning: in-class initialization of non-static data member is a C++11 extension [-Wc++11-extensions]
    size_t m_ParsedChars = 0, m_IndentationLevel = 0;
                                                 ^
/Users/tjordan/.local/share/nvim/tree-sitter-norg-old/src/scanner.cc:565:54: warning: in-class initialization of non-static data member is a C++11 extension [-Wc++11-extensions]
    const std::array<int32_t, 6> s_DetachedModifiers = { '*', '-', '>', '|', '=', '~' };
                                                     ^
/Users/tjordan/.local/share/nvim/tree-sitter-norg-old/src/scanner.cc:121:13: error: use of undeclared identifier 'advance'
            advance(lexer);
            ^
/Users/tjordan/.local/share/nvim/tree-sitter-norg-old/src/scanner.cc:131:13: error: use of undeclared identifier 'advance'
            advance(lexer);
            ^
/Users/tjordan/.local/share/nvim/tree-sitter-norg-old/src/scanner.cc:141:17: error: use of undeclared identifier 'advance'
                advance(lexer);
                ^
/Users/tjordan/.local/share/nvim/tree-sitter-norg-old/src/scanner.cc:148:21: error: use of undeclared identifier 'advance'
                    advance(lexer);
                    ^
/Users/tjordan/.local/share/nvim/tree-sitter-norg-old/src/scanner.cc:162:13: error: use of undeclared identifier 'advance'
            advance(lexer);
            ^
/Users/tjordan/.local/share/nvim/tree-sitter-norg-old/src/scanner.cc:167:48: error: use of undeclared identifier 'm_Current'
                if (lexer->lookahead == ']' && m_Current != '\\')
                                               ^
/Users/tjordan/.local/share/nvim/tree-sitter-norg-old/src/scanner.cc:169:21: error: use of undeclared identifier 'advance'
                    advance(lexer);
                    ^
/Users/tjordan/.local/share/nvim/tree-sitter-norg-old/src/scanner.cc:177:17: error: use of undeclared identifier 'advance'
                advance(lexer);
                ^
/Users/tjordan/.local/share/nvim/tree-sitter-norg-old/src/scanner.cc:184:20: error: use of undeclared identifier 'check_link'
            return check_link(lexer);
                   ^
/Users/tjordan/.local/share/nvim/tree-sitter-norg-old/src/scanner.cc:188:13: error: use of undeclared identifier 'advance'
            advance(lexer);
            ^
/Users/tjordan/.local/share/nvim/tree-sitter-norg-old/src/scanner.cc:206:17: error: use of undeclared identifier 'skip'
                skip(lexer);
                ^
/Users/tjordan/.local/share/nvim/tree-sitter-norg-old/src/scanner.cc:211:17: error: use of undeclared identifier 'advance'
                advance(lexer);
                ^
/Users/tjordan/.local/share/nvim/tree-sitter-norg-old/src/scanner.cc:217:21: error: use of undeclared identifier 'advance'
                    advance(lexer);
                    ^
/Users/tjordan/.local/share/nvim/tree-sitter-norg-old/src/scanner.cc:220:25: error: use of undeclared identifier 'advance'
                        advance(lexer);
                        ^
/Users/tjordan/.local/share/nvim/tree-sitter-norg-old/src/scanner.cc:223:29: error: use of undeclared identifier 'advance'
                            advance(lexer);
                            ^
/Users/tjordan/.local/share/nvim/tree-sitter-norg-old/src/scanner.cc:227:37: error: use of undeclared identifier 'advance'
                                    advance(lexer);
                                    ^
/Users/tjordan/.local/share/nvim/tree-sitter-norg-old/src/scanner.cc:252:25: error: use of undeclared identifier 'advance'
                        advance(lexer);
                        ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
6 warnings and 20 errors generated.

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

@tdjordan
Copy link
Author

tdjordan commented Sep 1, 2021

Hmmm, I am getting this on a fresh clone.

❯ node-gyp build                                       20:30:06
gyp info it worked if it ends with ok
gyp info using [email protected]
gyp info using [email protected] | darwin | x64
gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
make: *** No rule to make target `../../../../../usr/lib/node_modules/node-gyp/addon.gypi', needed by `Makefile'.  Stop.
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/Users/tjordan/.config/yarn/global/node_modules/node-gyp/lib/build.js:194:23)
gyp ERR! stack     at ChildProcess.emit (node:events:394:28)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:290:12)
gyp ERR! System Darwin 20.6.0
gyp ERR! command "/usr/local/Cellar/node/16.8.0/bin/node" "/usr/local/bin/node-gyp" "build"
gyp ERR! cwd /Users/tjordan/devRoot/treesitter/tree-sitter-norg
gyp ERR! node -v v16.8.0
gyp ERR! node-gyp -v v8.2.0
gyp ERR! not ok

@vhyrro
Copy link
Member

vhyrro commented Sep 1, 2021

We know as of right now that installation on macos is rather painful. We're also hoping to work with the nvim-treesitter guys to make the process easier. Danymat has a temporary workaround for compiling on mac here, you might wanna check it out.

@vitaly
Copy link

vitaly commented Dec 18, 2021

that link provides a solution that, I think, is a bit too 'dirty'. no need to mess with global cc, you can override it just for installation like so:

brew install gcc
CC=gcc-11 nvim -c "TSInstall norg"

@danymat
Copy link
Member

danymat commented Dec 18, 2021

Yes, this is what I wrote here: nvim-neorg/neorg#74 (comment)

@deryrahman
Copy link

Trying to use

CC=gcc-11 nvim

But I've got another error:

nvim-treesitter[norg]: Error during compilation
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/sys/wait.h:110,
                 from /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/stdlib.h:66,
                 from /usr/local/Cellar/gcc/11.2.0_3/include/c++/11/cstdlib:75,
                 from /usr/local/Cellar/gcc/11.2.0_3/include/c++/11/bits/stl_algo.h:59,
                 from /usr/local/Cellar/gcc/11.2.0_3/include/c++/11/algorithm:62,
                 from src/scanner.cc:1:
/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/sys/resource.h:443:34: error: expected initializer before '__OSX_AVAILABLE_STARTING'
  443 | int     getiopolicy_np(int, int) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0);
      |                                  ^~~~~~~~~~~~~~~~~~~~~~~~
/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/sys/resource.h:449:39: error: expected initializer before '__OSX_AVAILABLE_STARTING'
  449 | int     setiopolicy_np(int, int, int) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0);
      |                                       ^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/stdlib.h:128,
                 from /usr/local/Cellar/gcc/11.2.0_3/include/c++/11/cstdlib:75,
                 from /usr/local/Cellar/gcc/11.2.0_3/include/c++/11/bits/stl_algo.h:59,
                 from /usr/local/Cellar/gcc/11.2.0_3/include/c++/11/algorithm:62,
                 from src/scanner.cc:1:
/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/malloc/_malloc.h:52:77: error: expected initializer before '__OSX_AVAILABLE_STARTING'
...

I'm not sure why, I thought it was because of my SDK(?)

Here's my sdk location

❯ ls -l /Library/Developer/CommandLineTools/SDKs/
total 0
lrwxr-xr-x  1 root  wheel   15 Oct 10  2019 MacOSX.sdk -> MacOSX10.15.sdk
drwxr-xr-x  7 root  wheel  224 Jul 16  2019 MacOSX10.14.sdk
drwxr-xr-x  8 root  wheel  256 Aug 30  2019 MacOSX10.15.sdk

And here's my brew config

HOMEBREW_VERSION: 3.3.10
ORIGIN: https://github.com/Homebrew/brew
HEAD: 385892f3d27dcab0f5a1cb47c3927d9d65ed007c
Last commit: 22 hours ago
Core tap ORIGIN: https://github.com/Homebrew/homebrew-core
Core tap HEAD: c3d7d6ff280e2a907f2e1897d09cb90e77ffb279
Core tap last commit: 57 minutes ago
Core tap branch: master
HOMEBREW_PREFIX: /usr/local
HOMEBREW_CASK_OPTS: []
HOMEBREW_CORE_GIT_REMOTE: https://github.com/Homebrew/homebrew-core
HOMEBREW_DISPLAY: /private/tmp/com.apple.launchd.8BvWKdiBS3/org.macosforge.xquartz:0
HOMEBREW_MAKE_JOBS: 12
Homebrew Ruby: 2.6.8 => /usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/2.6.8/bin/ruby
CPU: dodeca-core 64-bit kabylake
Clang: 12.0.0 build 1200
Git: 2.34.1 => /usr/local/bin/git
Curl: 7.64.1 => /usr/bin/curl
macOS: 10.15.7-x86_64
CLT: 11.0.0.33.8
Xcode: 12.4

And here's my checkhealth nvim_treesitter

nvim_treesitter: health#nvim_treesitter#check
========================================================================
## Installation
  - OK: `tree-sitter` found  0.20.2 (parser generator, only needed for :TSInstallFromGrammar)
  - OK: `node` found v17.3.0 (only needed for :TSInstallFromGrammar)
  - OK: `git` executable found.
  - OK: `gcc-11` executable found. Selected from { "gcc-11", "cc", "gcc", "clang", "cl", "zig" }
    Version: gcc-11 (Homebrew GCC 11.2.0_3) 11.2.0
  - OK: Neovim was compiled with tree-sitter runtime ABI version 13 (required >=13). Parsers must be compatible with runtime ABI.
...

Still trying to figure it out the issue

@danymat
Copy link
Member

danymat commented Jan 12, 2022

Seems like you're on a old SDK version. What is your macOS Version ?

@deryrahman
Copy link

@danymat Catalina, macOS version 10.15.7

@yads
Copy link

yads commented Jan 28, 2022

Seeing the following compilation error after upgrading to Monterrey:

nvim-treesitter[norg]: Error during compilation
Undefined symbols for architecture x86_64:
  "_main", referenced from:
     implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [parser.so] Error 1

@l1ch40
Copy link

l1ch40 commented Jan 30, 2022

Same problem

@danymat
Copy link
Member

danymat commented Feb 3, 2022

Hello, can you guys check out what's the output of gcc-11 --version ?

@yads
Copy link

yads commented Feb 3, 2022

It doesn't look like I have gcc-11, but the output of gcc --version is:

Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 13.0.0 (clang-1300.0.29.30)
Target: x86_64-apple-darwin21.3.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

@danymat
Copy link
Member

danymat commented Feb 3, 2022

Yeah, you should use gcc version instead. It seems that default gcc version (even if it's gcc-11) fails on Mac

@yads
Copy link

yads commented Feb 3, 2022

Sorry I'm not sure I follow. So here's what I did.

  1. I ran brew install gcc
  2. I then symlinked /usr/local/bin/gcc-11 to /usr/local/bin/gcc So that it would be picked up before the system gcc on mac.
  3. Opened a new shell and ran :TSInstall norg in a new nvim

Still getting the same compilation error. Looking here https://stackoverflow.com/questions/11852568/gcc-4-8-on-mac-os-x-10-8-throws-undefined-symbols-for-architecture-x86-64 it seems like it's not linking the C++ std library by default?

@danymat
Copy link
Member

danymat commented Feb 3, 2022

I then symlinked /usr/local/bin/gcc-11 to /usr/local/bin/gcc So that it would be picked up before the system gcc on mac.

Weirdly it seems that the symlink did not work, or your PATH is somehow different. The output of gcc version with brew should yield different verbose text. Try exploring this part and be sure that doing gcc --version shows brew gcc

@yads
Copy link

yads commented Feb 3, 2022

Sorry, misunderstanding, I did all of those steps after you said to use gcc. Here's the output of gcc --version after creating the symlink:

❯ gcc --version
gcc (Homebrew GCC 11.2.0_3) 11.2.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

@danymat
Copy link
Member

danymat commented Feb 3, 2022

Can you show me the output of checkhealth nvim_treesitter

@yads
Copy link

yads commented Feb 4, 2022

So originally it looked like it was still using /usr/bin/gcc. Then after running export CC=/usr/loca/bin/gcc-11 I got this output

nvim_treesitter: health#nvim_treesitter#check
========================================================================
## Installation
  - OK: `tree-sitter` found 0.20.4 (parser generator, only needed for :TSInstallFromGrammar)
  - OK: `node` found v14.18.3 (only needed for :TSInstallFromGrammar)
  - OK: `git` executable found.
  - OK: `/usr/local/bin/gcc-11` executable found. Selected from { "/usr/local/bin/gcc-11", "cc", "gcc", "clang", "cl", "zig" }
    Version: gcc-11 (Homebrew GCC 11.2.0_3) 11.2.0
  - OK: Neovim was compiled with tree-sitter runtime ABI version 13 (required >=13). Parsers must be compatible with runtime ABI.

Unfortunately the error persists :(

@yads
Copy link

yads commented Feb 4, 2022

A bit more, I tried using g++ as in that SO link and it failed with an error complaining about the -std=c99 flag in the binding.gyp file

@lcrownover
Copy link

I am also seeing this compilation error on my Mac, though I have not yet upgraded to Monterey (still on Big Sur).

Everything was working fine, did a :PlugUpdate to update all my plugins via vundle, then this showed up when treesitter recompiled all the language parsers.

@yads
Copy link

yads commented Feb 5, 2022

Interesting, I've also now seen the same error with the latex parser. Maybe an upstream problem with node-gyp?

@shaunsingh
Copy link

I can't run gcc-11 as I'm using macOS 13, which throws an ld error under gcc-11, so I've installed gcc-12

Running CC=gcc-12 nvim and getting this error:

nvim-treesitter[norg]: Error during compilation
0  0x1031081a0  __assert_rtn + 140
1  0x102f8fa8c  mach_o::relocatable::Parser<arm64>::parse(mach_o::relocatable::ParserOptions const&) + 4536
2  0x102f61d38  mach_o::relocatable::Parser<arm64>::parse(unsigned char const*, unsigned long long, char const*, long, ld::File::Ordinal, mach_o::
relocatable::ParserOptions const&) + 148
3  0x102fca4ac  ld::tool::InputFiles::makeFile(Options::FileInfo const&, bool) + 1468
4  0x102fcd360  ___ZN2ld4tool10InputFilesC2ER7Options_block_invoke + 56
5  0x1a20b365c  _dispatch_client_callout2 + 20
6  0x1a20c70d0  _dispatch_apply_invoke + 224
7  0x1a20b361c  _dispatch_client_callout + 20
8  0x1a20c516c  _dispatch_root_queue_drain + 684
9  0x1a20c586c  _dispatch_worker_thread2 + 164
10  0x1a2236314  _pthread_wqthread + 228
A linker snapshot was created at:
^I/tmp/parser.so-2022-08-18-162321.ld-snapshot
ld: Assertion failed: (_file->_atomsArrayCount == computedAtomCount && "more atoms allocated than expected"), function parse, file macho_relocatab
le_file.cpp, line 2061.
collect2: error: ld returned 1 exit status

Any tips?

@vhyrro
Copy link
Member

vhyrro commented Aug 18, 2022

@shaunsingh Hm, that's a very weird error. All I can say is that it's unrelated to our TS parser - something at a lower level (presumably on the tree-sitter side) is messing up, and the assertion error is not giving a lot of detail :/

I know not everyone likes clang, but have you tried it? It could be a gcc oddity for all we know.

@shaunsingh
Copy link

@vhyrro Clang fails altogether with the same error as the first comment above (here: #7 (comment)).

@donbex
Copy link

donbex commented Aug 21, 2022

FWIW, I was able to compile the neorg TS parser under MacOS Monterey version 12.5.1 using gcc 12. Attempting to compile with clang, on the other hand, fails with the same errors as in the original message in this thread.

@ShouyeLiu
Copy link

I get same error

4  0x102a9d360  ___ZN2ld4tool10InputFilesC2ER7Options_block_invoke + 56
5  0x1893941f4  _dispatch_client_callout2 + 20
6  0x1893a7954  _dispatch_apply_invoke + 224
7  0x1893941b4  _dispatch_client_callout + 20
8  0x1893a5a04  _dispatch_root_queue_drain + 680
9  0x1893a6104  _dispatch_worker_thread2 + 164
10  0x189554324  _pthread_wqthread + 228
A linker snapshot was created at:
	/tmp/smr_dense_SL-2022-09-14-185324.ld-snapshot
ld: Assertion failed: (_file->_atomsArrayCount == computedAtomCount && "more atoms allocated than expected"), function parse, file macho_relocatable_file.cpp, line 2061.
collect2: error: ld returned 1 exit status
make: *** [smr_dense_SL] Error 1

@jaidetree
Copy link

jaidetree commented Sep 16, 2022

Also getting an error:

9 warnings and 20 errors generated.
Parser compilation failed.
Stdout:
Stderr: /Users/j/projects/tree-sitter-norg/src/scanner.cc:162:35: error: expected expression
  return std::vector<TokenType>({lhs, static_cast<TokenType>(rhs)});
                                ^
/Users/j/projects/tree-sitter-norg/src/scanner.cc:165:23: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
std::vector<TokenType>&& operator|(std::vector<TokenType>&& lhs, TokenType rhs)
                    ^
/Users/j/projects/tree-sitter-norg/src/scanner.cc:165:58: warning: rvalue references are a C++11 extension [-Wc++11-extensions]
std::vector<TokenType>&& operator|(std::vector<TokenType>&& lhs, TokenType rhs)
                                                       ^
/Users/j/projects/tree-sitter-norg/src/scanner.cc:177:10: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
  for (auto& elem : vec)
       ^
/Users/j/projects/tree-sitter-norg/src/scanner.cc:177:21: warning: range-based for loop is a C++11 extension [-Wc++11-extensions]
  for (auto& elem : vec)
                  ^
/Users/j/projects/tree-sitter-norg/src/scanner.cc:542:28: error: expected ';' at end of declaration list
  size_t& get_tag_level() noexcept { return m_TagLevel; }
                         ^
                         ;
/Users/j/projects/tree-sitter-norg/src/scanner.cc:919:23: warning: default member initializer for non-static data member is a C++11 extension [-Wc++11-extensions]
  size_t m_TagLevel = 0;
                    ^
/Users/j/projects/tree-sitter-norg/src/scanner.cc:923:27: warning: default member initializer for non-static data member is a C++11 extension [-Wc++11-extensions]
  TokenType m_LastToken = NONE;
                        ^
/Users/j/projects/tree-sitter-norg/src/scanner.cc:926:26: warning: default member initializer for non-static data member is a C++11 extension [-Wc++11-extensions]
  size_t m_ParsedChars = 0;
                       ^
/Users/j/projects/tree-sitter-norg/src/scanner.cc:929:54: warning: default member initializer for non-static data member is a C++11 extension [-Wc++11-extensions]
  const std::array<int32_t, 9> m_DetachedModifiers = {'*', '-', '>', '|', '=',
                                                   ^
/Users/j/projects/tree-sitter-norg/src/scanner.cc:931:70: warning: default member initializer for non-static data member is a C++11 extension [-Wc++11-extensions]
  const std::unordered_map<int32_t, TokenType> m_AttachedModifiers = {
                                                                   ^
/Users/j/projects/tree-sitter-norg/src/scanner.cc:931:72: error: non-aggregate type 'const std::unordered_map<int32_t, TokenType>' (aka 'const unordered_map<int, TokenType>') cannot be initialized with an initializer list
  const std::unordered_map<int32_t, TokenType> m_AttachedModifiers = {
                                                                     ^
/Users/j/projects/tree-sitter-norg/src/scanner.cc:201:13: error: use of undeclared identifier 'advance'
          advance(lexer);
          ^
/Users/j/projects/tree-sitter-norg/src/scanner.cc:209:13: error: use of undeclared identifier 'advance'
          advance(lexer);
          ^
/Users/j/projects/tree-sitter-norg/src/scanner.cc:210:20: error: use of undeclared identifier 'parse_text'
          return parse_text(lexer);
                 ^
/Users/j/projects/tree-sitter-norg/src/scanner.cc:214:13: error: use of undeclared identifier 'advance'
          advance(lexer);
          ^
/Users/j/projects/tree-sitter-norg/src/scanner.cc:223:17: error: use of undeclared identifier 'advance'
              advance(lexer);
              ^
/Users/j/projects/tree-sitter-norg/src/scanner.cc:236:17: error: use of undeclared identifier 'skip'
              skip(lexer);
              ^
/Users/j/projects/tree-sitter-norg/src/scanner.cc:241:17: error: use of undeclared identifier 'advance'
              advance(lexer);
              ^
/Users/j/projects/tree-sitter-norg/src/scanner.cc:251:21: error: use of undeclared identifier 'advance'
                  advance(lexer);
                  ^
/Users/j/projects/tree-sitter-norg/src/scanner.cc:254:25: error: use of undeclared identifier 'advance'
                      advance(lexer);
                      ^
/Users/j/projects/tree-sitter-norg/src/scanner.cc:257:29: error: use of undeclared identifier 'advance'
                          advance(lexer);
                          ^
/Users/j/projects/tree-sitter-norg/src/scanner.cc:262:37: error: use of undeclared identifier 'advance'
                                  advance(lexer);
                                  ^
/Users/j/projects/tree-sitter-norg/src/scanner.cc:294:17: error: use of undeclared identifier 'advance'
              advance(lexer);
              ^
/Users/j/projects/tree-sitter-norg/src/scanner.cc:300:24: error: use of undeclared identifier 'parse_text'
              return parse_text(lexer);
                     ^
/Users/j/projects/tree-sitter-norg/src/scanner.cc:312:32: error: expected expression
                             {'*'}) != NONE)
                             ^
/Users/j/projects/tree-sitter-norg/src/scanner.cc:316:92: error: expected expression
          if (check_detached(lexer, QUOTE1 | QUOTE2 | QUOTE3 | QUOTE4 | QUOTE5 | QUOTE6, {'>'}) !=
                                                                                         ^
/Users/j/projects/tree-sitter-norg/src/scanner.cc:328:32: error: expected expression
                             {'-'},
                             ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
9 warnings and 20 errors generated.

Also reported on nvim-neorg/neorg#580

@jaidetree
Copy link

jaidetree commented Sep 19, 2022

Wrestled with this a lot these past few days. Turns out to be largely bad timing.

I upgraded to the latest XCode 14 and its set of command line tools, but there's something off that breaks other build tools.

The trick was signing up for a free apple dev account, and installing Command Line tools 13.4 from the following:

https://developer.apple.com/download/all/?q=Command%20LIne%20Tools%2013

Then run this command to switch CLI Tools versions

sudo xcode-select --switch /Library/Developer/CommandLineTools

Then run the following to get the version. Make sure it's 13.4.

pkgutil --pkg-info=com.apple.pkg.CLTools_Executables

Additionally if you're using a GUI like Neovide you will likely need to edit your ~/.zprofile file to set the CC env var, as that is still needed to point to gcc-12.

After that :Neorg sync-parsers worked from a norg file.

Full credit to Magic105 for figuring that out in https://stackoverflow.com/a/73765819/5614103

@shaunsingh
Copy link

Thanks for the fix! my macOS gives an error that 13.4 is to old a version for macOS 13, probably explains why macOS 13 gives an error as well but it works on 12

@halfdan
Copy link

halfdan commented Sep 26, 2022

It's unclear to me why the compilation errors can't be fixed when compiling with clang.

@JoeyGrajciar
Copy link
Collaborator

If you mean Apple Clang, then you have to explicitly tell it C++ version. It defaults to pre C++11 version.

@nc7s
Copy link

nc7s commented Oct 13, 2022

FYI with clang 15 & 14 installed through MacPorts it went through fine.

@diktomat
Copy link

MacOS 12.4, had to downgrade to CLT 13.4 and use GCC, so still an issue with Apple-supplied Clang

@edwardsmit
Copy link

edwardsmit commented Oct 26, 2022

MacOS 12.6
Installed the Command Line Tools 14.1 RC-2 via https://developer.apple.com/download/all/?q=Command%20LIne%20Tools%2014.1 and GCC via brew install gcc

CC=gcc-12 nvim -c "TSInstall norg"

Update: typo fixed (thanks @kas227) , and see next comment of @kas227 for a possibly needed extra step.

@kas227
Copy link

kas227 commented Oct 30, 2022

Tyvm @edwardsmit
This almost made it work for me. The only part that was missing after installing the tools was to also switch, ie.
sudo xcode-select --switch /Library/Developer/CommandLineTools

Also minor typo in you prompt CC=gcc-12 nvim -c "TSInstall norg" (nog instead of norg)

@Joe-Withey
Copy link

For those on macOS (personally I am on 13.3.1)

The full steps I used to get this working were:

brew install gcc
xcode-select --install
sudo xcode-select --switch /Library/Developer/CommandLineTools
CC=gcc-12 nvim -c "TSInstall norg"

@ghost
Copy link

ghost commented May 2, 2023

For those on macOS (personally I am on 13.3.1)

The full steps I used to get this working were:

brew install gcc
xcode-select --install
sudo xcode-select --switch /Library/Developer/CommandLineTools
CC=gcc-12 nvim -c "TSInstall norg"

Can someone explain to me why this worked?

@hacker-DOM
Copy link

Fwiw, the guides here worked for me, but brew install gcc now installs gcc==13, so I had to change all gcc-12 to gcc-13.

@g-battaglia-h-farm
Copy link

This worked for me:

brew install gcc@12
CC="/opt/homebrew/bin/gcc-12" nvim
CC="/opt/homebrew/bin/gcc-12" nvim -c "TSInstallSync norg"

@khazixi
Copy link

khazixi commented May 8, 2023

I think the issue comes from two places:

  1. For some odd reason Apple Clang seems to default to C++98 as its compilation target which breaks the build script for compiling the parser itself.

(scanner.cc compiles with clang++ -std=c++11 on Mac)

  1. The C++ in which scanner.cc was written in seems to use a lot of C++11 features compared to other tree sitter parsers which breaks this specific parser where other ones are fine

The closest thing to a fix without needing to install another dependency that I have found is to run:

CC="/usr/bin/clang++ -std=c++17" nvim -c "TSInstallSync norg"

@aldanor
Copy link

aldanor commented May 10, 2023

The closest thing to a fix without needing to install another dependency that I have found is to run:

CC="/usr/bin/clang++ -std=c++17" nvim -c "TSInstallSync norg"

This will not work, because when scanning for compilers from CC env var, treesitter installer will call shell.select_executable(compilers) which, in its turn, will call vim.fn.executable() on each entry.

  • vim.fn.executable('clang++') = 1
  • vim.fn.executable('clang++ -std=c++17') = 0

@aldanor
Copy link

aldanor commented May 10, 2023

This seems to work:

  • without having to brew install gcc
  • without setting CC
  • without having to run anything from shell
local shell = require 'nvim-treesitter.shell_command_selectors'
local install = require 'nvim-treesitter.install'

-- save the original functions
local select_executable = shell.select_executable
local compilers = install.compilers

-- temporarily patch treesitter install logic
local cc = 'clang++ -std=c++11'
function shell.select_executable(executables)
  return vim.tbl_filter(function(c) ---@param c string
    return c ~= vim.NIL and (vim.fn.executable(c) == 1 or c == cc)
  end, executables)[1]
end
install.compilers = { cc }

-- install norg parsers
install.commands.TSInstallSync['run!'] 'norg' -- or vim.cmd [[ :TSInstallSync! norg ]]

-- restore the defaults back
shell.select_executable = select_executable
install.compilers = compilers

This should be good enough to be placed e.g. in build() function in lazy.

It's way too complicated though and 100% of macOS users will hit this, so maybe it should be handled by Neorg itself?

@vhyrro What do you think? (it's a bit brittle but still better than the build crashing for everyone on the mac)

@Brinkling96
Copy link

Brinkling96 commented Jun 26, 2023

All,
Installing gcc-12 wasn't enough for me.

This comment worked:
#7 (comment)

However, there are some gaps in that comment that caused me to stumble into issues. He is my attempt at a guide.

  1. Install Command Line tools (CLT) 13.4 from the following (apple account needed): https://developer.apple.com/download/all/?q=Command%20LIne%20Tools%2013
  2. Ensure xcode is installed: xcode-select --install
  3. Ensure gcc-12 is installed: brew install gcc@12; which gcc-12
  4. Switch to CLT 13.4: sudo xcode-select --switch /Library/Developer/CommandLineTools
  5. Ensure CLT 13.4 is active: pkgutil --pkg-info=com.apple.pkg.CLTools_Executables
  6. export CC path: export CC=$(which gcc-12)
  7. Open a norg file: nvim tmp.norg
  8. Execute parser sync install: :Neorg sync-parsers
  9. Profit

@shaunsingh
Copy link

I found that just setting the use_makefile option to true under the norg ts parser config did the trick

@aldanor
Copy link

aldanor commented Jun 26, 2023

You should no longer need to install gcc-12 or set CC paths etc: nvim-neorg/neorg#891

@molleweide
Copy link

I found that just setting the use_makefile option to true under the norg ts parser config did the trick

hey man, do you mean literally inside the norg parser repo or how did you do this?

@leviouwendijk
Copy link

leviouwendijk commented Oct 29, 2024

Best solution I found so far noted here.

Basically, you use llvm to compile the parser and don't need to change anything back thereafter. It subverts the need to downgrade Command Line Tools, or anything more laborious.

  1. Install llvm
brew install llvm
  1. Call it specifically to compile the .norg parser:
CC=/opt/homebrew/opt/llvm/bin/clang nvim -c 'TSInstallSync norg'

That should be it. No more errors, because your parser has been compiled!

Not sure about running subsequent TS updates though, but maybe keep llvm around for a while, until the issue is resolved. I think the C++11 extension dependencies need to be written out of the source code for this issue to go away.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests