6

I'm new to GTK and I'm using CLion IDE to code. I'm on Ubuntu and I've installed libgtk-3.0-dev . The headers I've added to my code is:

gtk-3.0

gtk-3.0/gtk/gtk.h

but when I want to build the project I get this error :

fatal error: gtk-3.0: No such file or directory

jcoppens
  • 5,306
  • 6
  • 27
  • 47
AmirAhmad
  • 153
  • 3
  • 12
  • 1
    First, you should `#include `, not `gtk-3.0/gtk/gtk.h`. Next, you need to tell CLion where the header files are located. I am not familiar with CLion, but [their FAQ](http://blog.jetbrains.com/clion/2014/09/clion-answers-frequently-asked-questions/) seems to contain some hint. You will also need to add some linker flags for the program to be successfully compiled. To get these flags you can use `pkg-config --cflags gtk+-3.0 gmodule-2.0` and `pkg-config --libs gtk+-3.0 gmodule-2.0`. – user12205 Jul 03 '15 at 01:12
  • In Windows You Can See This Link: http://stackoverflow.com/questions/38463809/how-to-create-gtk3-application-with-c-language-in-windows-with-clion-ide – samadadi Jul 19 '16 at 16:56

2 Answers2

15

I edited the CMakeLists file as as mentioned here and it worked.

Here is my CMakelists.txt:

cmake_minimum_required(VERSION 3.3)
project(gtk_test)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

set(SOURCE_FILES main.cpp)
add_executable(gtk_test ${SOURCE_FILES})

find_package(PkgConfig REQUIRED)
pkg_check_modules(GTK3 REQUIRED gtk+-3.0)

include_directories(${GTK3_INCLUDE_DIRS})
link_directories(${GTK3_LIBRARY_DIRS})

add_definitions(${GTK3_CFLAGS_OTHER})

target_link_libraries(gtk_test ${GTK3_LIBRARIES})

I'm using Clion 2016 and libgtk-3.0-dev on Ubuntu 15.04.

Petr R.
  • 1,247
  • 2
  • 22
  • 30
arnaud
  • 166
  • 2
  • 6
1

For GTK2, there is already a module call FindGTK2 defined under clion-2016.1.2/bin/cmake/share/cmake-3.5/Modules/FindGTK2.cmake. So just include it in your CMakeLists.txt.

include(FindGTK2)
if (GTK2_FOUND)
    include_directories(${GTK2_INCLUDE_DIRS})
    link_directories(${GTK2_LIBRARY_DIRS})
    link_libraries(${GTK2_LIBRARIES})
endif (GTK2_FOUND)
alijandro
  • 11,627
  • 2
  • 58
  • 74