0

I am trying to include GLib2 in my CLion C project on Windows. I have installed glib2.0 via pacman on Msys2. The include (#include <glib-2.0/glib.h>) get's recognized by CLion.

My problem is that the include's in the glib.h are not getting recognized.

Error:

C:/msys64/mingw64/include/glib-2.0/glib.h:30:10: fatal error: glib/galloca.h: No such file or directory
   30 | #include <glib/galloca.h>
      |          ^~~~~~~~~~~~~~~~
compilation terminated.

But these 2 files exist on the filesystem:

glib-2.0/glib.h
glib-2.0/glib/galloca.h

CMakeLists.txt

cmake_minimum_required(VERSION 3.16)
project(task_2 C)

set(CMAKE_C_STANDARD 99)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)

include_directories(BEFORE "C:/msys64/mingw64/include/glib-2.0" "C:/msys64/mingw64/lib/glib-2.0/include")

add_executable(main src/main.c)
target_link_libraries(main ws2_32)
Furkan
  • 288
  • 1
  • 8
  • Did you install the 'dev' version of this package? See the response to [this](https://stackoverflow.com/q/21890576/3987854) question. – Kevin May 29 '20 at 21:34
  • i am using windows.. Is there a dev version for windows? – Furkan May 29 '20 at 21:57
  • Did you try installing [this](https://packages.msys2.org/package/glib2-devel?repo=msys&variant=x86_64)? – Kevin May 29 '20 at 22:03
  • I just did, unfortunately still the same error. – Furkan May 29 '20 at 22:11
  • Actually, it looks like you should change the include directory (potentially via CMake) to be this `C:/msys64/mingw64/include/glib-2.0`. Based on your errors, it would seem the include directory is `C:/msys64/mingw64/include`. – Kevin May 29 '20 at 22:18
  • That worked! But now I unfortunately get an "Undefined reference to `g_key_****`" for all glib-functions. Normally this shouldn't be that complicated, i don't know what i am doing wrong.. – Furkan May 29 '20 at 22:37
  • You need to **link** with `glib` library for use its functions. In CMake linking is performed with `target_link_libraries` command. – Tsyvarev May 30 '20 at 09:23

1 Answers1

1

The best way to get the compiler and linker flags for glib2 is via pkg-config, which is also available in MSYS2. Please see: How do I make clion work with following make and pkg-config?

Brecht Sanders
  • 6,215
  • 1
  • 16
  • 40