I'm trying to write a GUI appication (under Ubuntu 18.04) using Qt5 and CMake. I failed to integrate the Qt multimedia module into my project.
My CMakeLists.txt:
cmake_minimum_required(VERSION 3.10)
project(Chess)
#set(CMAKE_PREFIX_PATH "/home/mashplant/Qt5.9.6/5.9.6/gcc_64")
#whether I comment it off or not doesn't have an effect on the result
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
find_package(Qt5 COMPONENTS Widgets Network Multimedia REQUIRED)
set(CMAKE_CXX_STANDARD 11)
include_directories(.)
add_executable(Main Main.cpp
MainWindow.cpp MainWindow.hpp ChessFrame.cpp ChessFrame.hpp resource.qrc)
target_link_libraries(Main Qt5::Widgets Qt5::Network Qt5::Multimedia)
And I get the following warning when I run CMake:
CMake Warning at CMakeLists.txt:18 (add_executable):
Cannot generate a safe runtime search path for target Main because files in
some directories may conflict with libraries in implicit directories:
runtime library [libQt5Widgets.so.5] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
/home/mashplant/Qt5.9.6/5.9.6/gcc_64/lib
runtime library [libQt5Network.so.5] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
/home/mashplant/Qt5.9.6/5.9.6/gcc_64/lib
runtime library [libQt5Gui.so.5] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
/home/mashplant/Qt5.9.6/5.9.6/gcc_64/lib
runtime library [libQt5Core.so.5] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
/home/mashplant/Qt5.9.6/5.9.6/gcc_64/lib
Some of these libraries may not be found correctly.
And when I compile, I get a link error.
/home/mashplant/Qt5.9.6/5.9.6/gcc_64/lib/libQt5Multimedia.so.5.9.6:undefined reference to ‘operator delete(void*, unsigned long)#Qt_5’
collect2: error: ld returned 1 exit status
CMakeFiles/Main.dir/build.make:203: recipe for target 'Main' failed
make[3]: *** [Main] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/Main.dir/all' failed
make[2]: *** [CMakeFiles/Main.dir/all] Error 2
CMakeFiles/Makefile2:79: recipe for target 'CMakeFiles/Main.dir/rule' failed
make[1]: *** [CMakeFiles/Main.dir/rule] Error 2
Makefile:118: recipe for target 'Main' failed
make: *** [Main] Error 2
My best bet is that CMake find different components from different installations of Qt. If that's the case, it should be enough to correct all Qt-related CMake variables to point to correct paths (for example, variables like Qt5Widgets_DIR, Qt5Multimedia_DIR, etc.).
Related
I have been pulling out of my hair because of CMakelists.txt. I would like to create a C++ application with GLFW, GLEW libraries, using MinGW and CLion IDE.
Here is my CMakeLists.txt:
cmake_minimum_required(VERSION 3.17.3)
project(imguiTask)
set(CMAKE_CXX_STANDARD 17)
add_compile_options(-DGLEW_NO_GLU)
add_executable(${PROJECT_NAME}
src/main.cpp
src/imgui.cpp
src/imgui_draw.cpp
src/imgui_widgets.cpp
)
target_include_directories(${PROJECT_NAME} PUBLIC includes)
add_library(libraries STATIC IMPORTED)
target_link_libraries(${PROJECT_NAME} glfw3)
I placed the needed libraries in the libraries folder as you can see in the picture. The folder is located in the project root. It is giving me the following error:
d:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: cannot find -lglfw3
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [imguiTask.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFiles/imguiTask.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles/imguiTask.dir/rule] Error 2
mingw32-make.exe: *** [imguiTask] Error 2
It seeems to me, that it does not search in the folder I specified. I don't know why.
I am currently trying to setup my C++ project using CMake, I successfully included dependencies like OpenMPI, but when going to Swiften, this became complex. This is not delivered in the form a package, but as shown in the git repository linked up there. Building that wasn't an issue, but I searched quite a lot of time, without finding any way to include libraries that don't provide a .so, and no main headers.
Here's my current CMakeLists.txt, made for testing only.
cmake_minimum_required (VERSION 3.0.0)
#set the executable
project (mtest)
set(EXECUTABLE_OUTPUT_PATH .)
add_executable (mtest main.cpp)
#defines libs
find_package(MPI REQUIRED)
set(CMAKE_CXX_COMPILE_FLAGS ${CMAKE_CXX_COMPILE_FLAGS} ${MPI_COMPILE_FLAGS})
set(CMAKE_CXX_LINK_FLAGS ${CMAKE_CXX_LINK_FLAGS} ${MPI_LINK_FLAGS})
include_directories(SYSTEM ${MPI_INCLUDE_PATH})
include_directories(SYSTEM Swiften)
target_link_libraries(mtest ${MPI_LIBRARIES})
add_library(swiften SHARED IMPORTED)
set_target_properties(swiften PROPERTIES
IMPORTED_LOCATION "${CMAKE_SOURCE_DIR}/Swiften/libSwiften.a"
INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_SOURCE_DIR}/Swiften"
)
target_link_libraries(mtest swiften)
And when trying to run make, here's the error :
-- Configuring done
-- Generating done
-- Build files have been written to: /home/user/Documents/CTests/build
[ 50%] Building CXX object CMakeFiles/mtest.dir/main.cpp.o
/home/user/Documents/CTests/main.cpp:12:10: fatal error: Swiften/Client/Client.h: No such file or directory
#include <Swiften/Client/Client.h>
^~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
CMakeFiles/mtest.dir/build.make:62: recipe for target 'CMakeFiles/mtest.dir/main.cpp.o' failed
make[2]: *** [CMakeFiles/mtest.dir/main.cpp.o] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/mtest.dir/all' failed
make[1]: *** [CMakeFiles/mtest.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
By the way, if the directory structure may help you, here's a tree output : https://pastebin.com/giPb9229
As part of a project I'm working on, I need to make use of the WebKitGTK+ library.
I downloaded the library (tarball) and compiled it as described here.
After the compilation was done:
The lib's headers are in /usr/local/include.
The lib's .so files are in /usr/local/lib.
In my C++ project I tried to add the following CMakeLists.txt file:
cmake_minimum_required(VERSION 3.7)
project(CVE_2016_4657)
set(CMAKE_CXX_STANDARD 11)
set(SOURCE_FILES main.cpp)
add_executable(CVE_2016_4657 ${SOURCE_FILES})
find_package(PkgConfig REQUIRED)
include_directories(/usr/local/include/webkitgtk-4.0)
link_directories(/usr/local/lib/webkit2gtk-4.0)
pkg_check_modules(GTK3 REQUIRED gtk+-3.0)
include_directories(${GTK3_INCLUDE_DIRS})
link_directories(${GTK3_LIBRARY_DIRS})
add_definitions(${GTK3_CFLAGS_OTHER})
pkg_check_modules(SOUP REQUIRED libsoup-2.4)
include_directories(${SOUP_INCLUDE_DIRS})
link_directories(${SOUP_LIBRARY_DIRS})
add_definitions(${SOUP_CFLAGS_OTHER})
target_link_libraries(
CVE_2016_4657
${GTK3_LIBRARIES}
${SOUP_LIBRARIES})
However, when compiling the project I'm getting the following error:
[ 50%] Linking CXX executable CVE_2016_4657
CMakeFiles/CVE_2016_4657.dir/main.cpp.o: In function `main':
/home/idanas/CLionProjects/Switcheroo/main.cpp:17: undefined reference to
`webkit_web_view_get_type'
/home/idanas/CLionProjects/Switcheroo/main.cpp:17: undefined reference to
`webkit_web_view_new'
/home/idanas/CLionProjects/Switcheroo/main.cpp:29: undefined reference to
`webkit_web_view_load_uri'
collect2: error: ld returned 1 exit status
CMakeFiles/CVE_2016_4657.dir/build.make:94: recipe for target
'CVE_2016_4657' failed
make[3]: *** [CVE_2016_4657] Error 1
CMakeFiles/Makefile2:67: recipe for target
'CMakeFiles/CVE_2016_4657.dir/all' failed
make[2]: *** [CMakeFiles/CVE_2016_4657.dir/all] Error 2
CMakeFiles/Makefile2:79: recipe for target
'CMakeFiles/CVE_2016_4657.dir/rule' failed
make[1]: *** [CMakeFiles/CVE_2016_4657.dir/rule] Error 2
Makefile:118: recipe for target 'CVE_2016_4657' failed
make: *** [CVE_2016_4657] Error 2
I have little-to-none experience with CMake and could really use some help.
You are trying to use WebKitGTK+, which is a separate library from both GTK+ and libsoup. You will need to duplicate your pkg_check_modules() code again for WebKitGTK+. You'll need to determine first if you are using WebKit1 or WebKit2 (they have subtly different APIs), and then find the appropriate pkg-config name for that version of WebKitGTK+; check the documentation and the contents of your /usr/lib/pkgconfig directory.
I'm trying to link a downloaded library called ArduinoJson to my project with CMake, but it seems that whenever i include the file it is missing, it will just ask for the next file its missing. I will end up with a lot of include lines which i think isnt the right way. I cant seem to find the correct syntax to include a libary in CMake
CMakeLists.txt
cmake_minimum_required(VERSION 2.8.11)
SET(CMAKE_CXX_STANDARD 11)
SET(CMAKE_CXX_STANDARD_REQUIRED ON)
SET(CMAKE_CXX_FLAGS "-DTESTING")
include_directories(
/usr/share/arduino/libraries/ArduinoJson/include
/usr/share/arduino/hardware/arduino/cores/arduino
)
set(files
DataHandler.h
DataHandler.cpp
JSON.cpp
JSON.h
HAL_mock.cpp
HAL_mock.h
HAL_Protocol.h
lib/ArduinoJson/ArduinoJson.h
)
# Locate GTest
find_package(GTest REQUIRED)
# Link runTests with what we want to test and the GTest library
add_executable(runTests DataHandlerTests.cpp JSONTests.cpp HALTests.cpp ${files})
target_link_libraries(runTests GTest::Main ArduinoJson)
The error I get
[ 14%] Building CXX object CMakeFiles/runTests.dir/JSONTests.cpp.o
In file included from /usr/share/arduino/libraries/ArduinoJson/include/ArduinoJson/Internals/../Internals/../String.hpp:14:0,
from /usr/share/arduino/libraries/ArduinoJson/include/ArduinoJson/Internals/../Internals/DynamicStringBuilder.hpp:11,
from /usr/share/arduino/libraries/ArduinoJson/include/ArduinoJson/Internals/../Internals/JsonPrintable.hpp:12,
from /usr/share/arduino/libraries/ArduinoJson/include/ArduinoJson/Internals/../JsonVariant.hpp:13,
from /usr/share/arduino/libraries/ArduinoJson/include/ArduinoJson/Internals/../JsonBuffer.hpp:14,
from /usr/share/arduino/libraries/ArduinoJson/include/ArduinoJson/Internals/BlockJsonBuffer.hpp:10,
from /usr/share/arduino/libraries/ArduinoJson/include/ArduinoJson/DynamicJsonBuffer.hpp:10,
from /usr/share/arduino/libraries/ArduinoJson/include/ArduinoJson.hpp:10,
from /usr/share/arduino/libraries/ArduinoJson/include/ArduinoJson.h:8,
from /usr/share/arduino/libraries/ArduinoJson/ArduinoJson.h:8,
from /home/zizyx/Desktop/git-sensorNetwerk/sensor-network/gtest/JSON.h:6,
from /home/zizyx/Desktop/git-sensorNetwerk/sensor-network/gtest/JSONTests.cpp:5:
/usr/share/arduino/hardware/arduino/cores/arduino/WString.h:29:26: fatal error: avr/pgmspace.h: No such file or directory
compilation terminated.
CMakeFiles/runTests.dir/build.make:86: recipe for target 'CMakeFiles/runTests.dir/JSONTests.cpp.o' failed
make[2]: *** [CMakeFiles/runTests.dir/JSONTests.cpp.o] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/runTests.dir/all' failed
make[1]: *** [CMakeFiles/runTests.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
I would like to add 2 maybe 3 lines which include all the libraries i need for my ArduinoJson library
I'm trying to compile a c++ program that uses xlib with cmake. However, I'm having a problem including and linking xlib libraries in cmake file.
This is the error that I'm getting.
main.cpp:378: undefined reference to `XClearWindow'
collect2: error: ld returned 1 exit status
CMakeFiles/project1.dir/build.make:94: recipe for target 'project1' failed
make[2]: *** [project1] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/project1.dir/all' failed
make[1]: *** [CMakeFiles/project1.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
And when I use just the command line to compile, it works just fine.
I use this command (g++ main.cpp -L/usr/X11R6/lib -lX11)
and this is my cmake file.
cmake_minimum_required(VERSION 3.6)
project(project1)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
link_directories(/usr/X11R6/lib)
include_directories(/usr/share/X11)
set(SOURCE_FILES main.cpp)
add_executable(project1 ${SOURCE_FILES})
In your case, you forgot to specify the libraries that cmake should use to link your application (target_link_libraries or link_libraries).
But, why not just let cmake find the required path, libraries and includes by itself? I suggest you to use find_package(X11). In your case, you can try:
cmake_minimum_required(VERSION 3.6)
project(project1)
set(CMAKE_CXX_STANDARD 11) # for c++11
find_package(X11 REQUIRED)
link_libraries(${X11_LIBRARIES})
include_directories(${X11_INCLUDE_DIR})
set(SOURCE_FILES main.cpp)
add_executable(project1 ${SOURCE_FILES})
I won't be able to explain why (if you have some idea, don't hesitate to comment my answer), but, in my case, I had to link X11 library using this command:
target_link_libraries( DisplayImage "-lX11" )
It works, at least, for the 3.5.1 version of cmake.