Use GLib in CLion - c++

I trying to compile my test GLib project using CLion. So I added #include "glib-2.0/glib.h" in my cpp file and added include_directories(/usr/include/glib-2.0/glib) in my CMakeLists.txt. But got output in CLion:
fatal error: glib/galloca.h: No such file or directory
So how I can correctly use GLib in my project in CLion?

Here's the skeleton I use for glib on my Mac (glib2 and pkgconfig installed via MacPorts):
cmake_minimum_required(VERSION 3.1)
project(HelloGlib)
include(FindPkgConfig)
pkg_check_modules(GLIB glib-2.0 REQUIRED)
include_directories(${GLIB_INCLUDE_DIRS})
set(SOURCE_FILES main.c)
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
target_link_libraries(${PROJECT_NAME} ${GLIB_LIBRARIES})

The include directory is supposed to be /usr/include/glib-2.0 not /usr/include/glib-2.0/glib. Or, more portably, pkg-config --cflags glib-2.0.

Related

I can't get gtkmm to compile on Mac using CMake

I'm attempting to set up an environment in which I can use gtkmm for C++ development. My CMakeLists.txt file looks like this:
cmake_minimum_required(VERSION 3.0.2)
project(program)
find_package(PkgConfig)
pkg_check_modules(GTKMM gtkmm-3.0)
link_directories(${GTKMM_LIBRARY_DIRS})
include_directories(include ${GTKMM_INCLUDE_DIRS})
file(GLOB SOURCES "*.cpp")
add_executable(program ${SOURCES})
target_link_libraries(program ${GTKMM_LIBRARIES})
Yet when I try to include the line include <gtkmm.h> in main I am met with this error from CMake:
fatal error: 'gtkmm.h' file not found
#include <gtkmm.h>
I installed gtkmm with brew using the command brew install gtkmm and brew install gtkmm3 to insure versions were not the issue. What can I do to get this working?
Be sure to install pkg-config (using brew).
Here is a CMakeLists.txt file that will work:
cmake_minimum_required(VERSION 3.16)
project(program LANGUAGES CXX)
find_package(PkgConfig)
pkg_check_modules(GTKMM gtkmm-3.0)
add_executable(program)
target_compile_features(program PRIVATE cxx_std_17)
target_sources(program PRIVATE main.cpp)
target_include_directories(program PRIVATE ${GTKMM_INCLUDE_DIRS})
target_link_directories(program PRIVATE ${GTKMM_LIBRARY_DIRS})
target_link_libraries(program PRIVATE ${GTKMM_LIBRARIES})

Building wxWidgets 3.1.0 on CLion (Ubuntu)

