根據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 <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.exe
nfc-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.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!