So I am trying to use flex in a project with Clion (because I'm on windows), which uses CMake but I cannot compile because my lexer.l file includes token.h my CMakeLists.txt:
cmake_minimum_required(VERSION 3.10)
find_package(FLEX)
FLEX_TARGET(MyScanner lexer.l ${CMAKE_CURRENT_BINARY_DIR}/lex.yy.c)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
add_executable(lexer token.h ${FLEX_MyScanner_OUTPUTS}
printtoken.c lexan.h lexanl.c )
ERROR:
[ 16%] Building C object CMakeFiles/lexer.dir/lex.yy.c.o
lexan.l:36:10: fatal error: token.h: No such file or directory
compilation terminated.
CMakeFiles/lexer.dir/build.make:74: recipe for target 'CMakeFiles/lexer.dir/lex.yy.c.o' failed
How do I include the token.h?
Problem Solved:
I had to add ${CMAKE_SOURCE_DIR}
to the include_directories()
call for it to find the header file.