我正在尝试在项目上使用flex,我正在尝试使用CMake将flex链接到我的项目。我在网上找到了一个FindFLEX.cmake,我正在使用它。你可以找到它here。这应该是默认的CMake,但我不认为是。我的目录结构如下
root
---src
---CMakeLists.txt
---cmake
---Modules
---FindFLEX.cmake
---build
---external
---flex - Where flex is installed
---bin
---flex.exe
---lib
---libfl.a
我的src / CMakeLists.txt如下
cmake_minimum_required(VERSION 2.8)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
message(${CMAKE_MODULE_PATH})
set( project_name "try_flex" )
message(${project_name})
project(${project_name})
find_package(FLEX)
FLEX_TARGET(Mylexer tokenize.lex ${CMAKE_CURRENT_BINARY_DIR}/tokenize.cpp)
add_executable(${project_name} ${FLEX_Mylexer_OUTPUTS})
target_link_libraries(${project_name} ${FLEX_LIBRARIES})
FLEX_TARGET应该由FindFLEX.cmake在找到Flex包时提供。在build /目录中运行以下命令没有找到flex包
build> cmake ..\src
然后我添加了前缀,部分工作
build> cmake -DCMAKE_PREFIX_PATH=c:\root\external\flex\ ..\src
找到了可执行文件flex.exe,但没有找到库。 FindFLEX.cmake的相关部分如下所示
FIND_PROGRAM(FLEX_EXECUTABLE flex DOC "path to the flex executable")
message("DEBUG:"${FLEX_EXECUTABLE})
MARK_AS_ADVANCED(FLEX_EXECUTABLE)
FIND_LIBRARY(FL_LIBRARY NAMES fl DOC "path to the fl library")
message("DEBUG:FL_LIBRARY"${FL_LIBRARY})
MARK_AS_ADVANCED(FL_LIBRARY)
SET(FLEX_LIBRARIES ${FL_LIBRARY})
我在运行cmake时收到的消息是
DEBUG:c:/root/external/flex/bin/flex.exe
DEBUG:FL_LIBRARYFL_LIBRARY-NOTFOUND
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake file s:FL_LIBRARY (ADVANCED)
linked by target "try_flex" in directory C:/root/src
-- Configuring incomplete, errors occurred!
在包含前缀路径之后,有人能告诉我为什么我找到flex二进制文件而不是库吗?任何帮助将不胜感激。
由于
答案 0 :(得分:3)
我弄清楚问题是什么。在Windows上,cmake正在寻找libfl.lib。但是Flex的Windows安装只提供了libfl.a所以我需要将这两行添加到我的cmake
LIST(APPEND CMAKE_FIND_LIBRARY_SUFFIXES ".a")
FIND_LIBRARY(FL_LIBRARY NAMES libfl fl DOC "path to the fl library")
第一行是.a搜索库的后缀列表,第二行是查找libfl。这工作