c - Error compiling with GLib -


i'm pretty new c programming, , trying work through exercises in '21st century c' second edition. i'm stuck on page 202, example 9-7, unicode.c. example starts with:

#include <glib.h> #include <locale.h> //setlocale #include "string_utilities.h" #include "stopif.h"  //frees instring you--we can't use else. char *localstring_to_utf8(char *instring){     gerror *e=null;     setlocale(lc_all, ""); //get os's locale.     char *out = g_locale_to_utf8(instring, -1, null, null, &e);     free(instring); //done original     stopif(!out, return null, "trouble converting locale utf-8.");     stopif(!g_utf8_validate(out, -1, null), free(out); return null,             "trouble: couldn't convert file valid utf-8 string.");     return out; } 

when try compile with:

c99 -i/usr/include/glib-2.0 -i/usr/lib/x86_64-linux-gnu/glib-2.0/include -g -wall -o3 -lglib-2.0 unicode.c string_utilities.o   -o unicode 

i errors such as:

$ c99 -i/usr/include/glib-2.0 -i/usr/lib/x86_64-linux-gnu/glib-2.0/include -g -wall -o3 -lglib-2.0 unicode.c string_utilities.o   -o unicode /tmp/ccbdqfih.o: in function `localstring_to_utf8': /home/kevin/21st_century_c/ch09/unicode.c:29: undefined reference `g_locale_to_utf8' /home/kevin/21st_century_c/ch09/unicode.c:32: undefined reference `g_utf8_validate' /tmp/ccbdqfih.o: in function `main': /home/kevin/21st_century_c/ch09/unicode.c:48: undefined reference `g_utf8_strlen' 

this seems indicate glib library not found, compiler didn't complain this, , glib libraries , include files right specified on command line. i've installed libglib2.0-dev package in addition libglib2.0 package (all installed 'sudo apt-get ..'). 'pkg-config' seems find glib-2.0 fine.

this on ubuntu 14.04.2 system.

i can't figure out how correct error, , don't understand why can't find specific glib functions, if finds glib include , lib files.

the order of things in command line matter. in general should like:

gcc [options] [source files] [object files] [-l stuff] [-lstuff] [-o outputfile] 

so give whirl instead:

gcc -g -wall -o3 -std=gnu11 `pkg-config --cflags glib-2.0` \     unicode.c string_utilities.o `pkg-config --libs glib-2.0` \     -o unicode 

this covered in compiling glib applications section of glib reference manual:

$ cc hello.c `pkg-config --cflags --libs glib-2.0` -o hello 

Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -