因此,我试图在带有Clion的项目中使用flex(因为我在Windows上),该项目使用CMake,但由于我的lexer.l文件包含token.h而无法编译。我的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 )
错误:
[ 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
我如何包含token.h?
我必须在${CMAKE_SOURCE_DIR}
调用中添加include_directories()
才能找到头文件。