Could NOT find FLTK (missing: FLTK_INCLUDE_DIR) - c++

I'm trying to use fltk library in my project but I have some troubles.
Here is my CMakeLists.txt file:
cmake_minimum_required(VERSION 3.12)
project(pp)
set(CMAKE_CXX_STANDARD 14)
add_executable(pp main.cpp)
FIND_PACKAGE(FLTK REQUIRED)
FIND_PACKAGE(GTK REQUIRED)
TARGET_LINK_LIBRARIES(pp ${FLTK_LIBRARIES})
TARGET_LINK_LIBRARIES(pp ${GTK_LIBRARIES})
FLTK version: 1.3.4
Cmake version: 3.7.2
I have installed fltk library in my /usr/local dirs
Include files are located in /usr/local/include/FL
I saw that the FindFLTK.cmake looks for following files:
FL/Fl.h or FL/Fl.H which the FL/Fl.h is located in /usr/local/include/FL so it can be found.
Here is the error message:
Could NOT find FLTK (missing: FLTK_INCLUDE_DIR)
Have you any ideas to solve this problem?
UPDATE
Current version of CMakeLists.txt
cmake_minimum_required(VERSION 3.7.2)
project(pp)
set(CMAKE_CXX_STANDARD 14)
add_executable(pp main.cpp)
target_include_directories(pp PRIVATE /usr/local/include/FL)
set (LIBRARIES fltk Xrender Xcursor Xfixes Xext Xft fontconfig Xinerama pthread dl m X11)
message(STATUS mess: ${CMAKE_MODULE_PATH})
target_link_libraries(pp ${LIBRARIES})'
In this configuration I can compile, and link executable, but why configuration with FIND_PACKAGE does not work? Where I should look for a bug?

Probably bad installation of library. I just installed fresh one from GitHub sources with CMake configuring by cmake -G "MinGW Makefiles" . with followed make and make install to install it in compiler library I suppose.
After that errors containing Could NOT find FLTK (missing: FLTK_INCLUDE_DIR) has disappeared in compilation of another project. I suppose, cmake error report is not so strict and clarified, i.e. this error means some exception in FindFLTK.cmake and not exactly about missing FLTK_INCLUDE_DIR.

Related

Add paho mqtt cpp library in CMake project

Following the instructions on their github repo I managed to build and install both libraries
paho-mqtt-c and paho-mqtt-cpp
in a custom directory
C:\mqtt\paho-c
C:\mqtt\paho-cpp
Now I'm trying to add those libraries in my project. My CMakelists.txt is as follows
cmake_minimum_required(VERSION 3.21)
enable_language(CXX)
list(APPEND CMAKE_PREFIX_PATH C:/mqtt/paho-cpp/lib/cmake/PahoMqttCpp)
find_package(PahoMqttCpp REQUIRED)
project(mqtt_test)
add_executable(mqtt_test main.cpp)
However, cmake insists on asking me where to find them.
Could NOT find PahoMqttC (missing: PAHO_MQTT_C_LIBRARIES PAHO_MQTT_C_INCLUDE_DIRS)
Why do I need to tell cmake again where to find C libraries? I think that was the job of find_package to also include those variables because I set it up on building and installation time.
Operating system: Windows 11 x64.
cmake version: 3.22.2
cmake generator: Ninja
C compiler: 11.2.0 (cygwin64)
C++ compiler: 11.2.0 (cygwin64)
EDIT: I manually specified the paths
set(PAHO_MQTT_C_LIBRARIES C:/mqtt/paho-c/lib/libpaho-mqtt3a-static.a)
set(PAHO_MQTT_C_INCLUDE_DIRS C:/mqtt/paho-c/include)
list(APPEND CMAKE_PREFIX_PATH C:/mqtt/paho-cpp/lib/cmake/PahoMqttCpp)
find_package(PahoMqttCpp REQUIRED)
However I'm getting a compilation error:
fatal error: mqtt/async_client.h: No such file or directory
61 | #include "mqtt/async_client.h"
I know how to solve it by manually adding the include paths in my cmakelist but I'm trying to figure out how to use their cmake module properly. find_package doesn't seem to do that.
Or I'm missing something.

