Thread: 'glib-object.h' file not found

  1. #1
    Registered User
    Join Date
    Nov 2018
    Posts
    9

    'glib-object.h' file not found

    I have coded a piece of code on my Mac laptop and I want to execute it.
    When i execute the code (with
    Code:
    gcc main.c -o main
    ) I get the error 'glib-object.h' file not found.
    But I did installed glib via brew.
    What am I doing wrong?

    This is what I have in my include file:

    Code:
    #include <stdlib.h>
    #include <stdio.h>
    #include <glib-object.h>
    #include <json-glib/json-glib.h>

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    You need to find where glib-object.h was actually installed.
    Let's say for illustration that it was in /path/to/headers/glib-object.h

    Then your compilation command line would be
    gcc -I/path/to/headers main.c -o main

    Presumably, the header files also come with libraries as well.
    In which case, you also need to investigate the -L and -l options as well.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Feb 2019
    Posts
    1,078
    Linux?
    Code:
    $ pkg-config --list-all | grep ^glib
    glib-2.0         GLib - C Utility Library 
    $ pkg-config --cflags glib-2.0 
    -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include 
    $ pkg-config --libs glib-2.0 
    -lglib-2.0
    
    $ gcc -O2 $(pkg-config --cflags glib-2.0) -o test test.c \
       $(pkg-config --libs glib-2.0)
    Last edited by flp1969; 09-12-2019 at 05:06 PM.

  4. #4
    Registered User
    Join Date
    Nov 2018
    Posts
    9
    Linux is also possible:
    Is this what I need to enter in the Terminal?
    Because I get the error: error: No such file or directory

    Code:
    pkg-config --list-all | grep ^glib glib-2.0         GLib - C Utility Library 
    pkg-config --cflags glib-2.0 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include 
    pkg-config --libs glib-2.0 -lglib-2.0
    gcc -O2 $(pkg-config --cflags glib-2.0) -o test test.c \   $(pkg-config --libs glib-2.0)

  5. #5
    Registered User
    Join Date
    Feb 2019
    Posts
    1,078
    Quote Originally Posted by jenniferruurs View Post
    Linux is also possible:
    Is this what I need to enter in the Terminal?
    Because I get the error: error: No such file or directory

    Code:
    pkg-config --list-all | grep ^glib glib-2.0         GLib - C Utility Library 
    pkg-config --cflags glib-2.0 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include 
    pkg-config --libs glib-2.0 -lglib-2.0
    gcc -O2 $(pkg-config --cflags glib-2.0) -o test test.c \   $(pkg-config --libs glib-2.0)
    Code:
    $ pkg-config --list-all | grep ^glib
    Will give you the correct "package" name to use with pkg-config. The --cflags and --libs options gives you the options to use with gcc/clang.
    Install pkg-config package, if needed (I believe - not sure - it will be installed with build-essentials)...
    Last edited by flp1969; 09-13-2019 at 07:06 AM.

  6. #6
    Registered User
    Join Date
    May 2012
    Location
    Arizona, USA
    Posts
    945
    If you're going to put the whole command on a single line, you need to leave out the backslash:

    Code:
    gcc -O2 $(pkg-config --cflags glib-2.0) -o test test.c $(pkg-config --libs glib-2.0)
    A backslash is used to continue a command onto the next line.

  7. #7
    Guest
    Guest
    Also, consider switching to CMake unless close handling the compilation/linking process is desired (for learning).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can't compile glib
    By luofeiyu in forum Linux Programming
    Replies: 0
    Last Post: 07-18-2012, 01:27 AM
  2. glib & g_checksum_*
    By sbaginov in forum Linux Programming
    Replies: 5
    Last Post: 01-26-2011, 10:41 AM
  3. Replies: 60
    Last Post: 12-20-2005, 11:36 PM
  4. Glib and file manipulation
    By unixOZ in forum Linux Programming
    Replies: 1
    Last Post: 03-22-2004, 09:39 PM

Tags for this Thread