This isn't a GLib problem (although you should probably use the C++ classes rather than the C versions), it's rather because quoted strings are const
. The function you're trying to use takes a void *
pointer rather than a const void *
pointer, which is what the error is trying to tell you.
Here's a fixed example:
#include <glib.h>
int main(){
GList *list = NULL;
list = g_list_append(list, (gpointer)"A1");
return 0;
}
...that casts the string to gpointer
(aka void *
) rather than const void *
. Compile e.g. with:
cc -Wall -o test test.c $(pkg-config --cflags --libs glib-2.0)
However, this is a bad idea as the string won't necessarily stick around in memory, causing the pointer to point to memory that is not yours, and cause a memory fault. A better idea (provided that you remember to free it later) might be to use g_strdup
which would duplicate the string in memory, or just to use the GLibmm-provided types as explained in the C++ version of the library's documentation.