Unable to install boost from Cygwin in Windows 10

I'm pretty sure I'm doing something stupid here but when I try to go install boost from Cygwin's installer, I only see the -debug and -build options.
Cygwin Screenshot
I'm using the http://mirrors.sonic.net mirror. I switch to this from the default mirror because I thought that might have been the problem.
I know the package isn't getting installed because when I try to load my CMAKE file in clion, it throws and an error saying "Could NOT find Boost (missing: Boost_INCLUDE_DIR graph)".
Heres my CMakeLists.txt code:
cmake_minimum_required(VERSION 3.15)
project(HW_9)
set(CMAKE_CXX_STANDARD 14)
add_executable(HW_9 main.cpp knuth.txt graph_1.h)
# see https://cmake.org/cmake/help/latest/module/FindBoost.html
find_package(Boost REQUIRED COMPONENTS graph)
include_directories(${Boost_INCLUDE_DIR})
# Note: a target should be already defined using 'add_executable' or 'add_library'
target_link_libraries(HW_9 ${Boost_LIBRARIES})

CMake FindJNI issue on linux

I'm setting up a C++17 project in CLion and i wanted to use java native interface, but here comes the problem. FindJNI.cmake fails with error:
Could NOT find JNI (missing: JAVA_INCLUDE_PATH JAVA_INCLUDE_PATH2)
Ive tried to manually set JAVA_INCLUDE_PATH in my CMakeLists.txt using:
set(JAVA_INCLUDE_PATH "$ENV{JAVA_HOME}/include") (and the same with PATH2), it only partly solves the problem because then cmake output is Found JNI: /usr/lib/jvm/default/lib/amd64/libjawt.so
My CMakeLists.txt
cmake_minimum_required(VERSION 3.14)
project(project1)
set(CMAKE_CXX_STANDARD 17)
find_package(JNI REQUIRED)
add_executable(project1 main.cpp)
NOTE: I have JAVA_HOME set to /usr/lib/jvm/java-8-openjdk and java-8-openjdk package installed from AUR.
Have you tried adding includes with this one
include_directories( ${CMAKE_JAVA_} $ENV{JAVA_HOME}/include $ENV{JAVA_HOME}/include/linux )

'OpenCV required but some headers or libs not found' with CLion, MinGW-64, CMake on Windows 10

