How to configure glib in makefile?

I use Eclipse CDT for C software development. I would like to use glib, but it always says "Unresolved inclusion:". I installed glib on my ubuntu:

carl@Carl :~$ dpkg -l | grep libglib ii libglib-perl 2:1.223-1 ii libglib2.0-0 2.28.6-0ubuntu1 ii libglib2.0-bin 2.28.6-0ubuntu1 ii libglib2.0-cil 2.12.10-1ubuntu1 ii libglib2.0-data 2.28.6-0ubuntu1 ii libglib2.0-dev 2.28.6-0ubuntu1 ii libglib2.0-doc 2.28.6-0ubuntu1 ii libglibmm-2.4-1c2a 2.28.0-1 

I am new to C. Although I found some tips:

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

But I do not know how to make it work through my Makefile:

 CC= gcc CXX= g++ CFLAGS= -ggdb -g -Wall -O2 CXXFLAGS= $(CFLAGS) DFLAGS= -DHAVE_PTHREAD #-D_FILE_OFFSET_BITS=64 OBJS= rand.o PROG= peta INCLUDES= LIBS= -lm -lz -lpthread -Lbwt_gen -lbwtgen SUBDIRS= . bwt_gen .SUFFIXES:.c .o .cc .co: $(CC) -c $(CFLAGS) $(DFLAGS) $(INCLUDES) $< -o $@ .cc.o: $(CXX) -c $(CXXFLAGS) $(DFLAGS) $(INCLUDES) $< -o $@ all:$(PROG) lib-recur all-recur clean-recur cleanlocal-recur install-recur: @target=`echo $@ | sed s/-recur//`; \ wdir=`pwd`; \ list='$(SUBDIRS)'; for subdir in $$list; do \ cd $$subdir; \ $(MAKE) CC="$(CC)" CXX="$(CXX)" DFLAGS="$(DFLAGS)" CFLAGS="$(CFLAGS)" \ INCLUDES="$(INCLUDES)" $$target || exit 1; \ cd $$wdir; \ done; lib: peta:lib-recur $(OBJS) main.o $(CC) $(CFLAGS) $(DFLAGS) $(OBJS) main.o -o $@ $(LIBS) cleanlocal: rm -f gmon.out *.o a.out $(PROG) *~ *.a clean:cleanlocal-recur 

Can someone help me? Thanks.

+7
source share
1 answer

Add this at the end of your LIBS directive:

 $(shell pkg-config --libs glib-2.0) 

And this is for your CXXFLAGS and CFLAGS:

 $(shell pkg-config --cflags glib-2.0) 

This will complete the task.

+23
source

All Articles