Comments (10)
Yup, it seems to be somewhat broken. May I ask you to fill-in a Pull-Request for this change?
from libfreefare.
Oh yes - I'll create one. Another question about the same topic:
why is there an explicit 'add_definitions("-std=c99")'
Is someone requiring that? This leads to compile errors (optind undeclared) on my Ubuntu 14.04
I commented that out - and everything works as expected...
from libfreefare.
Well, the code use moden (sic) c99, e.g. variable declarations are not always at the beginning of a bloc (example here); structure members are initialized the new way (example here). While most c89 compilers support c99 extensions, I think it's better to use -std=c99
because it's the version of the language that was used and compilers defaults to c89.
Are you sure there is no previous error (you can copy & paste a full build error)? The name optind
is linked to getopt(3)
in my mind, and maybe some header is missing on your system…
from libfreefare.
Hello Again,
toyed around a bit now (concerning c99, etc). How about:
diff --git a/CMakeLists.txt b/CMakeLists.txt
index a3cb9bf..a3d76fe 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -3,7 +3,11 @@ cmake_minimum_required(VERSION 2.6)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/")
-add_definitions("-std=c99")
+IF(CMAKE_C_COMPILER_ID STREQUAL "GNU")
+ add_definitions("--std=gnu99")
+ELSE()
+ add_definitions("-std=c99")
+ENDIF()
Otherwise - examples/mifare-classic-format.c would also require an
#inlude <getopt.h>
from libfreefare.
Hum, took some time to have a look. I booted-up an Ubuntu Xenial virtual machine and attempted to build the code.
CMake is definitively broken: the source files expect config.h
to be present (it is generated by the ./configure
script generated by the autotools). AFAICR, CMake was introduced at some point to permit build on Windows, which is not officially supported… Some linting seems required (at least check if HAVE_CONFIG_H
is defined before including config.h
).
Regarding getopts
, according the the man page, getopts.h
is only required when using getopt_long()
and getopt_long_only()
which are not used. This second problem therefore seems bogus, but maybe the config.h
that was found and used in your case defines some macros that change what the preprocessor generates? In this case, this second problem is a side effect of the first one.
I think the best is:
- Have a clean repo (clone it or clean is using
git clean -fdx
); - Create an empty directory for the build and change to this directory;
- Run
cmake /path/to/libfreefare-source
to generate the build files; - Build using
make
This way you should hit failures that you can fix in the libfreefare code. When everything is fine, please update your #58 Pull-Request 😄
from libfreefare.
Hey,
Yes - you're right with your suggestions - but which GCC are you compiling with? (I'm using GCC-6.2.0)
-
config.h - generated one with 'configure' and tried to compile the source then - same issue with optind. Previously I 'touch'ed an empty config.h (thus I forgot all about it...)
-
Do you want me to add HAVE_CONFIG_H ifdef everytime where config.h is included? An option would be to have cmake generate an empty config.h (for the folks that are doing cmake building in Linux)
-
The optind issue stays with C99 and leads to undefined references with htobe16, le16toh, et al.
Since CMake is primarily used for windows building - maybe the GNU Check and gnu99 switch wouldn't be too bad?
Thanks
from libfreefare.
This was tested with gcc 5.4.0, but the compiler should not pose any kind of problem with this code.
Regarding points 1 and 2, as CMake does not produce a config.h
file, either such a file should be generated by CMake, or the #include
should be "protected". libnfc does both: here are links to where CMake generates a config.h
file, defines HAVE_CONFIG_H
and an example of include protection (this should be in all files including config.h
).
In fact, the autotools are in charge of checking that a number of headers are available in order for them to be included (see this example). Since they are undefined, none of these headers are included, producing warnings and errors (e.g. endianness functions). I guess that CMake should perform some checks and define macros accordingly.
The -std=c99
flag makes the compiler more strict. In order to detect problems, compile with extended checks, for example with these CFLAGS: -Wall -Wextra -Werror -Wno-error=unused-variable -Wno-error=unused-but-set-variable -Wno-error=address
(All the -Wno-error=...
are required because of the ugly macros). I just checked (and fixed a problem): it now compiles with the autotools.
from libfreefare.
Sorry for the delay.
How about that:
swalkner@21c585a
Built with autotools and cmake (on ubuntu 14.04)
stefan.
from libfreefare.
Excellent!
from libfreefare.
Just merged #58, thanks!
from libfreefare.
Related Issues (20)
- Unknown key version - card locked after desfire test HOT 1
- Support for NTAG 424, DESFire Lite, and some limited DESFire EV2 HOT 13
- Why doesn't it support mifare plus? HOT 2
- MIFARE DESFire EV2 fails some unit tests HOT 1
- Cut a 1.0.0 release HOT 6
- Create a 0.4.x branch HOT 4
- Wiki, Website and Forum not available HOT 2
- libnfc.driver.acr122_usb: Command Code verification failed when calling mifare_classic_write() HOT 1
- Wrong implementation for CRC padding in mifare_cryto_postprocess_data
- Specs for setting encrypted transfer modes with DESFire tags HOT 2
- PCSC detection for PN532 board via SPI
- mifare_desfire_get_key_settings() discards encryption type bits HOT 5
- Failure to compile HOT 1
- Just some explanation needed HOT 1
- Why freefare_get_tags() not detect smartphone NFC?
- QUESTION: libfreefare portable to non-android system
- unable to dump application 0x9011f2
- DESFire key diversification - problem with random UID
- JCOB CARD EV3 8k Issue
- I can't write 6 bytes to a file on a Desfire card
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from libfreefare.