I've been trying for a few days to correctly setup OpenCV with CLion with little success, so asking on SO.
Here's what my CMakeLists looks like:
cmake_minimum_required(VERSION 3.12)
project(ocv_test)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
find_package(OpenCV REQUIRED)
set(SOURCE_FILES main.cpp)
add_executable(ocv_test ${SOURCE_FILES})
include_directories(${OpenCV_INCLUDE_DIRS})
target_link_libraries(ocv_test ${OpenCV_LIBS})
Here's the error I get:
"C:\Program Files\JetBrains\CLion 2018.2.2\bin\cmake\win\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - MinGW Makefiles" C:\Users\Owner\CLionProjects\ocv-test
Could not find OpenCV_CORE_INCLUDE_DIR
Could not find OpenCV_HIGHGUI_INCLUDE_DIR
Include dir: OFF
CMake Error at C:/Program Files/JetBrains/CLion 2018.2.2/bin/cmake/win/share/cmake-3.12/Modules/FindOpenCV.cmake:220 (MESSAGE):
OpenCV required but some headers or libs not found. Please specify it's
location with OpenCV_ROOT_DIR env. variable.
Call Stack (most recent call first):
CMakeLists.txt:6 (find_package)
-- Configuring incomplete, errors occurred!
See also "C:/Users/Owner/CLionProjects/ocv-test/cmake-build-debug/CMakeFiles/CMakeOutput.log".
I primarily followed these steps from another SO answer, but here are the steps:
Installed MinGW-64
Architecture: x86_64, Threads: posix, Exception: sjlj
Installed CMake 3.12.2 x64 msi
In System variables, set/create the following:
_CMAKE_HOME (C:\Program Files (x86)\CMake)
_MINGW_HOME (C:\mingw\mingw64)
Then, add the following to Path variable:
%_CMAKE_HOME%\bin
%_MINGW_HOME%\bin
Download OpenCV 3.4.3, and Extract to:
C:\opencv\opencv-3.4.3
Using CMake, Configure w/ MinGW Makefiles and specifying Native compilers:
C: C:/mingw/mingw64/bin/x86_64-w64-mingw32-gcc.exe
C++: C:/mingw/mingw64/bin/x86_64-w64-mingw32-g++.exe
Then, Generate (without Tests, Docs, Python, WITH_IPP, WITH_MSMF) to:
C:_dev_sw\opencv\opencv-3.4.3\build_mingw
Run mingw32-make, then mingw32-make install in C:_dev_sw\opencv\opencv-3.4.3\build_mingw
In System variables, set/create the following:
_OPENCV_HOME (C:\opencv\opencv-3.4.3\build_mingw\install\x64\mingw)
Then, add the following to Path variable:
%_OPENCV_HOME%\bin
Add FindOpenCV.cmake to:
C:\Program Files\JetBrains\CLion 2018.2.2\bin\cmake\win\share\cmake-3.12\Modules
Create new C++ executable project in CLion (ocv-test)
Update MakeLists.txt file (see above)
Reload MakeLists.txt and get errors shown above
I tried to update the CMakeLists as below, but still same errors:
cmake_minimum_required(VERSION 3.12)
project(ocv_test)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
# Where to find CMake modules and OpenCV
set(OpenCV_DIR "C:\\opencv\\opencv-3.4.3\\build_mingw\\install")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
add_executable(ocv_test main.cpp)
# add libs you need
set(OpenCV_LIBS opencv_core opencv_imgproc opencv_highgui opencv_imgcodecs)
# linking
target_link_libraries(ocv_test ${OpenCV_LIBS})
Unlike this SO answer, I do not see OpenCV_DIR name in my CMake build. Also, I tried updating _OPENCV_HOME to OpenCV_ROOT_DIR (as error says), but that didn't work either.
Does anything seem off?
===
Edit 1:
FindOpenCV was the issue (so skip step 11). Setting the OPENCV_DIR var in CMakeLists fixed the errors, and built successfully (Thanks Tsyvarev!).
I'm not sure if setting OPENCV_DIR in CMakeLists will be an issue if the project is ran on another PC and/or OS, so I added OPENCV_DIR entry (pointing to /install directory) into CMake GUI, Repeated steps 6-8, created new but similar CLion project, and got the following error:
CMake Error at CMakeLists.txt:10 (find_package):
By not providing "FindOpenCV.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "OpenCV", but
CMake did not find one.
Could not find a package configuration file provided by "OpenCV" with any
of the following names:
OpenCVConfig.cmake
opencv-config.cmake
Add the installation prefix of "OpenCV" to CMAKE_PREFIX_PATH or set
"OpenCV_DIR" to a directory containing one of the above files. If "OpenCV"
provides a separate development package or SDK, be sure it has been
installed.
Again, this is fixed if I set the OPENCV_DIR variable. But how can it be avoided since it's already configured in GUI?

Use libbitcoin in CLion

