My source code
#include <tree_sitter/api.h>
int main() {
TSParser *parser = ts_parser_new();
}
I compile it with the following gcc command
gcc \
-I ~/source_repos/tree-sitter/lib/include \
test-json-parser.c \
~/source_repos/tree-sitter-json/src/parser.c \
~/source_repos/tree-sitter/libtree-sitter.a \
-o test-json-parser
This works fine. But if I do the following in CMake
cmake_minimum_required(VERSION 3.17)
project(tmp_tree_sitter C)
set(CMAKE_C_STANDARD 11)
include_directories(/home/rip/source_repos/tree-sitter/lib/include)
add_executable(tmp_tree_sitter
main.c
/home/rip/source_repos/tree-sitter/libtree-sitter.a
/home/rip/source_repos/tree-sitter-json/src/parser.c
)
The following error message raises
Scanning dependencies of target tmp_tree_sitter
[ 33%] Building C object CMakeFiles/tmp_tree_sitter.dir/main.c.o
[ 66%] Linking C executable tmp_tree_sitter
/usr/bin/ld: CMakeFiles/tmp_tree_sitter.dir/main.c.o: in function `main':
/home/rip/CLionProjects/tmp_tree-sitter/main.c:12: undefined reference to `ts_parser_new'
The only difference is, I have different directories, so in one the source file is named test-json-parser.c
and in the other main.c
. So how can I do the same in CMake
, as I did with gcc
?