Can't build QT6 with CMake on ubuntu - c++

I am trying to manually setup a CMake project that uses QT6 on Ubuntu 20.04 LTS.
This is what the CMakeLists.txt looks like:
cmake_minimum_required(VERSION 3.16)
project(Button, LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_PREFIX_PATH "home/ilmu011/Qt/6.2.3/gcc64")
find_package(Qt6 REQUIRED COMPONENTS Widgets)
add_executable(Button
main.cpp
)
However, CMake states that it doesn't find the QT6 installation. It is installed under home/ilmu011/Qt/6.2.3/gcc64. But I get an error message:
CMake Error at CMakeLists.txt:14 (find_package):
By not providing "FindQt6.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "Qt6", but
CMake did not find one.
Could not find a package configuration file provided by "Qt6" with any of
the following names:
Qt6Config.cmake
qt6-config.cmake
Add the installation prefix of "Qt6" to CMAKE_PREFIX_PATH or set "Qt6_DIR"
to a directory containing one of the above files. If "Qt6" provides a
separate development package or SDK, be sure it has been installed.
-- Configuring incomplete, errors occurred!
See also "/home/ilmu011/Desktop/Button/build/CMakeFiles/CMakeOutput.log".
make: *** [Makefile:176: cmake_check_build_system] Error 1
It tells me to set the CMAKE_PREFIX_PATH to the QT6 location, which I did here, but it still doesn't work. I searched around for a solution and found this post:
CMAKE_PREFIX_PATH doesn't help CMake in finding Qt5
It says since the error message also states that eventually a separate development package is required that would eventually provide the "qt6-config.cmake" that CMake complains is not there, I should try installing these two things:
sudo apt-get install qtbase5-dev
sudo apt-get install qtdeclarative5-dev
However, these are for QT5 and that didn't work. How can I get CMake to detect QT6?

On ubuntu, the package qt6-base-dev provides Qt6Config.cmake. With this, cmake finds the qt6 libraries installed with apt, without helping it with the option CMAKE_PREFIX_PATH.
sudo apt install qt6-base-dev

Related

Generate wasm file using emscripten

I want to compile SealPIR library using emscripten to generate a wasm file.
When using this command:
emcmake cmake .
I get this error:
CMake Error at CMakeLists.txt:19 (find_package):
By not providing "FindSEAL.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "SEAL", but
CMake did not find one.
Could not find a package configuration file provided by "SEAL" (requested
version 3.2.0) with any of the following names:
SEALConfig.cmake
seal-config.cmake
Add the installation prefix of "SEAL" to CMAKE_PREFIX_PATH or set
"SEAL_DIR" to a directory containing one of the above files. If "SEAL"
provides a separate development package or SDK, be sure it has been
installed.
-- Configuring incomplete, errors occurred!
See also "/home/Zied/webassembly/SealPIR/CMakeFiles/CMakeOutput.log".
emcmake: error: 'cmake . -DCMAKE_TOOLCHAIN_FILE=/home/Zied/webassembly/emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake -DCMAKE_CROSSCOMPILING_EMULATOR="/home/Zied/webassembly/emsdk/node/14.15.5_64bit/bin/node"' failed (1)
SEAL is correctly installed. when i run the same command without emcmake it works just fine.
This is my CMakeList
cmake_minimum_required(VERSION 3.10)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
project(SealPIR VERSION 2.1 LANGUAGES CXX)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
add_executable(main
main.cpp
)
add_library(sealpir STATIC
pir.cpp
pir_client.cpp
pir_server.cpp
)
find_package(SEAL 3.2.0 EXACT REQUIRED)
target_link_libraries(main sealpir SEAL::seal)
When using a toolchain file for cross compiling, CMake will by default disable system libraries. It won't search into any directory to avoid finding files that is not compatible with the target system.
You think you didn't used a toolchain file? Think again! emcmake hides that from you. Look carefully at the error output.
Here you compiled the SEAL library, but you installed it in the default path, which is /usr/local.
We can tell CMake to explicitly search there, but I wouldn't recommend, but you can try if it works:
emcmake cmake . -CMAKE_PREFIX_PATH=/usr/local
The proper solution would be to create a directory with all the emscripten libraries in it:
# In the SEAL build directory
emcmake cmake .. -DCMAKE_INSTALL_PREFIX=/home/anblic/webassembly/install
Then after installing the libraries in that directory, you can set the prefix path in the same directory as the install path:
# Assuming you're in a build/ subdirectory
emcmake cmake .. -DCMAKE_PREFIX_PATH=/home/anblic/webassembly/install

