PDA

View Full Version : Error while trying to build android app. #error Bionic header ctype.h...



hackree
30th July 2015, 12:02
Hi, I have some very useful app that calculates some water/steam properties (engineering stuff). Now I thought I might just build it for android and run it on my android phone so I don't have to take my laptop with me all the time.

But it doesn't build. It fails with the error:
#error Bionic header ctype.h does not define either _U nor _CTYPE_U .

Now I'm suspecting this might have something to do with the gnu scientific library, because this app needs to link to it (and another lib called freesteam). It runs fine when I choose the desktop option from the debug menu.

I've checked online and the qt documentation but I didn't find anything that kinda lists all the steps I need to follow to make an app run on android if any other libraries are needed.

Some additional info. I'm using Qt5.4/qtcreator in a Linux Mint x64 machine.
I know (at least I think) that Qt5.4 is setup correctly because I can build/run programs, that do not need additional libraries, on my android device.

Here's my .pro file. Maybe it gives any clues about what I'm doing wrong.


TEMPLATE = app

QT += qml quick

SOURCES += main.cpp \
mysteamclass.cpp

RESOURCES += qml.qrc

# Additional import path used to resolve QML modules in Qt Creator's code model
QML_IMPORT_PATH =

# Default rules for deployment.
include(deployment.pri)

DISTFILES +=

HEADERS += \
mysteamclass.h
#--------------------------------ME= C++11 AND LIBRARIES-----------------#

CONFIG+=c++11


INCLUDEPATH += /usr/local/include
INCLUDEPATH += /usr/local/freesteam

DEPENDPATH += /usr/local/include


LIBS += -L/usr/local/include/

LIBS += -L/usr/local/include -lgsl

LIBS += -L/usr/local/include -libfreesteam
LIBS += -L/usr/local/include -lgslcblas

LIBS+= -L/usr/lib/freesteam



win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../../usr/lib/release/ -lfreesteam
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../../usr/lib/debug/ -lfreesteam
else:unix: LIBS += -L$$PWD/../../../../usr/lib/ -lfreesteam

INCLUDEPATH += $$PWD/../../../../usr/include
DEPENDPATH += $$PWD/../../../../usr/include



Thank you for your time. :)

anda_skoa
30th July 2015, 13:00
That doesn't look related to Qt.
The error complains about a difference in the C standard library that Android uses (Bionic)

Cheers,
_

hackree
30th July 2015, 13:26
Thanks for answering.

Can you point me in the right direction? What exactly should I be looking for ?

I've searched google a lot but the only thing that seemed related to this error was a thread in another website that, basically, said the op there shouldn't have those include libraries in the .pro file and then linked to a git repository that had some sort of tutorial. But that was clearly for more advanced users and I couldn't follow along.

Thanks again.

anda_skoa
30th July 2015, 14:16
First you need to find out where this error comes from, which file the compiler is trying to comile when it hits this.

Cheers,
_

ChrisW67
30th July 2015, 21:48
The current bionic code certainly defines the macro:
https://android.googlesource.com/platform/bionic/+/master/libc/include/ctype.h
Perhaps an earlier version does not or the consumer code complaining is in error.

hackree
30th July 2015, 23:21
The current bionic code certainly defines the macro:
https://android.googlesource.com/platform/bionic/+/master/libc/include/ctype.h
Perhaps an earlier version does not or the consumer code complaining is in error.

So what exactly is this bionic? Any ideas on how I could tackle this problem?

I'm pretty lost right now. Google hasn't spit out anything useful or I'm not searching in the right way.

Thanks for the answer. :)

anda_skoa
31st July 2015, 08:39
As I said, find the location of the error.

The error message is just the "end" of the stack, find out where the file that had this error message was included from.

Cheers,
_

ChrisW67
31st July 2015, 11:27
Bionic is a collection of C, math, dynamic linker, and C++ libraries and a linker application for Android.
https://android.googlesource.com/platform/bionic/

hackree
31st July 2015, 16:02
As I said, find the location of the error.

The error message is just the "end" of the stack, find out where the file that had this error message was included from.

Cheers,
_

I tried to follow the error, even before asking here, but I couldn't make any sense out of it. I'm not a real programmer so maybe I'm sounding stupid but when I followed the (bionic) error I was sent somewhere in a header file called ctype_base.h. Here's a snippet of the code around where the error.


// ISO C++ 14882: 22.1 Locales
//

// Information as gleaned from /usr/include/ctype.h, for solaris2.5.1

// Support for Solaris 2.5.1

#if defined (__ANDROID__)
#if !defined(_U)
#if !defined(_CTYPE_U)
#error Bionic header ctype.h does not define either _U nor _CTYPE_U
#endif
#define _U _CTYPE_U
#define _L _CTYPE_L
#define _N _CTYPE_N
#define _S _CTYPE_S
#define _P _CTYPE_P
#define _C _CTYPE_C
#define _X _CTYPE_X
#define _B _CTYPE_B
#endif
#endif /* __ANDROID__ */

namespace std _GLIBCXX_VISIBILITY(default)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION


I'm very new to qt so I hadn't seen those before but when I clicked the yellow exclamation mark button, some lines popped up before the error. Maybe that's where the error is caused.


/opt/android-ndk-r10e/sources/cxx-stl/gnu-libstdc++/4.9/include/bits/locale_facets.h:41: In file included from /opt/android-ndk-r10e/sources/cxx-stl/gnu-libstdc++/4.9/include/bits/locale_facets.h:41:0,