I am currently trying to build wxWidgets-3.1.0 on a CLion 1.3 project. I use Ubuntu 16.04 (64 bit). Basically, I edited the CMakeLists.txt file like this:
cmake_minimum_required(VERSION 3.5)
project(WxProva)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules"
${CMAKE_MODULE_PATH})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp)
add_executable(WxProva ${SOURCE_FILES})
find_package(wxWidgets)
include_directories(${wxWidgets_INCLUDE_DIRS})
target_link_libraries(WxProva ${wxWidgets_LIBRARIES})
The "External Libraries" section also shows me wxWidgets, but when it comes to write some lines on my main.cpp, everything related with the library seems to be unreachable by the compiler (it's all written in red, like an error). Anyway, if I try to compile, that's the result:
/home/federico/ClionProjects/WxProva/main.cpp:2:35: fatal error: wxWidgets-3.1.0/include: File o directory non esistente
compilation terminated.
Which is like "File or directory doesn't exists."
How can I fix this?
After some experiments here solution. You can just copy it and change some information and ready to build and run.
cmake_minimum_required(VERSION 3.7)
project(Your_Project_Name) //any name for your project
set(CMAKE_CXX_STANDARD 11)
set(wxWidgets_ROOT_DIR </usr/include/wx-3.0-unofficial>) // here I am giving where to search for wxwidgets library. it can be different for you
set(wxWidgets_CONFIGURATION mswu)
find_package(wxWidgets COMPONENTS core base REQUIRED)
include(${wxWidgets_USE_FILE})
set(SOURCE_FILES main.cpp)
add_executable(FirstC ${SOURCE_FILES})
target_link_libraries(FirstC ${wxWidgets_LIBRARIES})
For more Information read https://wiki.wxwidgets.org/CMake
Edit 1
Here you shouldn't even add some compile and link config (wx-config --cxxflags and wx-config --libs) as it is necessary in NetBeans
Here is example configuration for macOS 10.14.4 (Mojave) and CLion 2019.1
(/usr/local is folder where I installed wxWidgets)
cmake_minimum_required(VERSION 3.14)
project(wx1Test)
set(CMAKE_CXX_STANDARD 14)
set(wxWidgets_ROOT_DIR </usr/local/include/wx-3.1>)
set(wxWidgets_CONFIGURATION mswu)
find_package(wxWidgets COMPONENTS core base REQUIRED)
include(${wxWidgets_USE_FILE})
set(SOURCE_FILES main.cpp)
add_executable(wx1Test ${SOURCE_FILES})
target_link_libraries(wx1Test ${wxWidgets_LIBRARIES})

Getting SDL2 to work on Clion, Windows 10 using MinGW

I cannot for the life of me get SDL2 to work with my programming group's project.
I'm using
-Clion 1.2.1
-SDL 2.0.3
-MinGW 5.0
The compiler starts yelling at me from within the Graphics.h file which includes SDL like so:
#include <SDL.h>
#include <SDL_image.h>
with the error being:
fatal error: SDL.h: No such file or directory
compilation terminated.
I tried including with
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
which still yielded the same error.
I downloaded SDL from the MinGW 32/64-bit download of development libraries from: https://www.libsdl.org/download-2.0.php. I also linked the respective ..\SDL2\x86_64-w64-mingw32\include and lib to path in system->advanced system settings->...
Still nothing.
cmake_minimum_required(VERSION 3.3)
project(ClionProjects)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -lsdl2")
set(SOURCE_FILES
Kod/Graphics/Graphics.cc
Kod/Graphics/Graphics.h
Kod/Game/Game.cc
Kod/Game/Game.h
Kod/Gameboard/Gameboard.cc
Kod/Gameboard/Gameboard.h
Kod/Meeple/Meeple.cc
Kod/Meeple/Meeple.h
Kod/Player/Player.cc
Kod/Player/Player.h
Kod/Resource/Resource.cc
Kod/Resource/Resource.h
Kod/Tile/Tile.cc
Kod/Tile/Tile.h
Kod/Carcassonne.cc)
add_executable(ClionProjects ${SOURCE_FILES} Kod/Carcassonne.cc)
target_link_libraries(ClionProjects SDL2main SDL2 SDL2_image)
is the cmakefile I have in Clion. I've been bashing my head bloody trying to get this to work and none of the previous Stackoverflow questions managed to solve my issue.
Personally I uses MSYS2 in my project. The MINGW64 vesion of SDL2 and the other library were installed, as well as the other toolchains like gcc, cmake, and pkg-config (toolchains are MINGW64 version as well).
Then I point my CLion toolchain configuration to the c:\msys2\mingw64, given that I install the msys2 at c:\msys2.
The FindPkgConfig CMake module is used to locate the SDL2 library and include files location.
Please find the example below (I also use FreeType2 and harfbuzz as well). The important part is the FindPkgConfig part (pkg_check_modules) and include/link part.
Make sure to reload the configuration after you have modified the cmake file.
cmake_minimum_required (VERSION 2.6)
project (pgengine)
# The version number.
set (Tutorial_VERSION_MAJOR 0)
set (Tutorial_VERSION_MINOR 1)
add_definitions(-std=c++11)
aux_source_directory(src SRC_LIST)
aux_source_directory(src/game SRC_LIST)
aux_source_directory(src/graphics SRC_LIST)
aux_source_directory(src/sound SRC_LIST)
aux_source_directory(src/system SRC_LIST)
aux_source_directory(src/visual_novel SRC_LIST)
add_executable(${PROJECT_NAME} ${SRC_LIST})
INCLUDE(FindPkgConfig)
pkg_check_modules(FREETYPE2 REQUIRED freetype2)
pkg_check_modules(HARFBUZZ REQUIRED harfbuzz)
pkg_check_modules(SDL2 REQUIRED sdl2)
pkg_check_modules(SDL2_IMAGE REQUIRED SDL2_image)
pkg_check_modules(SDL2_MIXER REQUIRED SDL2_mixer)
include_directories(${SDL2_INCLUDE_DIRS}
${SDL2_IMAGE_INCLUDE_DIRS}
${SDL2_MIXER_INCLUDE_DIRS}
${FREETYPE2_INCLUDE_DIRS}
${HARFBUZZ_INCLUDE_DIRS})
link_directories (${SDL2_LIBRARY_DIRS}
${SDL2_IMAGE_LIBRARY_DIRS}
${SDL2_MIXER_LIBRARY_DIRS}
${FREETYPE2_LIBRARY_DIRS}
${HARFBUZZ_LIBRARY_DIRS})
target_link_libraries (pgengine ${SDL2_LIBRARIES}
${SDL2_IMAGE_LIBRARIES}
${SDL2_MIXER_LIBRARIES}
${FREETYPE2_LIBRARIES}
${HARFBUZZ_LIBRARIES})
This has been tested on Windows (MSYS2) and Linux.

Include Eigen library for Xcode project via CMake/CMakeLists.txt

I've got the following CMakeLists.txt (in my "project" folder) file for my project.
# define new project
PROJECT(SETUPMARKERTEST)
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.0 FATAL_ERROR)
if(UNIX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif(UNIX)
# Set static build for GLFW
SET(BUILD_SHED_LIBS OFF)
ADD_SUBDIRECTORY(ext/glfw-3.1.1)
# Set shared lib build for the rest
SET(BUILD_SHARED_LIBS ON)
# Find dependencies
SET(EIGEN_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/ext/Eigen-3.1.2")
FIND_PACKAGE(OpenCV REQUIRED)
# Set header and source files
SET(MAR_Test_SOURCES
src/main.cpp
src/MarkerTracker.h src/MarkerTracker.cpp
src/PoseEstimation.h src/PoseEstimation.cpp
)
# define executable
ADD_EXECUTABLE(${PROJECT_NAME} ${MAR_Test_SOURCES})
# define additional include directories and linking targets
INCLUDE_DIRECTORIES("ext/glfw-3.1.1/include" ${EIGEN_INCLUDE_DIR} ${OpenCV_INCLUDE_DIRS})
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${OpenCV_LIBS} glfw ${OPENGL_glu_LIBRARY} ${GLFW_LIBRARIES})
And my Eigen folder is in "project/ext/Eigen/3.1.2/Eigen/".
Somehow when I created my project for Xcode (in "project/buildXcode/" with Cmake .. -G "Xcode") and run it, Xcode throws me the error:
So I guess there is some error in my CMakeLists.txt, unfortunately I received that file and I'm new to CMake and thus didn't write it on my own nor am I very skilled with CMake.
Do you know what causes the error and can you fix the CMakeLists.txt that my project runs with the Eigen library?
Unfortunately it looks like windows is having no problem with this, whereas mac is bleating.
You just have to use
#include <Eigen/Dense>
instead of
#include <Eigen\Dense>
...pretty stupid error.

Cannot find QCursor in Qt CMake Project

I'm trying to build an application on Linux with Qt where I can set the Cursor position. The project is managed with CMake.
CMakeLists.txt:
cmake_minimum_required(VERSION 2.8.4)
project(Project)
add_definitions(-std=gnu++14 -std=c++14 -Wall -Wextra)
set(CMAKE_PREFIX_PATH "/home/elmewo/Libraries/Qt/5.3/gcc_64")
set(CMAKE_AUTOMOC ON)
find_package(Qt5Core REQUIRED)
find_package(Qt5Quick REQUIRED)
find_package(Qt5Gui REQUIRED)
include_directories(${CMAKE_SOURCE_DIR}/src)
set(SOURCE_FILES src/main.cpp)
add_executable(Project ${SOURCE_FILES})
qt5_use_modules(Project Core Quick Gui)
The packages are found by CMake. But when I try to
#include <QCursor>
my compiler says
fatal error: QCursor: file or directory not found
I was able to compile another basic QGuiApplication on the same machine.
The QCursor file is situated in ${CMAKE_PREFIX_PATH}/include/QtGui.
Am I missing something?
It seems that you are depending on 2.8.4, so at least you either need to change your build rules based on this or you will need to upgrade the dependency to at least cmake version 2.8.9:
Using Qt 5 with CMake older than 2.8.9
If using CMake older than 2.8.9, the qt5_use_modules macro is not available. Attempting to use it will result in an error.
To use Qt 5 with versions of CMake older than 2.8.9, it is necessary to use the target_link_libraries, include_directories, and add_definitions commands, and to manually specify moc requirements with either qt5_generate_moc or qt5_wrap_cpp:
Therefore, please add these if you stick with old cmake:
# Add the include directories for the Qt 5 Widgets module to
# the compile lines.
include_directories(${Qt5Core_INCLUDE_DIRS} ${Qt5Gui_INCLUDE_DIRS} ${Qt5Quick_INCLUDE_DIRS})
#Link the helloworld executable to the Qt 5 widgets library.
target_link_libraries(helloworld Qt5::Core Qt5::Gui Qt5::Quick)