Cannot find "Findaws-lambda-runtime.cmake" on ubuntu18.04

Trying to build the hello world example, but the cmake always complain
By not providing "Findaws-lambda-runtime.cmake" in CMAKE_MODULE_PATH this
project has asked CMake to find a package configuration file provided by
"aws-lambda-runtime", but CMake did not find one.
Environment
OS : ubuntu18.04.3 LTS,64bits
install curl by : sudo apt-get install libcurl4-openssl-dev
install cmake by ubuntu software(cmake version 3.16.1)
Steps to build and install aws lambda cpp
git clone https://github.com/awslabs/aws-lambda-cpp.git
cd aws-lambda-cpp
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF \
-DCMAKE_INSTALL_PREFIX=${PWD}/install
make -j2
sudo make install
CmakeLists.txt(omit another part, want to make sure find_package works first)
cmake_minimum_required(VERSION 3.5)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
project(aws_cpp_test LANGUAGES CXX)
list(APPEND CMAKE_MODULE_PATH "/home/yyyy/Qt/3rdLibs/aws-lambda-cpp/build/")
list(APPEND CMAKE_MODULE_PATH "/home/yyyy/Qt/3rdLibs/aws-lambda-cpp/cmake/")
find_package(aws-lambda-runtime REQUIRED)
add_executable(${PROJECT_NAME} "main.cpp")
I do not use the ec2 to build the project, how could I tell the cmake where should it find the aws-lambda-runtime?
Edit :
Based on the suggestion of Yevhenii Mamontov, I change the CMakeLists.txt to
cmake_minimum_required(VERSION 3.5)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
project(aws_cpp_test LANGUAGES CXX)
set(AWS_LAMBDA_CMAKE "/home/yyyy/Qt/3rdLibs/aws-lambda-cpp/cmake/")
set(CMAKE_PREFIX_PATH "${AWS_LAMBDA_CMAKE};${CMAKE_PREFIX_PATH}")
#check the prefix paths are correct or wrong
foreach(path ${CMAKE_PREFIX_PATH})
message("Path: " ${path})
endforeach(path)
find_package(aws-lambda-runtime REQUIRED)
But it come with different error message
CMake Error at
/home/yyyy/Qt/3rdLibs/aws-lambda-cpp/cmake/aws-lambda-runtime-config.cmake:6
(include): include could not find load file:
/home/yyyy/Qt/3rdLibs/aws-lambda-cpp/cmake/#CMAKE_PROJECT_NAME#-targets.cmake
I tried with different paths
set(AWS_LAMBDA_CMAKE "/home/yyyy/Qt/3rdLibs/aws-lambda-cpp/build/install")
set(AWS_LAMBDA_CMAKE "/home/yyyy/Qt/3rdLibs/aws-lambda-cpp/build/install/lib/aws-lambda-runtime/cmake")
and tried to do not add any new path, but all of them give the same error messages
Edit 2 :
Find a way to make it work
Remove the contents of /home/yyyy/Qt/3rdLibs/aws-lambda-cpp/cmake/aws-lambda-runtime-config.cmake
set path as set(AWS_LAMBDA_CMAKE "/home/yyyy/Qt/3rdLibs/aws-lambda-cpp/build/install/lib/aws-lambda-runtime/cmake")
However, this solution is awkward, should ask the cmake do not search from the path "/home/yyyy/Qt/3rdLibs/aws-lambda-cpp/cmake" first
Edit 3:
The solution I written in Edit 2 do not work. It fail when I add
add_executable(${PROJECT_NAME} "main.cpp")
target_link_libraries(${PROJECT_NAME} PUBLIC AWS::aws-lambda-runtime)
Error messages are
Target "aws_cpp_test" links to target "AWS::aws-lambda-runtime" but the
target was not found. Perhaps a find_package() call is missing for an
IMPORTED target, or an ALIAS target is missing?
Could you try to set CMAKE_PREFIX_PATH just before the find_package?
Something like this:
set(AWS_LAMBDA_CMAKE "/home/yyyy/Qt/3rdLibs/aws-lambda-cpp/cmake/")
set(CMAKE_PREFIX_PATH "${AWS_LAMBDA_CMAKE};${CMAKE_PREFIX_PATH}")
The first set() creates a variable with the path to your lib cmake folder.
The second set() appends to CMAKE_PREFIX_PATH one more path to search for any package that you've indicated in find_package().
Find out the solution, all you need to do are set the path of the aws library installed.
Example:
cmake_minimum_required(VERSION 3.5)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
project(encoder LANGUAGES CXX)
set(AWS_LAMBDA_CMAKE ${CMAKE_CURRENT_SOURCE_DIR}/../../3rdLibs/aws-lambda-cpp/build/install/)
set(AWS_LAMBDA_CPP_SDK ${CMAKE_CURRENT_SOURCE_DIR}/../../3rdLibs/aws-sdk-cpp/build/install/)
set(CMAKE_PREFIX_PATH "${AWS_LAMBDA_CMAKE};${CMAKE_PREFIX_PATH};${AWS_LAMBDA_CPP_SDK}")
find_package(CURL REQUIRED)
find_package(aws-lambda-runtime REQUIRED)
find_package(AWSSDK COMPONENTS s3)
add_executable(${PROJECT_NAME} "main.cpp")
target_link_libraries(${PROJECT_NAME}
${CURL_LIBRARIES}
AWS::aws-lambda-runtime
${AWSSDK_LINK_LIBRARIES})
aws_lambda_package_target(${PROJECT_NAME})
You may need to install following libs on your ubuntu if you haven't
sudo apt-get install zlib1g-dev libssl-dev libcurl4-openssl-dev
I got the same error, the answer marked as solution worked pretty well, but I also found tha this works:
set(aws-lambda-runtime_DIR /lib/aws-lambda/lib64/aws-lambda-runtime/cmake/)
I am using CMake 3.13 and had the lambda runtime installed on "/lib/aws-lambda" when running tha cmake as instructed by the installation instructions:
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/lib/aws-lambda

