I have been using the Clion IDE and am trying to get a simple GTK program to compile using it. I have found that Clion uses CMake, so the issues is here rather than with the IDE itself. I am able to successfully compile and run the program directly from the terminal but have been unsuccessful using CMake.
The problem is simple: when I attempt to compile, the compiler cannot find gtk.h, which is located in /usr/include/gtk-3.0/gtk/gtk.h. I have found that somehow the command compiler argument 'pkg-config --libs --cflags gtk+-3.0' fixes this problem but I have been unable to add this argument using CMake.
I have tried:
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} `pkg-config --libs --cflags gtk+-3.0`")
But am met with:
Linking CXX executable test
c++: error: `pkg-config: No such file or directory
c++: error: gtk+-3.0`: No such file or directory
c++: error: unrecognized command line option ‘--libs’
c++: error: unrecognized command line option ‘--cflags’
make[3]: *** [test] Error 1
make[2]: *** [CMakeFiles/test.dir/all] Error 2
make[1]: *** [CMakeFiles/test.dir/rule] Error 2
make: *** [test] Error 2
Any suggestions?
Further research has revealed this tutorial precisely on the issue I am having. It works like a charm but appears to throw many seemingly undefined variables into the mix. Can anyone explain how and why this works?
# Set the name and the supported language of the project
project(hello-world C)
# Set the minimum version of cmake required to build this project
cmake_minimum_required(VERSION 2.6)
# Use the package PkgConfig to detect GTK+ headers/library files
find_package(PkgConfig REQUIRED)
pkg_check_modules(GTK3 REQUIRED gtk+-3.0)
# Setup CMake to use GTK+, tell the compiler where to look for headers
# and to the linker where to look for libraries
include_directories(${GTK3_INCLUDE_DIRS})
link_directories(${GTK3_LIBRARY_DIRS})
# Add other flags to the compiler
add_definitions(${GTK3_CFLAGS_OTHER})
# Add an executable compiled from hello.c
add_executable(hello main.c)
# Link the target to the GTK+ libraries
target_link_libraries(hello ${GTK3_LIBRARIES})
/usr/includein thePATH(environment) variable? That isn't at all useful./usr/local... I know that, for example,iostreamis located at/usr/include/c++... If such a directory is not in the PATH, how does the compiler know where to find these headers?PATHis used by the shell for finding binaries. The compiler uses a built-in set of locations and any locations indicated by the-Iflag.