如何使用带有Flex和Bison的Clion构建C ++ CMake项目

问题描述

我正在尝试构建一个我克隆的git项目,该项目使用CMake进行编译,并且需要bison和flex。 我正在使用Windows 10和Clion IDE。

我已经从https://sourceforge.net/projects/winflexbison/下载Win flex-bison 但是我不明白如何指向CMake来查看我下载的win_flex_bison文件

当前构建失败的行:

find_program(BISON_EXECUTABLE bison)

if(NOT EXISTS ${BISON_EXECUTABLE})
    message("Could not find bison executable.")
endif(NOT EXISTS ${BISON_EXECUTABLE})


find_program(FLEX_EXECUTABLE flex)

if(NOT EXISTS ${FLEX_EXECUTABLE})
        message("Could not find flex executable.")
endif(NOT EXISTS ${FLEX_EXECUTABLE})

IF (DEFINED FLEXLEXER_H_DIR)
  include_directories(${FLEXLEXER_H_DIR})
  message("Looking in ${CMAKE_required_INCLUDES} for FlexLexer.h")
ELSE()

CHECK_INCLUDE_FILE_CXX("FlexLexer.h" HAVE_FLEXLEXER_H)
IF(NOT HAVE_FLEXLEXER_H)
  UNSET(HAVE_FLEXLER_H CACHE)
  message( FATAL_ERROR "Cannot find FlexLexer.h.  Set FLEXLEXER_H_DIR to point to where it is to be found.." )
ENDIF()

我得到的按摩是:

Could not find bison executable.
Could not find flex executable.
-- Looking for C++ include FlexLexer.h
-- Looking for C++ include FlexLexer.h - not found
CMake Error at VALfiles/parsing/CMakeLists.txt:28 (message):
  Cannot find FlexLexer.h.  Set FLEXLEXER_H_DIR to point to where it is to be
  found..

-- Configuring incomplete,errors occurred!

解决方法

您应该使用以下命令在CMake中查找FLEX和BISON:

V1 <- c( "M","A","T","N","S","I","V","L")
V2 <- c( 1.2,-0.15,-0.8,0.5,1.175,3.1,4.25,2.25,0.25,-1.675)
df <- data.frame(V1,V2)

有关FLEXBISON的更多信息为您提供了所有您需要了解的信息。