I am struggling with the following issue and I really wish someone could provide me with helpful tips.
When building my C++ application based on Qt5.8 using CMake 3.8.2, I got the following error during the "generate" step:
CMake Error at ntActions/ntActionsITK/CMakeLists.txt:81 (ADD_LIBRARY):
Target "ntActionsITK" links to target "Qt5::X11Extras" but the target
was not found. Perhaps a find_package() call is missing for an IMPORTED
target, or an ALIAS target is missing?
These are the two lines of my CMakeLists, where the issue is arising:
80 - ADD_DEFINITIONS(-DQT_GUI_LIBS -DQT_CORE_LIB -DQT3_SUPPORT)
81 - ADD_LIBRARY(ntActions ${ntActionsGUI_SRCS} ${ntActions_GUI}
My PATH variable includes QT5.8 install path (lib, lib/CMake, bin, include).
CMake is able to automatically find all Qt5 packages I am using, including Qt5X11Extras.
Am I missing something?
My dev env. is the following: Debian 8, Qt(5.8), CMake(3.8.2)
Any help will be appreciated
Thanks
Bouba
ADD: qt5Setup.cmake file
Hi Tsyvarev, thanks for your feedback. I have a qt5Setup.cmake file to setup Qt5, as follows:
find_package(Qt5 COMPONENTS Core Widgets Gui Network Concurrent OpenGL
Svg PrintSupport Sql SerialPort MultimediaWidgets X11Extras)
IF(QT_USE_FILE)
INCLUDE(${QT_USE_FILE})
ENDIF(QT_USE_FILE)
include_directories(
${Qt5Core_INCLUDE_DIRS}
${Qt5Widgets_INCLUDE_DIRS}
${Qt5Gui_INCLUDE_DIRS}
${Qt5Network_INCLUDE_DIRS}
${Qt5OpenGL_INCLUDE_DIRS}
${Qt5Svg_INCLUDE_DIRS}
${Qt5Concurrent_INCLUDE_DIRS}
${Qt5PrintSupport_INCLUDE_DIRS}
${Qt5Sql_INCLUDE_DIRS}
${QtSerialPort_INCLUDE_DIRS}
${Qt5MultimediaWidgets_INCLUDE_DIRS}
${Qt5X11Extras_INCLUDE_DIRS})
LINK_LIBRARIES(
${Qt5Svg_LIBRARIES}
${Qt5Network_LIBRARIES}
${Qt5Widget_LIBRARIES}
${Qt5Sql_LIBRARIES}
${QtSerialPort_LIBRARIES}
${Qt5MultimediaWidgets_LIBRARIES}
${Qt5PrintSupport_LIBRARIES}
${Qt5X11Extras_LIBRARIES})
Related
I have tried for a day to try and resolve issues with the cmake when trying to build a project using the zeromq library. I appreciate that there have been several threads on this question in the past, but none seem to explain the fix in any detail. I've exhausted my knowledge regarding how to solve this one and would appreciate an explanation as to what I need to do.
Below is the following error message from the project cmake command issued inside CLion.
The cmake Error occurs at line 1 of vcpkg-cmake-wrapper.cmake proving that it was found.
Could not find a package configuration file provided by "zeromq" with
any of the following names:
zeromqConfig.cmake
zeromq-config.cmake
Add the installation prefix of "zeromq" to CMAKE_PREFIX_PATH or set
"zeromq_DIR" to a directory containing one of the above files. If "zeromq"
provides a separate development package or SDK, be sure it has been
installed.
Where does this package config file go and what is in it? What is meant by adding the installation prefix to CMAKE_PREFIX_PATH?
I installed zeromq using vcpkg. The output from vcpkg list is
cppzmq:x64-linux 4.8.1#1 Header-only C++ binding for ZeroMQ
zeromq:x64-linux 4.3.4#6 The ZeroMQ lightweight messaging kernel is a lib...
So to me this looks like the library downloaded, built and installed correctly.
My cmake toolchain options are:
-DCMAKE_TOOLCHAIN_FILE=~/vcpkg/scripts/buildsystems/vcpkg.cmake
/vcpkg/installed/x64-linux/share/zeromq/vcpkg-cmake-wrapper.cmake:1
CMakeLists.txt is:
cmake_minimum_required(VERSION 3.24.0)
project(Template VERSION 1.0.0)
add_executable(template src/main.cpp)
find_package(zeromq CONFIG REQUIRED)
find_package(cppzmq CONFIG REQUIRED)
target_compile_features(Template PRIVATE cxx_std_17)
target_link_libraries(main
PRIVATE
zeromq::zeromq
cppzmq::cppzmq)
This is currently an empty project until I get cmake process to resolve the library
I have tried to understand by following the example on: https://vcpkg.readthedocs.io/en/latest/examples/manifest-mode-cmake/ From this I can successfully build and create an executable.
Thanks Tsyvarev. I achieved an error free CMake by changing my CMakeLists.txt to:
cmake_minimum_required(VERSION 3.24.0)
project(Template VERSION 1.0.0)
#set(zeromq_DIR "~/usr/local/lib/cmake/ZeroMQ")
add_executable(Template src/main.cpp)
find_package(ZeroMQ CONFIG REQUIRED)
target_compile_features(Template PRIVATE cxx_std_17)
target_link_libraries(Template
PRIVATE
ZeroMQ)
I have to do a project using CMake and the CGAL geometry library but, regardless having tried everything I can find online, I still can't figure out how to configure my project in CMake. I have installed all the libraries CGAL depends on and qt5 but CMake keeps giving me errors when I try to configure and generate. I am almost a beginner so any kind of help would be very useful. I am using windows 10 and visual studio 2019. Following are the errors it's giving me.
CMake Warning at CMakeLists.txt:5 (find_package): By not providing "FindCGAL.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "CGAL", but CMake did not find one.
Could not find a package configuration file provided by "CGAL" with any of the following names:
CGALConfig.cmake
cgal-config.cmake
Add the installation prefix of "CGAL" to CMAKE_PREFIX_PATH or set "CGAL_DIR" to a directory containing one of the above files. If "CGAL" provides a separate development package or SDK, be sure it has been installed.
CMakeLists.txt
cmake_minimum_required(VERSION "3.22.0-rc2")
project("TesiLaurea")
find_package(CGAL)
add_executable("${PROJECT_NAME}" "Main.cpp")
target_link_libraries("${PROJECT_NAME}" CGAL::CGAL)
I have git cloned, built (with MSVC for both Debug and Release) and then installed wxWidgets:
cmake -B build wxWidgets
cmake --build build --config <CONFIG>
cmake --install build --prefix my_install --config <CONFIG>
with <CONFIG> = Debug and <CONFIG> = Release.
Then I used the following CMake script to link against it, as suggested by the wiki:
cmake_minimum_required(VERSION 3.16)
project(Test)
add_executable(Test WIN32 Main.cpp)
# wxWidgets
SET(wxWidgets_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../thirdparty/my_install)
find_package(wxWidgets COMPONENTS core base REQUIRED)
include(${wxWidgets_USE_FILE})
target_link_libraries(Test PRIVATE ${wxWidgets_LIBRARIES})
# Copy runtime DLLs to the directory of the executable.
add_custom_command(TARGET Test POST_BUILD
COMMAND ${CMAKE_COMMAND} -E echo "Runtime Dlls: $<TARGET_RUNTIME_DLLS:Test>"
)
My goal is to automatically copy the DLLs into the directory of the built executable, so that they can be found at runtime. For that I'm using the TARGET_RUNTIME_DLLS generator expression (follwing the sample code in the docs). In the code above, I only print out the expression at build time for testing purposes. The problem is that it is empty.
The approach worked for me before when installing and linking SDL, but SDL provides package configuration files which create imported targets, defining the DLL location(s) via IMPORTED_LOCATION_RELEASE or IMPORTED_LOCATION_DEBUG. For wxWidgets one is apparently supposed to use the FindwxWidgets.cmake script shipped with CMake, which sadly doesn't define the produced binaries. Maybe that's why TARGET_RUNTIME_DLLS isn't populated.
Does anyone know, either how to get TARGET_RUNTIME_DLLS filled or how to obtain the list of built wxWidgets DLLs for the current configuration (Release/Debug) post build copying?
Thanks a lot in advance!
I am dealing with a similar problem.
First sanity checks:
You have to work on windows platform otherwise this feature does not
work.
Your Cmake is 3.21 or above
Next comes fuzzy part. I think the library that you are trying to include have to be a Shared Imported library and you have to set a set_target_properties for IMPORTED_IMPLIB which is a path to a .lib file of sort (dll import library, I think it is called) So you have to make sure that it is all set in the package library that you trying to link with your executable.
If you have those dll avaiable and you just want to use them and not actually build them then you can write your own cmake script that will do just what I said above. Then you can include that cmake file in your project and then link against your app.
Note: I also work on similar issue right now and what I just said have not been working very reliably. I got some dlls to be copied and some do not.
Edit:
Cmake docs give a more detailed explanation on how this library setting should look like if you use find_package feature.
Found here: https://cmake.org/cmake/help/latest/command/add_library.html#imported-libraries
An UNKNOWN library type is typically only used in the implementation
of Find Modules. It allows the path to an imported library (often
found using the find_library() command) to be used without having to
know what type of library it is. This is especially useful on Windows
where a static library and a DLL's import library both have the same
file extension.
I have searched for this topic and found this and this, but it only seems to either pertain to building wxWidgets or do not contain an answer to my question.
I have built the static libs für wxWidgets on Windows successfully, but I am now struggling to correctly include the libraries to my project using Cmake. This is my CMakeLists.txt:
set(PROJECT_NAME wxapp)
project(${PROJECT_NAME})
cmake_minimum_required(VERSION 2.8)
set(SRC_LIST main.cpp app.cpp app.h frame.cpp frame.h)
add_executable(${PROJECT_NAME} WIN32 ${SRC_LIST})
find_package(wxWidgets REQUIRED net gl core base)
include(${wxWidgets_USE_FILE})
target_link_libraries(${PROJECT_NAME} ${wxWidgets_LIBRARIES})
set(wxWidgets_USE_LIBS ON)
set(wxWidgets_CONFIGURATION msw)
I have set the WXWIN path variable correctly. Yet, CMake throws an error with this configuration:
Could NOT find wxWidgets (missing: wxWidgets_LIBRARIES
wxWidgets_INCLUDE_DIRS net gl core base)
I have tried multiple suggestions, like using downloading prebuild dynamic libraries and adding them manually as suggested here, e.g.
set(wxWidgets_ROOT_DIR $ENV{WXWIN})
set(wxWidgets_LIBRARIES $ENV{WXWIN}/include)
set(wxWidgets_INCLUDE_DIR $ENV{WXWIN}/lib/vc14x_x64_dll)
include_directories(includes $ENV{WXWIN} $ENV{WXWIN}/include $ENV{WXWIN}/lib/vc14x_x64_dll)
link_directories($ENV{WXWIN} $ENV{WXWIN}/include $ENV{WXWIN}/lib/vc14x_x64_dll) # this seems to be a discouraged/deprecated method
but all to no avail.
WORKAROUND (at least it works for me):
I changed the find_package command from the suggested statement:
find_package(wxWidgets COMPONENTS gl core base OPTIONAL_COMPONENTS net)
to
find_package(wxWidgets 3.1 REQUIRED)
A user in this post had this included in his/her CMake file and out of deperation, I tried this and it actually worked. Seems like the configuration of CMake under certain unknown circumstances won't function correctly with the statement provided in the instructions. If I change the command to the new statement my static build as well as self- and precompiled dlls are flawlessly identifed by CMake.
I also cleared the CMake cache, inspired by this post. According to this post, there seems to be an issue with Windows and the CMake cache in some situations, but the reasons escape me. I could replicate the behaviour observed by the user there:
Under Windows, you have to point to the installation directory, e.g.
set(wxWidgets_ROOT_DIR "C:/wxWidgets-3.1.3") set(wxWidgets_LIB_DIR
"C:/wxWidgets-3.1.3/lib/vc14x_x64_dll")
But then the behavior is still strange. When i use CMake GUI (3.16,
latest), behavior is like this
delete cache (just to be consistent)
press 'configure' button
--> fail: CMake Error at C:/Program Files/CMake/share/cmake-3.16/Modules/FindPackageHandleStandardArgs.cmake:146
(message): Could NOT find wxWidgets (missing: wxWidgets_LIBRARIES
wxWidgets_INCLUDE_DIRS core base qa adv net html gl propgrid richtext)
press 'configure' button again
--> success
I also have observed some inconsistent behaviour of CMake within the IDEs CLion and CodeBlocks when clearing the cache and reloading the project.
So, exactly how the cache clearing plays into the resolution of my issue, I don't know. But if I merely clear the cache, reload my project and leave the CMake instruction at find_package(wxWidgets COMPONENTS gl core base OPTIONAL_COMPONENTS net), CMake won't find my installation despite the WXWIN path being set correctly.
If you know more about this, I am happy to be corrected.
I'm trying to get compiled project under QTCreator with CMake under Windows, I'm wonder how to add external library and its headers to my project. I have my CMakeList.txt as follows
cmake_minimum_required(VERSION 2.8)
project(opencl_info)
add_executable(${PROJECT_NAME} "main.cpp")
include_directories(c:\\AMD APP SDK\\3.0\\include\\)
target_link_libraries(opencl_info c:\\AMD APP SDK\\3.0\\lib\\x86_64\\OpenCL.lib)
I'm getting "CL\cl.h - No such file or directory" how to include it? for now with "hardlink"?
Thank you.
Under VS15 I'm running this project and it requires to have:
"Additional Include Directories" c:\AMD APP SDK\3.0\include\
"Additional Library Directories" c:\AMD APP SDK\3.0\lib\x86_64\
"Additional Depandancies" OpenCL.lib and th eproject runs.
I need to have OpenCL.dll within my path.
So I'm looking for the same/similar behaviour for QTCreator/CMake to include headers and libraries (.lib,.dll) for my project.
Thank you.
I have more opencl platfroms (nVidia, AMD) present on my machine, per using FIND_PACKAGE(OpenCL REQUIRED) its nVidia identified instead Found OpenCL: C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v8.0/lib/x64/OpenCL.lib (found version "1.2")
How to tell CMake explicitly to find and use AMD?
In CMake spaces are separators. If you want to use string with spaces, enclose it in double quotes:
"c:\\AMD APP SDK\\3.0\\include\\"
Partial success, I moved AMD APP SDK to another directory named as c:\opencl\
which is shorten with no space in path directory
I included direcotries include_directories(c:\\opencl\\include\\) and now an issue of missing "CL\cl.h - No such file or directory" is gone.
I found solution :)
cmake_minimum_required(VERSION 2.8)
project(opencl_info)
include_directories("c:\\AMD APP SDK\\3.0\\include\\")
link_directories("c:\\AMD APP SDK\\3.0\\lib\\x86_64\\")
add_executable(${PROJECT_NAME} "main.cpp")
target_link_libraries(opencl_info OpenCL.lib)
Thanks for help, guys!!!