windows上怎么用libnfc的库函数编程

 我来答
盘默M2
2016-01-25 · TA获得超过2.9万个赞
知道大有可为答主
回答量:9723
采纳率:93%
帮助的人:8185万
展开全部
windows上怎么用libnfc的库函数编程
根据libnfc的说明文档,我在win7上装了
libnfc-1.7.0-rc6.Zip
MinGW64
libusb-win32-bin-1.2.6.0
CMake -2.8.10-win32-x86

然后用mingw32-make命令编译成功,并产生了libnfc.dll文件,并且能够顺利运行nfc-list.exe等例子。
但是我想问一下,如果我想自己写一个.c文件,我该如何调用libnfc的头文件库和函数库编译它呢?

//test.cpp
#include
#include "libnfc_read_only\include\nfc\nfc.h"
using namespace std;

int main() {
cout << nfc_version() << "\n";
return 0;
}

我用 gcc -o test test.cpp -lnfc 命令编译,会报错说找不到头文件。我将之前编译成功的libnfc.dll文件放在同一目录下,仍然报错。
求指导:-)

解决方法:
(因为之前是在libnfc社区发的贴,回帖也是那里回的,所以直接粘贴过来了。我的英文有点烂,应该大意是能看懂的~)

I got it!
Thanks a lot for yobibe's help. I finally compiled it successfully, the steps are as follow:
Before that, I'll describe my files and directories:
The operating system is windows 7-32bit.
E:.
├─libnfc-1.7.0-rc6
│ ├─cmake
│ ├─contrib
│ ├─examples
│ ├─include
│ ├─libnfc
│ ├─libusb
│ ├─m4
│ ├─test
│ └─utils
│ ├─nfc-list.c
│ ├─CmakeList.txt
│ └─test.c

└─nfc_built
├─utils
│ ├─nfc-list.exe
│ └─libnfc.dll
├─libnfc
│ └─libnfc.dll

└─(and so on)
when the operation "Cmake-->mingw32-make" achieved, copy the E:\nfc_built\libnfc\libnfc.dll to E:\nfc_built\utils, and then open the cmd.exe window:
C:\Users\WangYong> cd :e\libnfc\nfc_built\utils
e\libnfc\nfc_built\utils> nfc-list.exe
nfc-list.exe will run and then print the result.
If you write a program by yourself, for example:
//test.c
#include
#include
int main()
{
printf("%s",nfc_version());
return 0;
}
Next you should put the test.c in the E:\libnfc\libnfc-1.7.0-rc5\utils, and modify the CmakeList.txt which is under the same directory(E:\libnfc\libnfc-1.7.0-rc5\utils) by adding the "test" to CmakeList.txt:
SET(UTILS-SOURCES
nfc-emulate-forum-tag4
nfc-list
nfc-mfclassic
nfc-mfultralight
nfc-read-forum-tag3
nfc-relay-picc
nfc-scan-device
test
)
Finally, do the mingw32make again, and then you will see the test.exe under E:\libnfc\nfc_built\utils. Run it:
E:\libnfc\nfc_built\utils> test.exe
ok! The version of libnfc will be printed on the cmd screen. You can also compile and run the quick_start_example1.c by this way. Good luck!
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式