timmerk / libfreefare

Automatically exported from code.google.com/p/libfreefare
Other
0 stars 0 forks source link

Endianness problems when compiling on Mac OS X 10.7.2 #2

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Reported by [https://code.google.com/u/114415527994645740894/ kev.y.wang], Jan 
1, 2012

*What steps will reproduce the problem?*
1. inside libfreefare-0.3.2 dir, run ./configure --prefix=/usr
2. make

*What is the expected output? What do you see instead?*
The expected output should not have the warnings that I see:

Smooth-Lightning:libfreefare-0.3.2 kevin$ make
make  all-recursive
Making all in contrib
Making all in libutil
make[3]: Nothing to be done for `all'.
make[3]: Nothing to be done for `all-am'.
Making all in libfreefare
  CC     freefare.lo
  CC     mifare_classic.lo
mifare_classic.c: In function ‘mifare_classic_init_value’:
mifare_classic.c:326: warning: implicit declaration of function ‘htole32’
mifare_classic.c: In function ‘mifare_classic_read_value’:
mifare_classic.c:364: warning: implicit declaration of function ‘le32toh’
  CC     mifare_ultralight.lo
mifare_ultralight.c: In function ‘mifare_ultralightc_authenticate’:
mifare_ultralight.c:265: warning: ‘DES_random_key’ is deprecated (declared 
at /usr/include/openssl/des.h:218)
  CC     mifare_desfire.lo
mifare_desfire.c: In function ‘authenticate’:
mifare_desfire.c:355: warning: ‘RAND_bytes’ is deprecated (declared at 
/usr/include/openssl/rand.h:104)
mifare_desfire.c: In function ‘mifare_desfire_get_df_names’:
mifare_desfire.c:826: warning: implicit declaration of function ‘le16toh’
mifare_desfire.c: In function ‘mifare_desfire_get_file_settings’:
mifare_desfire.c:1249: warning: implicit declaration of function ‘le32toh’
  CC     mifare_desfire_aid.lo
...

Basically, some of the endian macros defined in freefare_internal.h are not 
working. The compilation succeeds, but when trying to run some of the examples 
(like mifare-classic-write-ndef), I get the following:

dyld: lazy symbol binding failed: Symbol not found: _htole32
  Referenced from: /Users/kevin/dev/libfreefare-0.3.2/libfreefare/.libs/libfreefare.0.dylib
  Expected in: flat namespace

dyld: Symbol not found: _htole32
  Referenced from: /Users/kevin/dev/libfreefare-0.3.2/libfreefare/.libs/libfreefare.0.dylib
  Expected in: flat namespace

Which makes sense, since during compilation, those were never defined.

*What version of the product are you using? On what operating system?*
OS: Mac OS X 10.7.
Version: libfreefare-0.3.2

Looking at it some more, would #ifdef macros in freefare_internal.h that use 
<libkern/OSByteOrder.h> work?

----
Comment 2 by project member ludovic.rousseau, May 19, 2012
Maybe the solution is to use _standard_ C functions like:

NAME
     htonl, htons, ntohl, ntohs -- convert values between host and network
     byte order

LIBRARY
     Standard C Library (libc, -lc)

SYNOPSIS
     #include <arpa/inet.h>

     uint32_t
     htonl(uint32_t hostlong);

     uint16_t
     htons(uint16_t hostshort);

     uint32_t
     ntohl(uint32_t netlong);

     uint16_t
     ntohs(uint16_t netshort);

Original issue reported on code.google.com by yob...@gmail.com on 15 Jan 2013 at 7:39

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Original report: https://code.google.com/p/nfc-tools/issues/detail?id=83

Original comment by yob...@gmail.com on 15 Jan 2013 at 7:49

GoogleCodeExporter commented 9 years ago

Original comment by yob...@gmail.com on 15 Jan 2013 at 8:19

GoogleCodeExporter commented 9 years ago
Is this issue still exists ?

Original comment by romu...@libnfc.org on 4 Dec 2013 at 10:10

GoogleCodeExporter commented 9 years ago
I can't reproduce the link problem (on Mac OS X 10.9).

But I still have a warning at the compilation:
mifare_desfire.c:881:25: warning: implicit declaration of function 'le16toh' is 
invalid in C99 [-Wimplicit-function-declaration]
                new_dfs[*count].fid = le16toh (*(uint16_t *)(res + 3));
                                      ^
I don't know where the symbol is found. None of the #define le16toh in 
freefare_internal.h are executed on 10.9.

I also have:
tlv.c:89:25: warning: implicit declaration of function 'htobe16' is invalid in 
C99 [-Wimplicit-function-declaration]
            uint16_t size_be = htobe16 (isize);
                               ^
tlv.c:153:12: warning: implicit declaration of function 'be16toh' is invalid in 
C99 [-Wimplicit-function-declaration]
            fvs = be16toh(be_size);
                  ^

Original comment by ludovic....@gmail.com on 4 Dec 2013 at 12:06