调用libpci库出现的问题和解决方法
调用libpci库出现的问题和解决方法
本方案以pciutils-3.5.1为例.
1. 从以下地址下载pciutils-3.5.1.tar.xz
https://www.kernel.org/pub/software/utils/pciutils/
2. 然后
[root@localhost terry]# xz –d pciutils-3.5.1.tar.xz
[root@localhost terry]tar xvf pciutils-3.5.1.tar
[root@localhost terry]# cd pciutils-3.5.1
[root@localhost pciutils-3.5.1]# make
就会发现在
[root@localhost pciutils-3.5.1]# ls lib/libpci.a
lib/libpci.a
**注意***
如果你需要动态的连接库,你只需要将Makefile改为
SHARED=yes
3. 写好自己的代码, 比如我写的如下:
#include
"pci.h"
bool PCIeVdp::getPCIConfig(PCI_CONFIG *pci_cfg, PCI_LOCATION *loc, int &pciCount)
{
struct pci_access *pacc;
struct pci_dev *dev;
unsigned
char data[256];
pciCount = 0;
memset(data, 0, sizeof(data));
pacc = pci_alloc(); /* Get the pci_access structure */
/* Set all options you want -- here we stick with the defaults */
pci_init(pacc); /* Initialize the PCI library */
pci_scan_bus(pacc); /* We want to get the list of devices */
for (dev=pacc->devices; dev; dev=dev->next) /* Iterate over all devices */
{
pci_fill_info(dev, PCI_FILL_IDENT | PCI_FILL_BASES | PCI_FILL_CLASS); /* Fill in header info we need */
for(int i=0;i<256;i++)
{
data[i] = pci_read_byte(dev, i);
}
memcpy((unsigned
char *)&pci_cfg[pciCount], data, 256);
loc[pciCount].bus_num = dev->bus;
loc[pciCount].dev_num = dev->dev;
loc[pciCount].func_num = dev->func;
pciCount++;
}
pci_cleanup(pacc); /* Close everything */
return
true;
}
需要将pciutils-3.5.1/lib下的pci.h, header.h, types.h以及libpci.a 拷贝到你的程序文件相同的目录.
4.运行make去编译,发现出现以下问题.
折腾了下,发现是因为libpci.a这个库是用C语言写的,而我的程序是用C++写的, 于是在pci.h的头和尾加上
#ifdef __cplusplus
extern
"C" {
#endif
#ifdef __cplusplus
}
#endif
问题解决.
5. 可是新的问题有出现了
查了下发现是我的makefile中没有加载libz,于是修改makefile如下
LIB+=-ldl -lz -lpthread ./libpci.a
发现问题解决,编译顺利通过.
最新文章
- aws在线技术峰会笔记-游戏解决方案
- XAF应用开发教程(三)业务对象模型之引用类型与关联关系
- Hibernate理论
- sharepreferce支持boolean,string类型
- 设置IE浏览器代理上网
- 建索引让SQL飞起来
- uboot从SD卡烧写内核和文件系统
- flash播放器遮挡页面中元素问题解决
- 设计一个有getMin功能的栈(2)
- DML数据操作语言之查询(二)
- 编程之美2.18 数组分割 原创解O(nlogn)的时间复杂度求解:
- CSS&;JS小结
- mybatis-plus报org.apache.ibatis.binding.BindingException分析【转载】
- C# -- 使用XmlDocument或XDocument创建xml文件
- vim鼠标模式打开与关闭
- 2156: 中南大学2018年ACM暑期集训前期训练题集(入门题) D: 机器人的指令
- async和await用法(Task)
- linux grep 正则表达式
- (转)mysql创建表时反引号的作用
- Docker深入浅出1
热门文章
- codeforces#505--B Weakened Common Divisor
- 数据去重优化 MemoryError 内存不足
- 验证ip地址
- Mongodb3.X版本的 的用户认证
- SprinBoot CLI 安装(Mac版)
- Unity-DLL反编译学习
- android 异步线程刷新UI 以及 JSON解析 以及 url get请求
- centos shell编程4【分发系统】 服务器标准化 mkpasswd 生成密码的工具 expect讲解 expect传递参数 expect自动同步文件 expect指定host和要同步的文件 expect文件分发系统 expect自动发送密钥脚本 Linux脚本执行方式 第三十八节课
- poi根据模板导出word文档
- sipp保持sip协议的tcp长连接