I'm trying to write a module using tree-sitter with some custom grammars. Here's a minimal example that works outside of Godot:
/* main.cpp */
#include <tree_sitter/api.h>
int main() {
TSParser* p = ts_parser_new();
return 0;
}
# SConstruct
env = Environment()
env.Append(LIBPATH="/home/teehee/git/tree-sitter")
env.Append(LIBS="tree-sitter")
env.Program("out", "main.cpp")
For the test in Godot, I made a trivial module and pasted in the above code:
/* printer_of_2s.cpp */
#include "printer_of_2s.h"
#include <tree_sitter/api.h>
int tt_fn() {
TSParser* p = ts_parser_new();
return 0;
}
void PrinterOf2s::print_two() {
print_line(two);
}
void PrinterOf2s::_bind_methods() {
ClassDB::bind_method(D_METHOD("print_two"), &PrinterOf2s::print_two);
}
PrinterOf2s::PrinterOf2s() {
two = 2;
}
# SCsub
Import('env')
menv = env.Clone()
menv.add_source_files(env.modules_sources, "*.cpp")
menv.Append(CPPPATH="/home/teehee/git/tree-sitter/lib/include")
env.Append(LIBPATH="/home/teehee/git/tree-sitter")
env.Append(LIBS="tree-sitter")
After compiling with scons p=windows custom_modules=~/godot/modules/ -j 3
(I'm using WSL), I get a linker error:
/usr/bin/x86_64-w64-mingw32-ld: modules/libmodule_simple.windows.editor.x86_64.a(printer_of_2s.windows.editor.x86_64.o):printer_of_2s.:(.text+0x125): undefined reference to `ts_parser_new'
I know that the function is defined, because otherwise the first program wouldn't compile. I also know that scons can find the library, because that would give me a different error. I'm not sure what I could be doing differently.