根据libnfc的说明文档,我在win7上装了
libnfc-1.7.0-rc6.Zip
然后用mingw32-make命令编译成功,并产生了libnfc.dll文件,并且能够顺利运行nfc-list.exe等例子。
但是我想问一下,如果我想自己写一个.c文件,我该如何调用libnfc的头文件库和函数库编译它呢?
//test.cpp
#include <iostream>
#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文件放在同一目录下,仍然报错。
求指导:-)
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.exenfc-list.exe will run and then print the result.
If you write a program by yourself, for example:
//test.c#include <stdio.h>#include <nfc\nfc.h>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.exeok! 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!