pyqtdeploy throws an extremely strange issue - android

I am using pyqtdeploy to pack a much simple python script into Qt Project. Then I will try to compile it as .apk file. I consider the environment has been completely set up so far, including Android SDK, Android NDK, Qt, android studio, ant etc. A strange error always appears when running pyqtdeploy.
Here is my code:
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QLabel
class Main(QWidget):
def __init__(self):
super().__init__()
self.build_inter()
def build_inter(self):
self.lb = QLabel("Test", self)
self.lb.move(0, 0)
self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
w = Main()
sys.exit(app.exec_())
I intercepted a part of error information:
..\include/pyport.h:617:60: error: expected constructor, destructor, or type conversion before '(' token
# define PyAPI_FUNC(RTYPE) __declspec(dllexport) RTYPE
^
..\include/fileutils.h:109:1: note: in expansion of macro 'PyAPI_FUNC'
PyAPI_FUNC(int) _Py_get_inheritable(int fd);
^
..\include/pyport.h:617:60: error: expected constructor, destructor, or type conversion before '(' token
# define PyAPI_FUNC(RTYPE) __declspec(dllexport) RTYPE
^
..\include/fileutils.h:111:1: note: in expansion of macro 'PyAPI_FUNC'
PyAPI_FUNC(int) _Py_set_inheritable(int fd, int inheritable,
^
..\include/pyport.h:617:60: error: expected constructor, destructor, or type conversion before '(' token
# define PyAPI_FUNC(RTYPE) __declspec(dllexport) RTYPE
^
..\include/fileutils.h:114:1: note: in expansion of macro 'PyAPI_FUNC'
PyAPI_FUNC(int) _Py_dup(int fd);
and the screenshot:
My config:
Have anyone encountered a similar problem? What am I supposed to do?
Thanks in advance!

I'm far from being an expert, but in the documentation it reads it does not make sense to check "run application" unless the target environment is equal to the source environment. From your windows it seems you are cross compiling from Windows to Android, thus I would try to omit the last parameter of "Additional build steps" ("run application"). You would then have to test it yourself from e.g. Android studio I guess. Hope it helps.

Related

Why is clang defining NULL as __null?

I have a .cpp file which has usage of NULL at several places. When I try to compile this cpp file for Android/x86 platform using clang++ on Windows machine + standalone tool chain, I am running into "expected expression" error at the places where NULL is used. I find the definition of NULL in stddef.h of clang headers provided by Android NDK as below.
#if defined(__need_NULL)
#undef NULL
#ifdef __cplusplus
# if !defined(__MINGW32__) && !defined(_MSC_VER)
# define NULL __null
# else
# define NULL 0
# endif
#else
# define NULL ((void*)0)
#endif
As far as I know, __null is specific to GNU compiler. In my case both _MSC_VER and __MINGW32__ are undefined because I am compiling for Android platform using clang++ and standalone tool chain. So it is hitting into define NULL __null. Since clang++ has no clue of what __null is, it is resulting into "expected expression" error.
My question is, why is clang using macros(like __null) provided by GNU compiler? Or am I missing something here?
Could somebody please help me understand. Thanks
Why is clang defining NULL as __null?
__null is superior to 0, because former is only a null pointer constant, while the latter is also an integer constant. This difference is significant in case of overload resolution and type deduction:
void foo(int);
void foo(void*);
foo(0); // calls foo(int)
foo(__null); // call is ambiguous, program is ill-formed
foo(NULL); // could have either behaviour
// call to foo(int) would be undesirable
foo(nullptr); // calls foo(void*)
The reason is same or similar as why nullptr was introduced to the language in C++11.
Another reason to do so is that clang strives to be closely compatible with GCC.
Since clang++ has no clue of what __null is
clang++ appears to know what __null is.

Linker can't find function

Im trying to build an Ubuntu Touch tree, based on an Aosp tree I already correctly built.
It fails with this error
CAPEWrapper.cpp:16: error: undefined reference to '__xlog_buf_printf'
this is the header that file includes
#include "CAPEWrapper.h"
which on cascade includes
#include <cutils/xlog.h>
which in turn defines
#if defined(__cplusplus)
extern "C" {
#endif
int __xlog_buf_printf(int bufid, const struct xlog_record *rec, ...);
#if defined(__cplusplus)
}
#endif
I suspect that my g++ doesn't set __cplusplus macro. Could it be a realistic scenario with this kind of error? If this could be the problem, should I need to specify a standard implementation with "stdc=something" to solve it?
Any other idea is welcome.
Make sure that your project is linking libcutils, and that it's linking it in the correct order (i.e. that -lcutils appears in the linker command line after any module that depends on it).
In the end, I found that the modules was listed inside a macro called LOCAL_WHOLE_STATIC_LIBRARIES, that in Android environment passes its content to the --whole-archive flag of GCC linker.

Android NDK compiling C++ code gets a Type 'errno_t' could not be resolved

I'm compiling C++ code written primarily for Mac OS, using the Android NDK and I get the following error:
- Type 'errno_t' could not be resolved
In Xcode this type is defined on OSX 10.0/usr/include/sys/_types/_errno_t.h as this:
#ifndef _ERRNO_T
#define _ERRNO_T
typedef int errno_t;
#endif /* _ERRNO_T */
Any suggestions on how to convert this to the NDK, or add compiler flags to make this compile, or where to even get the source code to define this type in my source code itself?
Thanks.
See this answer for information on errno_t.
errno_t is not a part of the C standard, and bionic doesn't support it.
The fix is simply to change all the errno_ts to be ints.

How to resolve "There are no arguments to <name> depending on a template parameter"?

I'm converting my legacy VC++ project to be compatible with Android NDK and I'm getting a weird error. The message says:
[armeabi] Compile++ thumb: procalc-core <= pcc_arithmetics.cpp
In file included from D:/Dokumenty/Dev/Android/ProCalc//jni/pcc_arithmetics.h:10:0,
from D:/Dokumenty/Dev/Android/ProCalc//jni/pcc_arithmetics.cpp:1:
D:/Dokumenty/Dev/Android/ProCalc//jni/pcc_common.h: In static member function
'static std::string ProCalcCore::CommonTools::ToStringBase(T, int)':
D:/Dokumenty/Dev/Android/ProCalc//jni/pcc_common.h:102:68: error: there are no
arguments to 'ConvertException' that depend on a template parameter, so a
declaration of 'ConvertException' must be available [-fpermissive]
throw ConvertException(PROCALC_ERROR_SYNTAX_INVALID_INTEGER_BASE);
^
D:/Dokumenty/Dev/Android/ProCalc//jni/pcc_common.h:102:68: note: (if you use
'-fpermissive', G++ will accept your code, but allowing the use of an undeclared
name is deprecated)
make.exe: *** [D:/Dokumenty/Dev/Android/ProCalc//obj/local/armeabi/objs/procalc-
core/pcc_arithmetics.o] Error 1
The error is thrown in the following place:
template <typename T>
std::string CommonTools::ToStringBase(T val, int base)
{
if (base < 2)
throw ConvertException(PROCALC_ERROR_SYNTAX_INVALID_INTEGER_BASE);
The caps-named error value is a #defined int value.
ConvertException is declared in another file:
namespace ProCalcCore
{
(...)
class ConvertException : public InternalException
{
public:
ConvertException(const unsigned long int & newErrorCode);
};
When I try to change ConvertException to ProCalcCore::ConvertException, I get another error:
D:/Dokumenty/Dev/Android/ProCalc//jni/pcc_common.h:102:10: error: 'ConvertException'
is not a member of 'ProCalcCore'
All dependencies are resolved correctly - in VS the project compiles without problems.
How can I solve it? What causes this error?
"In visual studio the project compiles without problems" is weak evidence that your dependencies are correct.
The problem is that ConvertException is not visible at the point where the template is declared. Some versions of Visual Studio only try to bind such "free" types and expressions at the point where the template is instantiated, which is not correct under the C++ standard.
So your compiler is pointing out that it cannot work out what type ConvertException refers to. In order for it to know what type it refers to, you need to either forward declare it (which can have its own problems), or #include the header file prior to using it.
If you think you are already #includeing it, often your problem is that the header file that contains ConvertException ends up #includeing CommonTools::ToStringBase. The header file guards (or #pragma once) then eliminate the infinite loop.
Annoyingly, how the infinite loop is eliminated depends on which header file you include first! If you include the ConvertException header file, it then includes ToStringBase, which includes ConvertException back. That second #include "ConvertException.h" is eliminated by header-file #define guards.
If you instead included ToStringBase first, it would include ConvertException, which then includes ToStringBase, which is eliminated by the header guards.
So whatever header file is included first ends up being parsed second.

Building android source code

I downloaded android source from source.android.com and followed the instruction to setup build environment on MAC OS X, Everything went fine except when i run make it gives me following error
============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=4.0.1
TARGET_PRODUCT=full
TARGET_BUILD_VARIANT=eng
TARGET_BUILD_TYPE=release
TARGET_BUILD_APPS=
TARGET_ARCH=arm
TARGET_ARCH_VARIANT=armv7-a
HOST_ARCH=x86
HOST_OS=darwin
HOST_BUILD_TYPE=release
BUILD_ID=ITL41D
============================================
host C++: aapt <= frameworks/base/tools/aapt/AaptAssets.cpp
frameworks/base/tools/aapt/AaptAssets.cpp:2161:38: warning: unused parameter 'bundle' [-Wunused-parameter]
AaptAssets::slurpResourceZip(Bundle* bundle, const char* filename)
^
In file included from frameworks/base/tools/aapt/AaptAssets.cpp:5:
In file included from frameworks/base/tools/aapt/AaptAssets.h:10:
In file included from frameworks/base/include/utils/AssetManager.h:25:
frameworks/base/include/utils/KeyedVector.h:193:17: error: use of undeclared identifier 'indexOfKey'
ssize_t i = indexOfKey(key);
^
this->
frameworks/base/tools/aapt/AaptAssets.h:446:46: note: in instantiation of member function 'android::DefaultKeyedVector<android::String8, android::sp<AaptSymbols> >::valueFor' requested here
sp<AaptSymbols> sym = mNestedSymbols.valueFor(name);
^
frameworks/base/include/utils/KeyedVector.h:66:29: note: must qualify identifier to find this declaration in dependent base class
ssize_t indexOfKey(const KEY& key) const;
^
1 warning and 1 error generated.
make: *** [out/host/darwin-x86/obj/EXECUTABLES/aapt_intermediates/AaptAssets.o] Error 1
I just started in android so do not have any clue, any small help also would be appreciated
Just to expand on Pete's answer, in case anyone really wants to know:
The indexOfKey is defined in DefaultKeyVector's parent class, KeyedVector. For class templates, a function call is resolved during compile-time, not during run-time. The error happens because at the point indexOfKey is called, the compiler wouldn't know where that template function might be located. Here is how the base and derived classes look like:
template <typename KEY, typename VALUE>
class KeyedVector
{
...
ssize_t indexOfKey(const KEY& key) const;
...
template <typename KEY, typename VALUE>
class DefaultKeyedVector : public KeyedVector<KEY, VALUE>
{
...
And the offending call:
template<typename KEY, typename VALUE> inline
const VALUE& DefaultKeyedVector<KEY,VALUE>::valueFor(const KEY& key) const {
ssize_t i = indexOfKey(key);
...
Most likely, using the older MacOS SDK compiler (or other compilers) works because it was probably just guessing the function exists in some base class, instead of failing. However, that is not standard behavior.
More info from this clang entry, and from the C++ FAQ.
I finally figured out the problem.
There's an error in the sourcecode of frameworks/base/include/utils/KeyedVector.h:193
Some of the member functions require Scope resolution operator "this->" to build the android source on MAC OS X Lion with xcode 4.3.x and on gcc version 4.9.2 (Debian 4.9.2-10).
Without scope resolution operator compiler will not be able to identify the existence of the function.
Open frameworks/base/include/utils/KeyedVector.h
Change the line 193 from:
ssize_t i = indexOfKey(key);
to
ssize_t i = this->indexOfKey(key);
and Android 4.0.1 compiles.
To build ICS on newer GCC versions, you must apply these patches:
https://groups.google.com/forum/#!msg/android-building/2EwtWQTqjdI/fbZlzXErscwJ
I faced this problem several times when building Browser for Android 4.0.3 with make -j Browser on MAC OS X 10.8.4. I dont have any problem with Android 4.2.1.
So my solution is
make CC=gcc CXX=g++ -j Browser
Hope it helps

Categories

Resources