g++ include all /usr/include recursively

来源:互联网 发布:周杰伦才华 知乎 编辑:程序博客网 时间:2024/06/05 14:57

6down votefavorite

2

I'm trying to compile a simple program, with

#include <gtkmm.h>

The path to gtkmm.h is /usr/include/gtkmm-2.4/gtkmm.h. g++ doesn't see this file unless I specifically tell it-I /usr/include/gtkmm-2.4.

My question is, how can I have g++ automatically look recursively through all the directories in/usr/include for all the header files contained therein, and why is this not the default action?





14down voteaccepted

In this case, the correct thing to do is to use pkg-config in yourMakefile or buildscripts:

# Makefileifeq ($(shell pkg-config --modversion gtkmm-2.4),)  $(error Package gtkmm-2.4 needed to compile)endifCXXFLAGS += `pkg-config --cflags gtkmm-2.4`LDLIBS += `pkg-config --libs gtkmm-2.4`BINS = programprogram_OBJS = a.o b.o c.oall: $(BINS)program: $(program_OBJS)        $(CXX) $(LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@# this part is actually optional, since it's covered by gmake's implicit rules%.o: %.cc        $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $< -o $@

If you're missing gtkmm-2.4, this will produce

$ makePackage gtkmm-2.4 was not found in the pkg-config search path.Perhaps you should add the directory containing `gtkmm-2.4.pc'to the PKG_CONFIG_PATH environment variableNo package 'gtkmm-2.4' foundMakefile:3: *** Package gtkmm-2.4 needed to compile.  Stop.

Otherwise, you'll get all the appropriate paths and libraries sucked in for you, without specifying them all by hand. (Check the output ofpkg-config --cflags --libs gtkmm-2.4: that's far more than you want to type by hand, ever.)



http://stackoverflow.com/questions/510098/g-include-all-usr-include-recursively

0 0
原创粉丝点击