Issue 1714 in zxing: C++ Port with Android NDK r8d: Problem with isnan() in ZXing.h

285 views
Skip to first unread message

zx...@googlecode.com

unread,
Jun 24, 2013, 9:26:27 AM6/24/13
to zx...@googlegroups.com
Status: New
Owner: ----

New issue 1714 by nichtess...@gmail.com: C++ Port with Android NDK r8d:
Problem with isnan() in ZXing.h
http://code.google.com/p/zxing/issues/detail?id=1714

What steps will reproduce the problem?
1. Download Release Sourcepackage of ZXing 2.2
2. Copy cpp/core/src/zxing and cpp/core/src/bigint to your JNI-Folder
3. Add the following to Android.mk: LOCAL_C_INCLUDES +=
$(LOCAL_PATH)/<DirectoryWhereZXingFolderIs>
4. When compiling, the g++ runs stops at an error caused by ZXing.h (Line
52)



### What is the expected output? What do you see instead?
I expected the same source-code to compile with the NDK, as id did on my
Desktop (Suse 12.02 with gcc (SUSE Linux) 4.7.1 20120723 [gcc-4_7-branch
revision 189773]). Instead I get the following error (zxing-folder is
located in jni/avcore):

In file included from jni/avcore/zxing/common/BitArray.h:21:0,
from jni/avcore/zxing/common/BitMatrix.h:25,
from jni/avcore/zxing/BinaryBitmap.h:24,
from jni/avcore/zxing/Reader.h:23,
from jni/avcore/zxing/MultiFormatReader.h:24,
from
jni/avcore/featureTagExtractors/ImprovedQRExtractor.cpp:11:
jni/avcore/zxing/ZXing.h:55:13: error: expected unqualified-id
before 'sizeof'
jni/avcore/zxing/ZXing.h:55:13: error: expected ')' before 'sizeof'
jni/avcore/zxing/ZXing.h:55:13: error: expected ')' before 'sizeof'
jni/avcore/zxing/ZXing.h:56:13: error: expected unqualified-id
before 'sizeof'
jni/avcore/zxing/ZXing.h:56:13: error: expected ')' before 'sizeof'
jni/avcore/zxing/ZXing.h:56:13: error: expected ')' before 'sizeof'
make: ***
[obj/local/armeabi/objs-debug/avNative/avcore/featureTagExtractors/ImprovedQRExtractor.o]
Error 1


### What version of the product are you using? On what operating system?
ZXing 2.2 on Android, compiled for Android API 10+ with android-ndk-r8d


### Please provide any additional information below.
A guy states on Stackoverflow that this issue is caused by changes btw. C99
and C++11 compiler implementations. In C99 isnan was defined as a macro,
where it became a function with the same name in standard-namespace in
C++11. Refer
http://stackoverflow.com/questions/8766092/build-issue-when-using-cmath-with-android-ndk

I tried out his suggested solution and it compiled smoothly. Since I'm
running into an issue with iconv.h right now I'm not in a position to
confirm that it is working at runtime as well - I'll report back on that as
soon I fixed the other issue.


What I did was changing this:
#include <cmath>

namespace zxing {
inline bool isnan(float v) {return std::isnan(v);}
inline bool isnan(double v) {return std::isnan(v);}
inline float nan() {return std::numeric_limits<float>::quiet_NaN();}
}

to this - so I simply undefined and removed the std-scopeoperators:

#include <cmath>
#undef isnan

namespace zxing {
inline bool isnan(float v) {return isnan(v);}
inline bool isnan(double v) {return isnan(v);}
inline float nan() {return std::numeric_limits<float>::quiet_NaN();}
}


--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

zx...@googlecode.com

unread,
Jun 24, 2013, 10:04:53 AM6/24/13
to zx...@googlegroups.com

Comment #1 on issue 1714 by nichtess...@gmail.com: C++ Port with Android
NDK r8d: Problem with isnan() in ZXing.h
http://code.google.com/p/zxing/issues/detail?id=1714

Actually my "solution" does not work at runtime - of course not. As i
undefined the macro AND removed the std::-operator, the expression "isnan"
is now completely undefined and causes a crash without printing any hints
on the reason to the stdout/stderr.

I'm going to evaluate whether the r8e NDK has fixed this issue probably
since I read that there were some bugs fixed in cmath.h (but from what I
read this is probably unrelated..)

zx...@googlecode.com

unread,
Jun 24, 2013, 11:04:11 AM6/24/13
to zx...@googlegroups.com

Comment #2 on issue 1714 by nichtess...@gmail.com: C++ Port with Android
NDK r8d: Problem with isnan() in ZXing.h
http://code.google.com/p/zxing/issues/detail?id=1714

I found a Workaround for this without changing any code (note I removed
aztec and pdf417 modules since I ran into some troubles with BigInteger as
well );

Just add the following to your Android.mk

# Needed for the compilation of native ZXing
LOCAL_C_INCLUDES += $(LOCAL_PATH)/<DirectoryWhereZXingFolderIs> # ZXing
includes everything in <*>, thus from Include-Paths, so we have to add the
avcore-Directory as an include path
LOCAL_CFLAGS += -DNO_ICONV # States that the ICONV-Library is not
available with Android-NDK
LOCAL_CPPFLAGS += -D_GLIBCXX_USE_C99_MATH=1

The first one - as described - adds the folder where the zxing-directory is
located to the Include-Path of your compiler.

Second defines the NO_ICONV-Symbol, because in the Android-NDK (Revision
8D) the libiconv.so is not available and would have to be compiled
separately with the NDK (there are guides on this on the internet)

The third line now actuallC++11-compatibely "solves" the reported issue,
because it tells the g++ to use the cmath (whichi s part of the standard
template library STL) from C99 standard.

Although this lets me compile and run code smoothly on my Android, I'd
prefer a more generic solution to this problem so compilation works with
both standards.

zx...@googlecode.com

unread,
Aug 18, 2013, 7:24:58 PM8/18/13
to zx...@googlegroups.com
Updates:
Status: NotABug

Comment #3 on issue 1714 by srowen: C++ Port with Android NDK r8d: Problem
OK thanks for the info -- closing this out.
Reply all
Reply to author
Forward
0 new messages