fixed cross compilation of libnfc

319 views
Skip to first unread message

Frank Morgner

unread,
May 21, 2013, 10:38:27 AM5/21/13
to nfc-too...@googlegroups.com
Hi!

I updated the scripts for compiling libnfc (and tools!) for windows in a linux environment. Tested with Minimalist GNU win32 4.2.1 and MinGW-w64 2.0.3-1.

See https://github.com/frankmorgner/libnfc

Cheers,
Frank.

Philippe Teuwen

unread,
Jun 15, 2013, 7:36:58 PM6/15/13
to nfc-too...@googlegroups.com
Hi Frank,

Thanks! I've merged it to branch win-cross

Innocent question: how can I cross-compile?
I just tried:
apt-get install mingw32
./mingw-cross-configure.sh
make
but it fails finding windows.h

It would be also better to avoid sylinks in the sources.
I'm talking about
# libnfc/buses/uart-win32.c
# libnfc/log-internal-win32.c
# libnfc/stdlib-win32.c
# utils/stdlib-win32.c
but I'm not sure the best way to remove them

Best regards
Phil
> --
> You received this message because you are subscribed to the Google
> Groups "nfc-tools developers group" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to nfc-tools-dev...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Frank Morgner

unread,
Jun 17, 2013, 8:24:34 AM6/17/13
to nfc-too...@googlegroups.com
On Sunday, June 16 at 01:36AM, Philippe Teuwen wrote:
>
> Hi Frank,
>
> Thanks! I've merged it to branch win-cross
>
> Innocent question: how can I cross-compile?
> I just tried:
> apt-get install mingw32
> ./mingw-cross-configure.sh
> make
> but it fails finding windows.h

Have you installed mingw32-runtime?

The script adds -I/usr/i586-mingw32msvc/include to the CFLAGS, which
should work on Debian/Ubuntu.

If you want to use acr_pcsc you need to use MinGW-w64.

> It would be also better to avoid sylinks in the sources.
> I'm talking about
> # libnfc/buses/uart-win32.c
> # libnfc/log-internal-win32.c
> # libnfc/stdlib-win32.c
> # utils/stdlib-win32.c
> but I'm not sure the best way to remove them

Agreed. The problem is that the automake seems to have a problem
including a source file from an other directory (in
libnfc/buses/Makefile.am and libnfc/Makefile.am). While you can use a
source file from a *sub*directory, I could not find out how to add a
file somewhere in the upper directory or even with an absolute path. I
tried hard, but I did not find a better solution than a link.

--
Frank Morgner

Virtual Smart Card Architecture http://vsmartcard.sourceforge.net
OpenPACE http://openpace.sourceforge.net
IFD Handler for libnfc Devices http://sourceforge.net/projects/ifdnfc

Philippe Teuwen

unread,
Jun 17, 2013, 10:04:36 AM6/17/13
to nfc-too...@googlegroups.com
On 06/17/2013 02:24 PM, Frank Morgner wrote:
> On Sunday, June 16 at 01:36AM, Philippe Teuwen wrote:
>> Hi Frank,
>>
>> Thanks! I've merged it to branch win-cross
>>
>> Innocent question: how can I cross-compile?
>> I just tried:
>> apt-get install mingw32
>> ./mingw-cross-configure.sh
>> make
>> but it fails finding windows.h
> Have you installed mingw32-runtime?
>
> The script adds -I/usr/i586-mingw32msvc/include to the CFLAGS, which
> should work on Debian/Ubuntu.

Yes and I have the file in that directory.
But looking at details of the fauty command I get:

$ make V=1
make all-recursive
make[1]: Entering directory
`/home/phil/devel/00smartcard/tools/libnfc/git/libnfc'
Making all in libnfc
make[2]: Entering directory
`/home/phil/devel/00smartcard/tools/libnfc/git/libnfc/libnfc'
Making all in chips
make[3]: Entering directory
`/home/phil/devel/00smartcard/tools/libnfc/git/libnfc/libnfc/chips'
make[3]: Nothing to be done for `all'.
make[3]: Leaving directory
`/home/phil/devel/00smartcard/tools/libnfc/git/libnfc/libnfc/chips'
Making all in buses
make[3]: Entering directory
`/home/phil/devel/00smartcard/tools/libnfc/git/libnfc/libnfc/buses'
/bin/bash ../../libtool --tag=CC --mode=compile gcc -DHAVE_CONFIG_H
-I. -I../.. -I../../libnfc -I../../include -I../../include
-I../../libnfc
-I/home/phil/devel/00smartcard/tools/libnfc/git/libnfc/libusb-win32-bin-1.2.6.0/include
-Wfatal-errors -I/usr/i686-w64-mingw32/include -U__STRICT_ANSI__
-I/home/phil/devel/00smartcard/tools/libnfc/git/libnfc
-I/home/phil/devel/00smartcard/tools/libnfc/git/libnfc/contrib/win32
-D_WINDLL -D_MSC_VER -Wall -pedantic -Wextra -std=c99 -Du_int8_t=uint8_t
-Du_int16_t=uint16_t -MT libnfcbuses_la-spi.lo -MD -MP -MF
.deps/libnfcbuses_la-spi.Tpo -c -o libnfcbuses_la-spi.lo `test -f
'spi.c' || echo './'`spi.c
libtool: compile: gcc -DHAVE_CONFIG_H -I. -I../.. -I../../libnfc
-I../../include -I../../include -I../../libnfc
-I/home/phil/devel/00smartcard/tools/libnfc/git/libnfc/libusb-win32-bin-1.2.6.0/include
-Wfatal-errors -I/usr/i686-w64-mingw32/include -U__STRICT_ANSI__
-I/home/phil/devel/00smartcard/tools/libnfc/git/libnfc
-I/home/phil/devel/00smartcard/tools/libnfc/git/libnfc/contrib/win32
-D_WINDLL -D_MSC_VER -Wall -pedantic -Wextra -std=c99 -Du_int8_t=uint8_t
-Du_int16_t=uint16_t -MT libnfcbuses_la-spi.lo -MD -MP -MF
.deps/libnfcbuses_la-spi.Tpo -c spi.c -o libnfcbuses_la-spi.o
In file included from
/home/phil/devel/00smartcard/tools/libnfc/git/libnfc/contrib/win32/unistd.h:34:0,
from spi.c:52:
../../contrib/windows.h:35:23: fatal error: windows.h: No such file or
directory