I am not a C++ programmer, only have made a course a while ago. Using homebrew I installed libbitcoin and was hoping that I can reference the library like I was able to reference the boost libraries. I also realized that there are no links in /usr/local/bin to the Cellar.
I think I could get it working by using the absolute paths but I am looking for the proper way of handling this constellation that I just mentioned.
Current CMake:
cmake_minimum_required(VERSION 2.8.4)
project(cplusplus)
message(STATUS "start running cmake...")
find_package(boost 1.65.1 COMPONENTS system filesystem REQUIRED)
find_package(libbitcoin 3.3.0 COMPONENTS system filesystem REQUIRED)
message("system: ${CMAKE_SYSTEM_PREFIX_PATH}")
find_library(LIB_BITCOIN libbitcoin)
message("bitcoin: ${LIB_BITCOIN}")
if(Boost_FOUND)
message(STATUS "Boost_INCLUDE_DIRS: ${Boost_INCLUDE_DIRS}")
message(STATUS "Boost_LIBRARIES: ${Boost_LIBRARIES}")
message(STATUS "Boost_VERSION: ${Boost_VERSION}")
include_directories(${Boost_INCLUDE_DIRS})
endif()
add_executable(cplusplus main.cpp)
if(Boost_FOUND)
target_link_libraries(cplusplus ${Boost_LIBRARIES})
endif()
Currently I get these errors:
/Applications/CLion.app/Contents/bin/cmake/bin/cmake -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - Unix Makefiles" /Users/johndow/Documents/Workspace/bitcoin-code/cplusplus
-- start running cmake...
-- Boost version: 1.65.1
CMake Error at CMakeLists.txt:8 (find_package):
By not providing "Findlibbitcoin.cmake" in CMAKE_MODULE_PATH this project
has asked CMake to find a package configuration file provided by
"libbitcoin", but CMake did not find one.
Could not find a package configuration file provided by "libbitcoin"
(requested version 3.3.0) with any of the following names:
libbitcoinConfig.cmake
libbitcoin-config.cmake
Add the installation prefix of "libbitcoin" to CMAKE_PREFIX_PATH or set
"libbitcoin_DIR" to a directory containing one of the above files. If
"libbitcoin" provides a separate development package or SDK, be sure it has
been installed.
-- Configuring incomplete, errors occurred!
See also "/Users/johndoe/Documents/Workspace/bitcoin-code/cplusplus/cmake-build-debug/CMakeFiles/CMakeOutput.log".
[Finished]
You seem to have double lookup for libbitcoin library in your CMakeLists file. You are first looking for it by:
find_package(libbitcoin ...)
and then by
find_library(LIB_BITCOIN libbitcoin)
Cmake is not happy (as your error message says) with the find_package() clause as libbitcoin does not provide cmake configuration by itself. You have many ways how to fix it, just two of them:
remove find_package() and use only find_library(), I think this is the simpler way and your project should work this way
provide cmake configuration for libbitcoin by yourself. Good introduction how to do this is here (and good to read anyway):
https://cmake.org/Wiki/CMake:How_To_Find_Libraries
As far as I know, currently libbitcoin does not export any <libbitcoin>Config.cmake package.
But it does export a libbitcoin.pc file for generic use with pkg-config.
ie: /usr/local/lib/pkgconfig/libbitcoin.pc
If you get results from invoking pkg-config --cflags libbitcoin then it's there.
And then you can put something like this in your CMakeLists.txt:
#use this if libbitcoin is installed to some custom location
set(ENV{PKG_CONFIG_PATH} "/path/to/libbitcoin/pkgconfig/:$ENV{PKG_CONFIG_PATH}")
#then later..
find_package(PkgConfig REQUIRED)
pkg_check_modules(LIB_BITCOIN REQUIRED libbitcoin)
#then later..
target_link_libraries(${PROJECT_NAME} PRIVATE ${LIB_BITCOIN_LIBRARIES})
target_include_directories(${PROJECT_NAME} PRIVATE ${LIB_BITCOIN_INCLUDE_DIRS})
That should pull in boost, make the libbitcoin includes visible and solve all manner of compiler and linker woes.
(Or if you are feeling mad, you could always make use of this gist).