0

When using this CMakeLists.txt

cmake_minimum_required(VERSION 3.17)
project(project_c)

set(CMAKE_CXX_STANDARD 11)

set(project_name project_c)

find_package(BISON)
find_package(FLEX)

BISON_TARGET(parser parser.y ${CMAKE_SOURCE_DIR}/parser.cpp)
FLEX_TARGET(lexer lexer.l ${CMAKE_SOURCE_DIR}/lexer.cpp)
ADD_FLEX_BISON_DEPENDENCY(lexer parser)

add_executable(${project_name} ${BISON_parser_OUTPUTS} ${FLEX_lexer_OUTPUTS})

target_include_directories(${project_name} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}")
target_link_libraries(${project_name} ${FLEX_LIBRARIES})

CMake complains about

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 files:
FL_LIBRARY (ADVANCED)
    linked by target "project_c" in directory D:/asant/workspace/CLionProjects/project_c

I've tried to copy the winflex folder inside the project folder but that won't help anyway. This proposed solution isn't working.

This is the complete CMake log

"C:\Program Files\JetBrains\CLion 2018.3.4\bin\cmake\win\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - MinGW Makefiles" D:\asant\workspace\CLionProjects\project_c
-- The C compiler identification is GNU 8.1.0
-- The CXX compiler identification is GNU 8.1.0
-- Check for working C compiler: C:/Qt/Tools/mingw810_64/bin/gcc.exe
-- Check for working C compiler: C:/Qt/Tools/mingw810_64/bin/gcc.exe - works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: C:/Qt/Tools/mingw810_64/bin/g++.exe
-- Check for working CXX compiler: C:/Qt/Tools/mingw810_64/bin/g++.exe - works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found BISON: C:/Program Files (x86)/win_flex_bison-2.5.23/win_bison.exe (found version "3.7.1") 
-- Found FLEX: C:/Program Files (x86)/win_flex_bison-2.5.23/win_flex.exe (found version "2.6.4") 
-- Configuring done
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 files:
FL_LIBRARY (ADVANCED)
    linked by target "project_c" in directory D:/asant/workspace/CLionProjects/project_c

-- Generating done
CMake Generate step failed.  Build files cannot be regenerated correctly.

[Failed to reload]
Antonio Santoro
  • 827
  • 1
  • 11
  • 29
  • ***winflex folder inside the project folder but that won't help anyway*** It won't look there by default so its not going to help. – drescherjm Dec 04 '20 at 18:18
  • Usually you need to do what the error says. There is usually a more verbose message above the part you quoted. – drescherjm Dec 04 '20 at 18:19
  • @drescherjm I edited the question with the complete CMake log – Antonio Santoro Dec 04 '20 at 18:31
  • You may have to look at the source code for the finder. – drescherjm Dec 04 '20 at 18:38
  • what source code? – Antonio Santoro Dec 04 '20 at 18:40
  • For me its: `C:\Program Files\CMake\share\cmake-3.17\Modules`. With that said it looks like you have CMake in a different location then the default. It will probably be somewhere in here: C:\Program Files\JetBrains\CLion 2018.3.4\bin\cmake\win\ – drescherjm Dec 04 '20 at 18:42
  • Inside `C:\Program Files\JetBrains\CLion 2018.3.4\bin\cmake\win\share\cmake-3.17\Modules` there are no files referring to anything as "flex" – Antonio Santoro Dec 04 '20 at 18:44
  • I am talking about `FindFLEX.cmake` on my Win10 PC using CMake 3.17.5 the path is: `C:\Program Files\CMake\share\cmake-3.17\Modules\FindFLEX.cmake` – drescherjm Dec 04 '20 at 18:44
  • I have no such file – Antonio Santoro Dec 04 '20 at 18:46
  • Usually, `find_package` is used with REQUIRED keyword. That way, if the package isn't found, CMake emits the error **immediately** and doesn't process the rest of `CMakeLists.txt`. Situations when REQUIRED keyword could be omited are those, when your project can work without the package and checks `XXX_FOUND` variable for determine, whether the package is found. This is not your case, so add `REQUIRED` to both your `find_package` calls. The error message "The following variables are used in this project, but they are set to NOTFOUND." **always** signals about the **bad** `CMakeLists.txt`. – Tsyvarev Dec 04 '20 at 22:06
  • @Tsyvarev put `REQUIRED` in both `find_package`s and still getting the same message – Antonio Santoro Dec 04 '20 at 22:11
  • Hm, true: script [FindFLEX.cmake](https://github.com/Kitware/CMake/blob/master/Modules/FindFLEX.cmake#L264) checks success only in finding Flex executable (`FLEX_EXECUTABLE`) but doesn't check existence of libraries (`FLEX_LIBRARIES`). So this is a problem with `FindFLEX.cmake` script, not with your `CMakeLists.txt`. – Tsyvarev Dec 04 '20 at 23:10
  • In any case, `FL_LIBRARY` contains the path to the library named `fl`. If you have this library installed in unusual location, you may pass directory with that library via `CMAKE_LIBRARY_PATH` variable. E.g. with parameter `-DCMAKE_LIBRARY_PATH=` when call `cmake`. If this doesn't help, then we need more information about your flex installation. E.g. what is extension of `fl` library? (Or, better, which is exact path, consisting directory, filename and extension). – Tsyvarev Dec 04 '20 at 23:13
  • The only thing I did was to download [this](https://github.com/lexxmark/winflexbison) flex/bison build for windows, put the extracted folder in C: and then add the path to the PATH environment variable – Antonio Santoro Dec 04 '20 at 23:21
  • @Tsyvarev I downloaded the `libfl.lib` file from [here](https://github.com/ty733420/windows-utils/blob/master/libfl.lib) and I added your suggested option but it outputs the same error message – Antonio Santoro Dec 05 '20 at 02:09
  • According to [that answer](https://stackoverflow.com/a/15853231/3440745), MinGW doesn't work with `.lib` libraries. It knows only `.dll` and `.a` ones. Probably, you need to download `libfl.a` instead of `libfl.lib`. Setting `CMAKE_LIBRARY_PATH` (or other hint for CMake to search the library in unusual location) is still needed. – Tsyvarev Dec 05 '20 at 09:54
  • Same error, I'm building using the -DCMAKE_LIBRARY_PATH option pointing to the `libfl.a` file – Antonio Santoro Dec 05 '20 at 11:25

0 Answers0