Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to config glib in Makefile?

Tags:

makefile

glib

I am using Eclipse CDT to develop a C software. I would like to use glib, but it always reports "Unresolved inclusion: ". I have 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 a freshman to C. Although I found some suggestions:

% 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

.c.o:
        $(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

Could anybody help me? Thanks.

like image 516
Joy Avatar asked Oct 21 '11 08:10

Joy


1 Answers

Append this at the end of your LIBS directive:

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

And this to your CXXFLAGS and CFLAGS:

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

This will do the job.

like image 66
moongoal Avatar answered Oct 19 '22 12:10

moongoal