Function g_utf8_collate() not found in GLib

I’ve here a rather small test example, which does not link on my L5 (Byzantium):

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

What I am missing here?

hmm, it’s impossible to write the Subject of the posting correctly with a small g: g_utf8_collate()

Try compiling with this command:

gcc test.c `pkg-config --cflags glib-2.0 --libs glib-2.0`

(I believe order is crucial - you need to have what you link with after the test.c in the command).

Yes. This order helps:

$ cc -I/usr/include/glib-2.0 -I/usr/lib/aarch64-linux-gnu/glib-2.0/include  test.c -L/usr/lib/aarch64-linux-gnu/ -lm -lglib-2.0

On FreeBSD it does not matter:

guru@vm-r368166:~/c $ rm a.out
guru@vm-r368166:~/c $ cc -I/usr/local/include/glib-2.0 -I/usr/local/lib/glib-2.0/include -L/usr/local/lib -lm -lglib-2.0 g-utf8.c
guru@vm-r368166:~/c $ ls -l a.out
-rwxr-xr-x  1 guru  wheel  17376 23 Mai  11:48 a.out


Checking some, it looks like cc on FreeBSD is the clang compiler by default, which would explain the difference. If you use clang instead of cc in the command, you will get the same behavior on PureOS.