'g_utf8_collate() not found in GLib-2.0 on Ubuntu 20.04.3 (LTS)

I've installed in my Ubuntu:

sudo apt-get install libglib2.0-dev
sudo apt-get install libgtk2.0-dev
sudo apt-get install libglib2.0-dev-bin

but this small test code fails to link:

cat -n test.c
     1  #include <stdio.h>
     2  #include <glib.h>
     3  
     4  int main()
     5  {
     6      char *p1 = "foo";
     7      char *p2 = "bar";
     8      int rc = 0;
     9  
    10      rc = g_utf8_collate(p1, p2);
    11      printf("g_utf8_collate(p1, p2) = %d\n", rc);
    12  }
cc -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -lm -L/usr/lib/x86_64-linux-gnu -lglib-2.0 test.c
/usr/bin/ld: /tmp/cc583STn.o: in function `main':
test.c:(.text+0x38): undefined reference to `g_utf8_collate'
collect2: error: ld returned 1 exit status

On all my other systems (SuSE Linux, FreeBSD) it links file, ofc with other -I and -L dirs.



Solution 1:[1]

Try

cc $(pkg-config --cflags --libs glib-2.0) test.c

pkg-config exists to provide the right compiler and linker flags for dependencies, so that you don’t have to specify them manually.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Philip Withnall