如何在Makefile中配置glib?
我正在使用 Eclipse CDT 开发 C 软件。我想使用 glib,但它总是报告“未解决的包含:”。我已经在我的 ubuntu 上安装了 glib:
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
我是 C 语言的新手。 虽然我找到了一些建议:
% gcc test.c -Wall -o test `pkg-config --cflags --libs glib-2.0`
但我不知道如何通过我的 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
有人可以帮助我吗?谢谢。
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) lt; -o $@
.cc.o:
$(CXX) -c $(CXXFLAGS) $(DFLAGS) $(INCLUDES) lt; -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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将其附加到您的 LIBS 指令的末尾:
并将其添加到您的 CXXFLAGS 和 CFLAGS:
这将完成这项工作。
Append this at the end of your LIBS directive:
And this to your CXXFLAGS and CFLAGS:
This will do the job.