本文介绍了g ++递归地包含所有/ usr / include的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图编译一个简单的程序,使用

  #include< gtkmm.h> 

gtkmm.h 的路径是 /usr/include/gtkmm-2.4/gtkmm.h 。除非特别说明 -I /usr/include/gtkmm-2.4



我的问题是,如何让g ++自动查看 / usr / include 中所有包含在其中的头文件的所有目录,为什么这不是默认值在这种情况下,正确的做法是使用 pkg-config

code>在你的 Makefile 或构建脚本中:

 #Makefile 
ifeq($(shell pkg-config --modversion gtkmm-2.4),)
$(错误的包需要编译gtkmm-2.4)
endif

CXXFLAGS + =`pkg-config --cflags gtkmm-2.4`
LDLIBS + =`pkg-config --libs gtkmm-2.4`

BINS =程序
program_OBJS = ao bo ($)$(b








$(CXX)$(LDFLAGS)$ ^ $(LOADLIBES)$(LDLIBS )-o $ @

#这部分实际上是可选的,因为它被覆盖gmake的隐式规则
%.o:%.cc
$(CXX)-c $(CPPFLAGS)$(CXXFLAGS)$< -o $ @

如果您缺少 gtkmm-2.4 ,这将产生

 $ make 
在pkg-config搜索路径中找不到包gtkmm-2.4。
也许您应该将包含`gtkmm-2.4.pc'
的目录添加到PKG_CONFIG_PATH环境变量
无包'gtkmm-2.4'找到
Makefile:3:***包gtkmm-2.4需要编译。停止。

否则,您将获得所有适合您的路径和库,而无需手动指定它们。 (检查 pkg-config --cflags --libs gtkmm-2.4 的输出:这远远超过您想要手动输入的内容。)


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?

解决方案

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

# Makefile
ifeq ($(shell pkg-config --modversion gtkmm-2.4),)
  $(error Package gtkmm-2.4 needed to compile)
endif

CXXFLAGS += `pkg-config --cflags gtkmm-2.4`
LDLIBS += `pkg-config --libs gtkmm-2.4`

BINS = program
program_OBJS = a.o b.o c.o

all: $(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

$ make
Package 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 variable
No package 'gtkmm-2.4' found
Makefile: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 of pkg-config --cflags --libs gtkmm-2.4: that's far more than you want to type by hand, ever.)

这篇关于g ++递归地包含所有/ usr / include的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 18:34