1

I'm trying to compile the typescript, tsx, and python parsers for use with neovim, but when I run gcc -o parser.so -shared src/parser.c -Os -I./src as instructed by the tree-sitter tracking issue I get:

Undefined symbols for architecture x86_64:
  "_tree_sitter_tsx_external_scanner_create", referenced from:
      _tree_sitter_tsx.language in parser-eb4e9b.o
  "_tree_sitter_tsx_external_scanner_deserialize", referenced from:
      _tree_sitter_tsx.language in parser-eb4e9b.o
  "_tree_sitter_tsx_external_scanner_destroy", referenced from:
      _tree_sitter_tsx.language in parser-eb4e9b.o
  "_tree_sitter_tsx_external_scanner_scan", referenced from:
      _tree_sitter_tsx.language in parser-eb4e9b.o
  "_tree_sitter_tsx_external_scanner_serialize", referenced from:
      _tree_sitter_tsx.language in parser-eb4e9b.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I've run the npm build steps, and tried the make file in build, but I'm not able to get the final .so files.

saltdotac
  • 111
  • 1
  • 3
  • this is strange, I just get the GIT project, then go under *tsx* and I do not have problem doing `gcc -o parser.so -shared src/parser.c -Os -I./src` (the missing definitions are in *scanner.c*) – bruno May 18 '20 at 16:30
  • 1
    sorry to say but are you sure that command produces the error ? Is it not later when you link with *parser.so* ? – bruno May 18 '20 at 16:36
  • @bruno I'm sure that's the error I get when I run the above. I'm not splitting the compile steps, since I'm specifying the .so file, so there shouldn't be another step, no? – saltdotac May 19 '20 at 09:35
  • For me you have the error when you try to make an executable linking with at least *parser.so* but without *scanner.so* (supposing this is the name for that lib) or *scanner.o* (if no lib usage for it) – bruno May 19 '20 at 09:40
  • 2
    @bruno I needed to include src/scanner.c in the call, i.e. `gcc -o parser.so -shared src/parser.c src/scanner.c -Os -I./src`. Gotta read the fine print. Thanks for your help! – saltdotac May 19 '20 at 10:23

2 Answers2

2

the error undefined symbol: tree_sitter_parsername_external_scanner_create also appears, when there is a mismatch between parser name and function names

  // grammar.js
  name: 'parsername',
// scanner.cc
void *tree_sitter_oldparsername_external_scanner_create() {
  return new Scanner();
}

quickfix: replace name in scanner source

sed -i -E 's|(tree_sitter)_oldparsername_|\1_parsername_|g' src/scanner.* 
milahu
  • 2,447
  • 1
  • 18
  • 25
1

Some grammars have external scanners - hand written C/C++ source files that are by convention called scanner.c or scanner.cc, which need to be compiled along with parser.c.

maxbrunsfeld
  • 341
  • 2
  • 2