/opt/android-ndk-r10e/sources/cxx-stl/gnu-libstdc++/4.9/include/bits/basic_ios.h:37: from /opt/android-ndk-r10e/sources/cxx-stl/gnu-libstdc++/4.9/include/bits/basic_ios.h:37,

/opt/android-ndk-r10e/sources/cxx-stl/gnu-libstdc++/4.9/include/ios:44: from /opt/android-ndk-r10e/sources/cxx-stl/gnu-libstdc++/4.9/include/ios:44,

/opt/android-ndk-r10e/sources/cxx-stl/gnu-libstdc++/4.9/include/ostream:38: from /opt/android-ndk-r10e/sources/cxx-stl/gnu-libstdc++/4.9/include/ostream:38,

/opt/android-ndk-r10e/sources/cxx-stl/gnu-libstdc++/4.9/include/iostream:39: from /opt/android-ndk-r10e/sources/cxx-stl/gnu-libstdc++/4.9/include/iostream:39,

/home/ihaaaaa/QtProjects/freesteam/main.cpp:8: from ../freesteam/main.cpp:8:


There also a bunch of other errors after the actual error. All of the type:


/opt/android-ndk-r10e/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/include/bits/ctype_base.h:62: error: '_CTYPE_U' was not declared in this scope
static const mask upper = _U;
^
/opt/android-ndk-r10e/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/include/bits/ctype_base.h:63: error: '_CTYPE_L' was not declared in this scope
static const mask lower = _L;
^

Would you please have a look at it? Maybe you would understand what exactly is wrong.

Thank you. :)

anda_skoa
1st August 2015, 11:35
[QUOTE=hackree;280347]/opt/android-ndk-r10e/sources/cxx-stl/gnu-libstdc++/4.9/include/iostream:39: from /opt/android-ndk-r10e/sources/cxx-stl/gnu-libstdc++/4.9/include/iostream:39,

/home/ihaaaaa/QtProjects/freesteam/main.cpp:8: from ../freesteam/main.cpp:8:[/Iquote]

So you are including some standard header there in line 8 of main.cpp?

If yes, check if the error also happens in a minimal project without Qt. If so you might want to ask on an Android forum instead,

Cheers,
_

hackree
1st August 2015, 13:51
I've tried that. If I remove any link to C++ or anything outside QML it (the UI) compiles and runs well. Also if I try to run it as a desktop app it works. From digging around the internet I found something suggesting that the compiler is including a header from the system when it should be using one from the android ndk.

Had no luck on finding a solution yet though.

Thanks.

ChrisW67
1st August 2015, 21:39
Are you able to build, deploy, and run a simple "Hello world!" program that uses iostream for Android using your build environment?

Your pro file does indeed include a bunch of folders for your native environment: all includes and libraries should be coming from the NDK. It also contains what looks like the wrong name for the freesteam library. Try this cut down version


TEMPLATE = app
QT += qml quick
SOURCES += main.cpp \
mysteamclass.cpp
RESOURCES += qml.qrc
# Additional import path used to resolve QML modules in Qt Creator's code model
QML_IMPORT_PATH =
# Default rules for deployment.
include(deployment.pri)
HEADERS += \
mysteamclass.h
#--------------------------------ME= C++11 AND LIBRARIES-----------------#

CONFIG+=c++11
LIBS += -lgsl
LIBS += -lfreesteam
LIBS += -lgslcblas


I am assuming the the three libs have been built with the cross-compiler and installed in the NDK default library path.

hackree
1st August 2015, 22:24
Are you able to build, deploy, and run a simple "Hello world!" program that uses iostream for Android using your build environment?

Your pro file does indeed include a bunch of folders for your native environment: all includes and libraries should be coming from the NDK. It also contains what looks like the wrong name for the freesteam library.

Well, I can build and run simple programs but I have to admit that I don't know what exactly an iostream for android is. :(



I am assuming the the three libs have been built with the cross-compiler and installed in the NDK default library path.
When I installed them I just used the ./run like command from the terminal so I'm assuming the weren't built with a cross compiler! And for sure they're not in the default library path of the NDK.

Going after what you said, it pretty much looks like I'm hopeless huh?

Thank you very much.

ChrisW67
2nd August 2015, 21:18
If you do not have the freesteam/gsl library built for the Android target you will not get to the finish line. The linker will need these to build a working Android app even if we got past the prsent compilation-stage errors.

It looks like you need quite a few pieces to achieve that.

hackree
2nd August 2015, 22:07
If you do not have the freesteam/gsl library built for the Android target you will not get to the finish line. The linker will need these to build a working Android app even if we got past the prsent compilation-stage errors.

It looks like you need quite a few pieces to achieve that.

That's what I figured.

It seems like I heavily underestimated the complexity that hides behind the code once deploy everywhere phrase. I couldn't even manage to deploy and create a (desktop)package for this app, let alone make it work on android.

This may be because I'm fairly new to linux but still. In visual studio it was way easier creating executable files and distributing them. Not cross platform but still very easy to do.

Seems like this has to wait until I find some time to dig deeper in qt and the whole things like writing .pro and make files, cmake, qmake, library cross compilations and all that stuff.

Maybe we'll chat again sometime in the upcoming future, when I get stuck, again.

Thank you for your time. :)