nfc-tools / libnfc

Platform independent Near Field Communication (NFC) library
http://nfc-tools.org
GNU Lesser General Public License v3.0
1.64k stars 436 forks source link

CMake expects lusb0_usb.h to be accessible for libnfc/buses/usbbus.h #720

Closed tol-va closed 3 months ago

tol-va commented 3 months ago

I am on Windows 11 and I'm trying to build a dll for libnfc. It should work from what I can tell based on the Configure step passing in the GUI. I set the path variables in Powershell and then I ran CMake. When I try to build, a fatal error prevents the dll from being generated. Can you provide some insight into what I am doing wrong?

SET PATH=%PATH%;"D:\mingw64\bin";"D:\mingw64\x86_64-w64-mingw32\lib32";"D:\mingw64\x86_64-w64-mingw32\include\"

I added a wildcard to the src path to see if that would help.


PS D:\tools\libnfc-build> cmake -G "MinGW Makefiles" -DMAKE_BUILD_TYPE=Release ..\libnfc-master -DLIBUSB_INCLUDE_DIRS="D:\tools\libusb" -DLIBUSB_LIBRARIES="D:\tools\libusb\src\*" -DMAKE_BUILD_TYPE="Release"
CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required):
  Compatibility with CMake < 3.5 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.

Building 64-bit Windows DLL
-- Found LIBUSB: D:/tools/libusb/src/* D:/tools/libusb
-- Found LIBUSB: D:/tools/libusb/src/* D:/tools/libusb
-- Found LIBUSB: D:/tools/libusb/src/* D:/tools/libusb
-- Configuring done (0.3s)
-- Generating done (0.4s)
-- Build files have been written to: D:/tools/libnfc-build
PS D:\tools\libnfc-build> cmake --build . --config Release
[  1%] Building C object libnfc/CMakeFiles/nfc.dir/drivers/acr122_usb.c.obj
In file included from D:/tools/libnfc-build/config.h:1:0,
                 from D:\tools\libnfc-master\libnfc\drivers\acr122_usb.c:50:
D:/tools/libnfc-master/contrib/windows.h:47:0: warning: "ETIMEDOUT" redefined
 #    define ETIMEDOUT     WSAETIMEDOUT
 ^
In file included from D:/tools/TDM-GCC-64/lib/gcc/x86_64-w64-mingw32/5.1.0/include/mm_malloc.h:28:0,
                 from D:/tools/TDM-GCC-64/lib/gcc/x86_64-w64-mingw32/5.1.0/include/xmmintrin.h:34,
                 from D:/tools/TDM-GCC-64/lib/gcc/x86_64-w64-mingw32/5.1.0/include/x86intrin.h:31,
                 from D:/tools/TDM-GCC-64/x86_64-w64-mingw32/include/winnt.h:1521,
                 from D:/tools/TDM-GCC-64/x86_64-w64-mingw32/include/minwindef.h:163,
                 from D:/tools/TDM-GCC-64/x86_64-w64-mingw32/include/windef.h:8,
                 from D:/tools/TDM-GCC-64/x86_64-w64-mingw32/include/windows.h:69,
                 from D:/tools/libnfc-master/contrib/windows.h:36,
                 from D:/tools/libnfc-build/config.h:1,
                 from D:\tools\libnfc-master\libnfc\drivers\acr122_usb.c:50:
D:/tools/TDM-GCC-64/x86_64-w64-mingw32/include/errno.h:183:0: note: this is the location of the previous definition
 #define ETIMEDOUT 138
 ^
In file included from D:/tools/libnfc-build/config.h:1:0,
                 from D:\tools\libnfc-master\libnfc\drivers\acr122_usb.c:50:
D:/tools/libnfc-master/contrib/windows.h:48:0: warning: "ENOTSUP" redefined
 #    define ENOTSUP       WSAEOPNOTSUPP
 ^
In file included from D:/tools/TDM-GCC-64/lib/gcc/x86_64-w64-mingw32/5.1.0/include/mm_malloc.h:28:0,
                 from D:/tools/TDM-GCC-64/lib/gcc/x86_64-w64-mingw32/5.1.0/include/xmmintrin.h:34,
                 from D:/tools/TDM-GCC-64/lib/gcc/x86_64-w64-mingw32/5.1.0/include/x86intrin.h:31,
                 from D:/tools/TDM-GCC-64/x86_64-w64-mingw32/include/winnt.h:1521,
                 from D:/tools/TDM-GCC-64/x86_64-w64-mingw32/include/minwindef.h:163,
                 from D:/tools/TDM-GCC-64/x86_64-w64-mingw32/include/windef.h:8,
                 from D:/tools/TDM-GCC-64/x86_64-w64-mingw32/include/windows.h:69,
                 from D:/tools/libnfc-master/contrib/windows.h:36,
                 from D:/tools/libnfc-build/config.h:1,
                 from D:\tools\libnfc-master\libnfc\drivers\acr122_usb.c:50:
D:/tools/TDM-GCC-64/x86_64-w64-mingw32/include/errno.h:76:0: note: this is the location of the previous definition
 #define ENOTSUP         129
 ^
In file included from D:/tools/libnfc-build/config.h:1:0,
                 from D:\tools\libnfc-master\libnfc\drivers\acr122_usb.c:50:
D:/tools/libnfc-master/contrib/windows.h:49:0: warning: "ECONNABORTED" redefined
 #    define ECONNABORTED  WSAECONNABORTED
 ^
In file included from D:/tools/TDM-GCC-64/lib/gcc/x86_64-w64-mingw32/5.1.0/include/mm_malloc.h:28:0,
                 from D:/tools/TDM-GCC-64/lib/gcc/x86_64-w64-mingw32/5.1.0/include/xmmintrin.h:34,
                 from D:/tools/TDM-GCC-64/lib/gcc/x86_64-w64-mingw32/5.1.0/include/x86intrin.h:31,
                 from D:/tools/TDM-GCC-64/x86_64-w64-mingw32/include/winnt.h:1521,
                 from D:/tools/TDM-GCC-64/x86_64-w64-mingw32/include/minwindef.h:163,
                 from D:/tools/TDM-GCC-64/x86_64-w64-mingw32/include/windef.h:8,
                 from D:/tools/TDM-GCC-64/x86_64-w64-mingw32/include/windows.h:69,
                 from D:/tools/libnfc-master/contrib/windows.h:36,
                 from D:/tools/libnfc-build/config.h:1,
                 from D:\tools\libnfc-master\libnfc\drivers\acr122_usb.c:50:
D:/tools/TDM-GCC-64/x86_64-w64-mingw32/include/errno.h:102:0: note: this is the location of the previous definition
 #define ECONNABORTED 106
 ^
In file included from D:\tools\libnfc-master\libnfc\drivers\acr122_usb.c:69:0:
D:/tools/libnfc-master/libnfc/buses/usbbus.h:44:23: fatal error: lusb0_usb.h: No such file or directory
compilation terminated.
libnfc\CMakeFiles\nfc.dir\build.make:195: recipe for target 'libnfc/CMakeFiles/nfc.dir/drivers/acr122_usb.c.obj' failed
mingw32-make.exe[2]: *** [libnfc/CMakeFiles/nfc.dir/drivers/acr122_usb.c.obj] Error 1
CMakeFiles\Makefile2:263: recipe for target 'libnfc/CMakeFiles/nfc.dir/all' failed
mingw32-make.exe[1]: *** [libnfc/CMakeFiles/nfc.dir/all] Error 2
Makefile:154: recipe for target 'all' failed
mingw32-make.exe: *** [all] Error 2```
tol-va commented 3 months ago

Ok, I worked around this issue and wanted to add my discovery. I have Arduino Sketch installed to work with the Nano board I'm using to convert the RC522 board's SPI to UART. I gave up on the linker, just dragging and dropping the files from the libusb project into the libnfc/busses/ directory resolved the missing header file issue. The path and build process of the libusb-win32 is not documented in that project. The next issue was the libusb0.dll. I tried using the dll in Windows32 that results from using the libusb-win32 installer. This did not work, so I searched my system to be sure I was pointing at the correct dll. This is when I discovered Arduino Sketch had added a copy of the libusb.dll to my driver store, System32\DriverStore\FileRepository\arduino_gemma.***\amd64\libusb0.dll. This is a much more accessible method of getting this driver.

tol-va commented 3 months ago

After commenting out the pn53x specific files in the "\examples\CMakeLists.txt" file I was able to finish the windows build.

  # pn53x-diagnose
  # pn53x-sam
  # pn53x-tamashell

The examples require the pn53x_transceive method from the "libnfc\chips\pn53x.h" file but there seems to be a failure to successfully link the classes even though the path looks correct, #include "libnfc/chips/pn53x.h". I'm good but I would suggest updating the Windows build documentation since the lusb0.dll from System32 did not successfully satisfy the build requirements. I'm on Windows 11.