So I see a -I/usr/i686-w64-mingw32/include but no
-I/usr/i586-mingw32msvc/include
I don't have any /usr/i686-w64-mingw32/include directory

Note also that by default the script is configuring all drivers.
this has to be reduced to the list of drivers supported under Windows
(=all but SPI & I2C?)

Best regards
Phil

Frank Morgner

unread,
Jun 18, 2013, 3:47:09 AM6/18/13
to nfc-too...@googlegroups.com
Ah, I see. You need to call
env MINGW=i586-mingw32msvc ./mingw-cross-configure.sh

The default cross compiler is MinGW-w64 (32 bit, hence
i686-w64-mingw32), because it has support for PC/SC.

The subsequent call to ./configure will not enable pn532_spi by default.
What is I2C and how can it be enabled/disabled?

Philippe Teuwen

unread,
Jun 18, 2013, 4:03:38 AM6/18/13
to nfc-too...@googlegroups.com
A hw bus similar to SPI, but don't' worry it's already automatically
disabled for Windows and therefore by your script when I use the proper
MINGW:

Selected drivers:
acr122_pcsc...... no
acr122_usb....... yes
acr122s.......... yes
arygon........... yes
pn53x_usb........ yes
pn532_uart....... yes
pn532_spi....... no
pn532_i2c........ no

Now it compiles.
Next stupid question: how do I bundle the dll & exe to install them on a
Windows machine in a clean way?

Best regards
Phil

Frank Morgner

unread,
Jun 18, 2013, 7:12:57 AM6/18/13
to nfc-too...@googlegroups.com
Hi!

> > The default cross compiler is MinGW-w64 (32 bit, hence
> > i686-w64-mingw32), because it has support for PC/SC.
> >
> > The subsequent call to ./configure will not enable pn532_spi by default.
> > What is I2C and how can it be enabled/disabled?
>
> A hw bus similar to SPI, but don't' worry it's already automatically
> disabled for Windows and therefore by your script when I use the proper
> MINGW:
>
> Selected drivers:
> acr122_pcsc...... no
> acr122_usb....... yes
> acr122s.......... yes
> arygon........... yes
> pn53x_usb........ yes
> pn532_uart....... yes
> pn532_spi....... no
> pn532_i2c........ no
>
> Now it compiles.
> Next stupid question: how do I bundle the dll & exe to install them on a
> Windows machine in a clean way?

There are no stupid questions, only stupid answers...

The clean way would propably involve some sort of installer. I would
simply use a zip with binaries, headers and so on:

env MINGW=i686-w64-mingw32 ./mingw-cross-configure.sh --prefix=/
make install DESTDIR=`pwd`/libnfc_win32

Now zip libnfc_win32 (and maybe add a version number) and you're done.
A copy of libusb could also be added to the package so that everything
comes in one bundle.

I use the same process for pcsc-relay (based on libnfc). See
http://sourceforge.net/p/vsmartcard/git/ci/master/tree/pcsc-relay/win32/Makefile.am#l38

Philippe Teuwen

unread,
Jun 20, 2013, 7:27:54 AM6/20/13
to nfc-too...@googlegroups.com
Hi Frank

Ok it runs without crashing on Windows :-)
Next step is to get the reader recognized.
Here I have only a SCL3711 to try (installed without drivers) but it's
not detected.
From the README-windows.txt it says ASK LoGO works so I expect SCL3711
to work too (unless LoGO works only through driver & PCSC...)
What's your experience? Which reader are you using?

BTW I'm used to debug with "LIBNFC_LOG_LEVEL=3 nfc-foo" but under
windows it has no effect of I do a "set LIBNFC_LOG_LEVEL=3" in the cmd.

Thanks for your help.
Phil

PS: I've added a link to your PC/SC Relay on
http://nfc-tools.org/index.php?title=Related_links

Reply all
Reply to author
Forward
0 new messages