让CMake在Windows上找到flex

前端之家收集整理的这篇文章主要介绍了让CMake在Windows上找到flex前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试在项目上使用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二进制文件而不是库?任何帮助,将不胜感激.

谢谢

我弄清楚问题是什么.在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.那很有效

原文链接:https://www.f2er.com/windows/441240.html

猜你在找的Windows相关文章