From 276ca6ab8ac038054b15cdcfab0cdda2028609ca Mon Sep 17 00:00:00 2001 From: Greg Price Date: Sat, 28 Oct 2017 23:20:16 -0700 Subject: [PATCH 1/3] README: Fix the order of sources/libraries in example compilation commands. Some linkers (among them, the GNU ld 2.28 on my laptop, which clang relies on for linking) are picky about the order they get their ingredients in on the command line. When they are, they want the leaf nodes (like your `main` function) first, and the dependencies (like `libcompiler.a`) after. It's kind of counterintuitive (at least to me) that this is the preferred order, though I can understand it from the perspective of efficient resource use in the era when some linkers were first written. Anyway, it's the way it is. There's a detailed explanation here: https://stackoverflow.com/a/409470/378130 So, adjust the examples in the README to an order that should work everywhere. This fixes part of #102. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 70716e79..30dc1fe3 100644 --- a/README.md +++ b/README.md @@ -137,8 +137,8 @@ To create the parser, compile this file like this: clang++ -std=c++11 \ -I tree-sitter/include \ -L tree-sitter/out/Release \ - -l compiler \ arithmetic_grammar.cc \ + -l compiler \ -o arithmetic_grammar ``` @@ -209,8 +209,8 @@ To demo this parser's capabilities, compile this program like this: clang \ -I tree-sitter/include \ -L tree-sitter/out/Debug \ + test_parser.c arithmetic_parser.c \ -l runtime \ - arithmetic_parser.c test_parser.c \ -o test_parser ./test_parser From 6bfe95fc955c97b9efdc3ae1c2f6a89afcd265f0 Mon Sep 17 00:00:00 2001 From: Greg Price Date: Sat, 28 Oct 2017 23:28:18 -0700 Subject: [PATCH 2/3] README: Consistently use Release in examples. Following the instructions in the README from the top, I don't get a `Debug` build directory, only `Release`. So, stick to that. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 30dc1fe3..603a1dc7 100644 --- a/README.md +++ b/README.md @@ -208,7 +208,7 @@ To demo this parser's capabilities, compile this program like this: ```sh clang \ -I tree-sitter/include \ - -L tree-sitter/out/Debug \ + -L tree-sitter/out/Release \ test_parser.c arithmetic_parser.c \ -l runtime \ -o test_parser From 704b8ad8108716e2c464015e9168678515b4e62c Mon Sep 17 00:00:00 2001 From: Greg Price Date: Sat, 28 Oct 2017 23:31:54 -0700 Subject: [PATCH 3/3] README: Make the examples work despite variation in out/*/ structure. Fixes #102. While on macOS the `libcompiler.a` and `libruntime.a` files apparently get output directly into `out/Release/` by the build, on Linux they seem to go into a subdirectory `out/Release/obj.target/`. This causes someone who tries to follow the instructions to get an error like ``` /usr/bin/ld: cannot find -lcompiler clang: error: linker command failed with exit code 1 (use -v to see invocation) ``` That looks like the setup is broken somehow, and for someone who hasn't spent much time fixing up Unix linker errors, it doesn't give a lot of clues as to how to fix it. Instead, have the recommended command find the actual library file directly, and pass that to the linker. (Alternatively we could have passed the containing directory to `-L`; this is a little shorter, and of course neither version is what you'd want in an industrial-strength build recipe.) This isn't the world's most elegant solution, obviously -- it'd be better (at least as far as this part is concerned) to have the layout be the same on different platforms. But doing that sounds likely to require significant messing around with build scripts, so this at least makes the instructions work reliably. --- README.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 603a1dc7..cb184c20 100644 --- a/README.md +++ b/README.md @@ -136,9 +136,8 @@ To create the parser, compile this file like this: ```sh clang++ -std=c++11 \ -I tree-sitter/include \ - -L tree-sitter/out/Release \ arithmetic_grammar.cc \ - -l compiler \ + "$(find tree-sitter/out/Release -name libcompiler.a)" \ -o arithmetic_grammar ``` @@ -208,9 +207,8 @@ To demo this parser's capabilities, compile this program like this: ```sh clang \ -I tree-sitter/include \ - -L tree-sitter/out/Release \ test_parser.c arithmetic_parser.c \ - -l runtime \ + "$(find tree-sitter/out/Release -name libruntime.a)" \ -o test_parser ./test_parser