# Why in my project bison file (parser.yy)can't include normal header?

**URL:** https://discourse.cmake.org/t/why-in-my-project-bison-file-parser-yy-cant-include-normal-header/1455
**Category:** Development
**Created:** [June 28, 2020, 1:41pm UTC](https://discourse.cmake.org/t/why-in-my-project-bison-file-parser-yy-cant-include-normal-header/1455 "2020-06-28T13:41:40Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![cookieli](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/c/87869e/32.png) [@cookieli](https://discourse.cmake.org/u/cookieli)
#### Post date: [June 28, 2020, 1:41pm UTC](https://discourse.cmake.org/t/why-in-my-project-bison-file-parser-yy-cant-include-normal-header/1455/1 "2020-06-28T13:41:40Z")

</div>

Here is the error:

```auto
/home/lzx/mitscript/parser.yy:29:10: fatal error: AST.h: No such file or directory
 #include "AST.h"
          ^ ~~~~~~
compilation terminated.

```

And here is my cmake:

```auto
cmake_minimum_required(VERSION 3.16)
project(mitscript)

set(CMAKE_CXX_STANDARD 17)
find_package(BISON)
find_package(FLEX)

bison_target(Parser parser.yy ${CMAKE_CURRENT_SOURCE_DIR}/parser.cpp
        DEFINES_FILE ${CMAKE_CURRENT_SOURCE_DIR}/parser.h)
flex_target(Scanner lexer.lex ${CMAKE_CURRENT_BINARY_DIR}/lexer.cpp
        DEFINES_FILE ${CMAKE_CURRENT_SOURCE_DIR}/lexer.h)

add_flex_bison_dependency(Scanner Parser)

add_executable(mitscript main.cpp ${FLEX_Scanner_OUTPUTS} ${BISON_Parser_OUTPUTS} AST.h Visitor.h PrettyPrinter.h)

```

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [June 28, 2020, 9:37pm UTC](https://discourse.cmake.org/t/why-in-my-project-bison-file-parser-yy-cant-include-normal-header/1455/2 "2020-06-28T21:37:13Z")

</div>

First up, all the references to `CMAKE_CURRENT_SOURCE_DIR` should really be `CMAKE_CURRENT_BINARY_DIR`. You should not generate files into the source directory, only the build directory.

Take a look at the example at the end of the [FindFLEX module](https://cmake.org/cmake/help/latest/module/FindFLEX.html) page. Apart from the source/binary dir problem mentioned above, there are a couple of lines your project is missing (I’ve modified the include part to use target-based includes rather than the old-style `include_directories()`)

```cmake
target_include_directories(mitscript PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
target_link_libraries(mitscript ${FLEX_LIBRARIES})

```

I suspect fixing the combination of the above will make things work for you.
