Linux下編譯安裝libnfc

     最近從朋友那裏借來了兩塊PN532板子玩,在電腦上編譯安裝libnfc的時候大費周折,泡了將近一天的罈子,終於安裝成功了,這裏把這個安裝過程記錄了一下。

首先安裝編譯需要的庫

$ sudo apt-get install libusb-dev libpcsclite-dev libusb-0.1-4 libpcsclite1 libccid pcscd

下載libnfc源碼包

可以到google code下載官方包(https://code.google.com/p/libnfc/downloads/list),不過貌似google code在國內用不是很穩定,我下了n多次才下好,把它傳到百度網盤上(http://pan.baidu.com/s/1sjCVliX

解壓、配置、安裝

$ tar -xvzf libnfc-1.7.0-rc7.tar.gz
$ cd libnfc-1.7.0-rc7$ ./configure --with-drivers=pn532_uart
$ make
$ make install

安裝完成後驗證安裝是否成功:

將PN532插入PC USB接口運行nfc-list示例程序
$ sudo nfc-list
出現以下信息則表示安裝成功:

nfc-list uses libnfc 1.7.0-rc7                              
NFC device: pn532_uart:/dev/ttyUSB0 opened

如果顯示:

情況一:

No NFC device found.

則安裝失敗,這時候請檢查/usr/local/etc/目錄下是否有nfc文件夾。如果沒有,請在/usr/local/etc/目錄下新建nfc文件夾,然後在nfc文件夾下新建一個文件,保存爲libnfc.conf,文件內容如下:
# Allow device auto-detection (default: true)
# Note: if this auto-detection is disabled, user has to set manually a device
# configuration using file or environment variable
# allow_autoscan = true
# Allow intrusive auto-detection (default: false)
# Warning: intrusive auto-detection can seriously disturb other devices
# This option is not recommended, user should prefer to add manually his device.
# allow_intrusive_autoscan = true
# Set log level (default: error)
# Valid log levels are (in order of verbosity): 0 (none), 1 (error), 2 (info), 3 (debug)
# Note: if you compiled with --enable-debug option, the default log level is "debug"
# log_level = debug
# Manually set default device (no default)
# To set a default device, you must set both name and connstring for your device
# Note: if autoscan is enabled, default device will be the first device available in device list.
device.name = "microBuilder.eu"
#device.connstring = "pn532_uart:/dev/ttyAMA0"
device.connstring = "pn532_uart:/dev/ttyUSB0"

保存退出後再次嘗試,問題解決。

情況二:

nfc-list: error while loading shared libraries: libnfc.so.4: cannot open shared object file: No such file or directory

打開終端執行如下命令

# sudo su
# echo "/usr/local/lib" >> /etc/ld.so.conf.d/loc_lib.conf
# /sbin/ldconfig

我暫時就遇到了這兩個問題,其他的問題我從網上找了些資料,大家可自行參閱。問題彙集


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章