'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).

cmake does not find qt 5.1.1

I just installed the Qt 5.1.1 for Windows 32-bit (MinGW 4.8, OpenGL) and tried to add it to my cmake. But CMake just does not want to find it and i dont know why. What am i missing? Do i need to set an environment variable or something?
Here is my cmake :
cmake_minimum_required( VERSION 2.8.11 )
PROJECT(Blemmer)
# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
# Detect and add SFML
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules" ${CMAKE_MODULE_PATH})
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin )
set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib )
find_package(SFML REQUIRED system window graphics network audio)
# The QUIET option disables messages if the package cannot be found.
FIND_PACKAGE(Qt5Widgets)
add_subdirectory(Entity)
add_subdirectory(Engine)
add_subdirectory(Game)
add_executable(Blemmer main.cpp)
include_directories(${SFML_INCLUDE_DIR} ${PROJECT_SOURCE_DIR})
target_link_libraries(Blemmer ${SFML_LIBRARIES} Game Engine Qt5::Widgets)
and this is the output of cmake-gui :
CMake Warning at CMakeLists.txt:14 (FIND_PACKAGE):
By not providing "FindQt5Widgets.cmake" in CMAKE_MODULE_PATH this project
has asked CMake to find a package configuration file provided by
"Qt5Widgets", but CMake did not find one.
Could not find a package configuration file provided by "Qt5Widgets" with
any of the following names:
Qt5WidgetsConfig.cmake
qt5widgets-config.cmake
Add the installation prefix of "Qt5Widgets" to CMAKE_PREFIX_PATH or set
"Qt5Widgets_DIR" to a directory containing one of the above files. If
"Qt5Widgets" provides a separate development package or SDK, be sure it has
been installed.
I successly build my GUI on MacOSX 10.10 by exporting Linux environment variables
$ brew install qt5
$ ls /usr/local/opt/qt5/lib/cmake/Qt5Widgets/Qt5WidgetsConfig.cmake
$ /usr/local/opt/qt5/lib/cmake/Qt5Widgets/Qt5WidgetsConfig.cmake
$ export CMAKE_PREFIX_PATH=/usr/local/opt/qt5/
$ cd ./build
$ cmake ../CMakeLists.txt
$ make -j8
Acroding to http://www.cmake.org/cmake/help/v3.0/variable/CMAKE_PREFIX_PATH.html, the cmake function FIND_LIBRARY() will appends /lib to each of the directories. So done.
You need to set the CMAKE_PREFIX_PATH to the Qt installation.
See http://doc.qt.io/qt-5/cmake-manual.html
Fixed it with the following in a CMakeLists.txt file:
set(CMAKE_PREFIX_PATH $ENV{HOME}/Qt5.5.0/5.5/gcc_64)
For me, the context ended up something like:
# Ubuntu 14.04 LTS, CMake 2.8.12.2
wget http://download.qt.io/official_releases/qt/5.5/5.5.0/qt-opensource-linux-x64-5.5.0.run
chmod u+x qt-opensource-linux-x64-5.5.0.run
./qt-opensource-linux-x64-5.5.0.run
# Follow GUI prompts, installed to default location