[TOC]
背景
在编译安装软件时候, 经常会遇到某个 .h 文件找不到的报错, 例如:
致命错误:mysql.h:没有那个文件或目录
这种原因, 一般是 系统的$LD_LIBRARY_PATH
目录下找不到对应的文件, 这里就是找不到 mysql.h
, 这时候一般可以通过安装软件包(rpm或deb)解决. 但是我们如何知道哪个软件包, 包含这个文件呢? 这里有一些命令可以帮的上忙.
处理方案
RedHat/CentOS
可以通过yum provides
命令查找
yum provides "*/文件名"
注意: 根据yum provides
文档, 我们必须使用在文件前面使用通配符*/
代表文件前面的路径.
例如:
yum provides "*/mysql.h"
结果:
1:mariadb-devel-5.5.68-1.el7.i686 : Files for development of MariaDB/MySQL applications
Repo : base
Matched from:
Filename : /usr/include/mysql/mysql.h
1:mariadb-devel-5.5.68-1.el7.x86_64 : Files for development of MariaDB/MySQL applications
Repo : base
Matched from:
Filename : /usr/include/mysql/mysql.h
Ubuntu/Debian
# 更新本地库
apt-file update
# 搜索文件所属 dep 文件
apt-file search "文件名"
PS: 如果遇到 Command 'apt-file' not found
, 先安装apt-file
apt install -y apt-file
例如:
apt-file update
apt-file search "mysql.h"
得到:
pike7.8-reference: /usr/share/doc/pike7.8-doc/html/reference/ex/predef_3A_3A/Sql/mysql.html
pike8.0-doc: /usr/share/doc/pike8.0-doc/html/reference/ex/predef_3A_3A/Mysql/mysql.html
pike8.0-doc: /usr/share/doc/pike8.0-doc/html/reference/ex/predef_3A_3A/Sql/mysql.html
python-azure-doc: /usr/share/doc/python-azure/html/ref/azure.mgmt.rdbms.mysql.html
python-sqlalchemy-doc: /usr/share/doc/python-sqlalchemy-doc/html/dialects/mysql.html
libgearman-doc: /usr/share/doc/libgearman-doc/html/gearmand/queues/mysql.html
libmariadb-dev: /usr/include/mariadb/mysql.h
libmariadbclient-dev: /usr/include/mysql/mysql.h
libmariadbclient-dev: /usr/include/mysql/private/probes_mysql.h
libmysqlclient-dev: /usr/include/mysql/mysql.h
libodb-mysql-dev: /usr/include/odb/mysql/mysql.hxx
有时候觉得结果有些文件名根本不对, 可以增加grep
命令筛选结果:
apt-file search "mysql.h" | grep -E '/mysql.h$'
得到:
libmariadb-dev: /usr/include/mariadb/mysql.h
libmariadbclient-dev: /usr/include/mysql/mysql.h
libmariadbclient-dev: /usr/include/mysql/private/probes_mysql.h
libmysqlclient-dev: /usr/include/mysql/mysql.h
网友评论