g++ include all /usr/include recursively(g++ 递归包含所有/usr/include)
问题描述
我正在尝试用
#include <gtkmm.h>
gtkmm.h
的路径是 /usr/include/gtkmm-2.4/gtkmm.h
.g++ 看不到这个文件,除非我特别告诉它-I/usr/include/gtkmm-2.4
.
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
.
我的问题是,如何让 g++ 自动递归查看 /usr/include
中包含的所有头文件的所有目录,为什么这不是默认操作?
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?
推荐答案
在这种情况下,正确的做法是在你的 Makefile
中使用 pkg-config
或构建脚本:
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 $@
如果您缺少 gtkmm-2.4
,这将产生
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.
否则,您将获得所有合适的路径和库,而无需手动指定它们.(检查 pkg-config --cflags --libs gtkmm-2.4
的输出:这远远超过您想要手动输入的内容.)
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:g++ 递归包含所有/usr/include
基础教程推荐
- C++ 程序在执行 std::string 分配时总是崩溃 2022-01-01
- 运算符重载的基本规则和习语是什么? 2022-10-31
- C++,'if' 表达式中的变量声明 2021-01-01
- 什么是T&&(双与号)在 C++11 中是什么意思? 2022-11-04
- C++ 标准:取消引用 NULL 指针以获取引用? 2021-01-01
- 您如何将 CreateThread 用于属于类成员的函数? 2021-01-01
- 如何定义双括号/双迭代器运算符,类似于向量的向量? 2022-01-01
- 调用std::Package_TASK::Get_Future()时可能出现争用情况 2022-12-17
- 如何在 C++ 中处理或避免堆栈溢出 2022-01-01
- 设计字符串本地化的最佳方法 2022-01-01