Ffmpeg-Build: Error during build - android

I am building ffmpeg and stuck in an unusual spot. Inside libavutil we have float_dsp.h and float_dsp.c files. Inside these file there is a declaration of a methond which is:
void (*butterflies_float)(float *av_restrict v1, float *av_restrict v2, int len);
float (*scalarproduct_float)(const float *v1, const float *v2, int len);
when building and compiling this file i get this error and have no idea what to do. I think problem is somewhere else but again have no idea at all. Error is
jni/ffmpeg/libavcodec/../libavutil/float_dsp.h:150: error: expected ';', ',' or ')' before 'v1'
jni/ffmpeg/libavcodec/../libavutil/float_dsp.h:161: error: expected ';' before 'float'
Anybody who wants to help please take a step forward because i have not really got any support on ffmpeg during couple of weeks now.
Regards

This may be caused by:
not set GCC to C99 mode where restrict keyword is supported
restrict was redefined by some #define
restrict is not supported for particular architecture but this is unlikely
GCC is set to C++ mode where restrict keyword is not supported GCC according http://gcc.gnu.org/onlinedocs/gcc/Restricted-Pointers.html.
There are other supported forms by GCC like __restrict and __restrict__.
ffmpeg configure script sets macro av_restrict to just restrict which can be checked in produced config.h file.
Fix could be to change configure detection code and remove invalid case restrict:
--- ./configure.orig 2014-01-15 18:53:59.000000000 +0100
+++ ./configure 2014-03-13 17:50:45.754442028 +0100
## -3896,7 +3896,7 ##
EOF
_restrict=
-for restrict_keyword in restrict __restrict__ __restrict; do
+for restrict_keyword in __restrict__ __restrict; do
check_cc <<EOF && _restrict=$restrict_keyword && break
void foo(char * $restrict_keyword p);
EOF

Related

go with networking on Android

I've been trying to get a Go application running on Android 10 and hit a snag. I'm pretty sure I now know why I'm hitting this snag, but not sure how to fix it. First, simple things work with cross compilation. For example,
package main
import "fmt"
func main() {
fmt.Println("Hello, Android!")
}
will run just fine compiled with GOARM=arm64 GOOS=linux go build
But now if I add some networking code:
package main
import (
"fmt"
"net/http"
"io/ioutil"
)
func main() {
fmt.Println("Hello, Android!")
client := &http.Client{}
resp, err := client.Get("https://www.google.com")
if err != nil {
fmt.Println(err)
return
}
bodyBytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Printf("%s", bodyBytes)
}
And compile the same way it will run, but I'll get an error like:
Get "https://www.google.com": dial tcp: lookup www.google.com on [::1]:53: read udp [::1]:47618->[::1]:53: read: connection refused
Initially I thought this was some networking config on my Android device, but after lots of messing around I'm pretty sure it has to do with the fact that Android networking is "different". Maybe this is a bionic vs libc thing (?) but at least one other person seems to have hit the same snag and solved by building using the toolchain that comes with the NDK.
Does anyone know how to actually get this to work though?
Initially I was hoping it was as easy as GOOS=android GOARCH=arm64 go build but that fails with:
# command-line-arguments
/usr/lib/golang/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
/usr/bin/ld: /tmp/go-link-384615804/go.o: Relocations in generic ELF (EM: 183)
<bunch of these>
/usr/bin/ld: /tmp/go-link-384615804/go.o: error adding symbols: file in wrong format
collect2: error: ld returned 1 exit status
Some Googling turned up https://github.com/golang/go/issues/30216 - which says you need to explicitly enable CGO. But GOARCH=arm64 GOOS=android CGO_ENABLED=1 go build still fails, this time with:
# runtime/cgo
gcc_android.c:6:10: fatal error: android/log.h: No such file or directory
6 | #include <android/log.h>
| ^~~~~~~~~~~~~~~
compilation terminated.
I messed around with a lot of other combinations and the closest I got was pointing Go to compilers in my NDK installation. Basically something like GOARCH=arm64 GOOS=android CC=$NDKROOT/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc CGO_ENABLED=1 CGO_CFLAGS="--sysroot $NDKROOT/sysroot -I$NDKROOT/sysroot/usr/include/arm-linux-androideabi/" go build. But this failed with:
# runtime/cgo
In file included from _cgo_export.c:4:0:
cgo-gcc-export-header-prolog:25:14: error: size of array '_check_for_64_bit_pointer_matching_GoInt' is negative
There's something broken in the way I'm pointing to the compiler - for example I won't find any header files (stdlib.h) without specifying sysroot, and even then it won't find the architecture specific includes (asm/types.h) without specifying the additional include path. So the error is probably a mismatch between architecture and compiler I'm just not sure where or how to fix it.
If you've read all this, thanks! Some additional info:
go version: 1.14.13 linux/amd64
NDK version: r16b
I've also looked at things like gomobile but that seems more geared towards building Android applications (like apks) although maybe I'm missing something here.
Figured it out! Well, got my specific example working but I'm not really sure why this works. The answer came basically from https://github.com/golang/go/issues/20755 and you have to:
Build a standalone version of the NDK (the comment in the Python script that does this says it packages it in a more convenient way for other tools to use)
Rebuild Go's standard library using the cross compiler in your NDK
Build your application using the NDK cross compiler.
So for my example:
$ $(NDKROOT)/build/tools/make_standalone_toolchain.py --arch arm64 --api 24 --install-dir $(HOME)/ndk_standalone
$ CC=$(HOME)/ndk_standalone/bin/clang CXX=$(HOME)/ndk_standalone/bin/clang GOOS=android GOARCH=arm64 go install std
$ CC=$(HOME)/ndk_standalone/bin/clang CXX=$(HOME)/ndk_standalone/bin/clang GOOS=android GOARCH=arm64 CGO_ENABLED=1 go build
And networking works!
I'm not really sure why (or if) clang makes a difference as opposed to invoking the compiler directly. Maybe I'll play around with this more. Also, I had to still enabled CGO explicitly when compiling my application (but not for the go std library) otherwise linking failed.

Cross Compiling PALSIADE for android

we are trying to build PALISADE (https://git.njit.edu/palisade/PALISADE) for Android. We have made some Progress by building “gmp” and “ntl” successfully for Android.
GMP is able to cross compile out of the box. NTL was a bit more tricky. We used https://github.com/nemirst/ntl-android but changed the headers and src to the version provided within PALISADE (10.5.0)
We also did some changes to the PALISADE makefiles so they support cross compiling using the android standalone toolchains. The issue is now, when trying to compile PALISADE using the cross compiled NTL and GMP lib we get the following errors:
PALISADE/bin/build/toolchains/aarch64-linux-android/bin/aarch64-linux-android-gcc --sysroot=PALISADE/bin/build/toolchains/aarch64-linux-android/sysroot -g -Wall -Werror -O3 -fopenmp -pthread -I src -Isrc/core/lib -Isrc/pke/lib -Isrc/abe/lib -Isrc/signature/lib -I test -I /opt/local/include/libomp -fopenmp -I third-party/include -I third-party/include/rapidjson -c -o bin/build/core/lib/math/benative-math-impl.o src/core/lib/math/benative-math-impl.cpp
In file included from src/core/lib/math/benative-math-impl.cpp:28:
In file included from src/core/lib/utils/../math/backend.h:43:
src/core/lib/math/native_int/binint.h:956:79: error: no viable conversion from 'const unsigned long' to 'NTL::wide_double'
return (uint_type)NTL::MulModPrecon(this->m_value,b.m_value,modulus.m_value,bInv.m_value);
^~~~~~~~~~~~
src/core/lib/math/transfrm.cpp:192:33: note: in instantiation of member function 'native_int::NativeInteger<unsigned long>::ModMulPreconOptimized' requested here
InputToFFT[i]=element[i].ModMulPreconOptimized((*rootOfUnityTable)[i],modulus,preconTable[i]);
^
third-party/include/NTL/sp_arith.h:405:4: note: candidate constructor not viable: no known conversion from 'const unsigned long' to 'const NTL::wide_double &' for 1st argument
wide_double(const wide_double& x) : data(x.data) { }
^
third-party/include/NTL/sp_arith.h:812:62: note: passing argument to parameter 'bninv' here
inline long MulModPrecon(long a, long b, long n, wide_double bninv)
^
In file included from src/core/lib/math/benative-math-impl.cpp:36:
src/core/lib/math/transfrm.cpp:107:48: error: too many arguments to function call, expected 4, have 5
preconRootOfUnityInverseTable, cycloOrder, ans);
^~~
src/core/lib/math/transfrm.cpp:300:38: note: in instantiation of member function 'lbcrypto::NumberTheoreticTransform<native_int::NativeVector<native_int::NativeInteger<unsigned long> > >::InverseTransformIterative' requested here
NumberTheoreticTransform<VecType>::InverseTransformIterative(element, *rootOfUnityITable,
^
src/core/lib/math/transfrm.h:67:3: note: 'ForwardTransformIterative' declared here
static void ForwardTransformIterative(const VecType& element, const VecType &rootOfUnityTable, const usint cycloOrder, VecType* result) {
^
In file included from src/core/lib/math/benative-math-impl.cpp:28:
In file included from src/core/lib/utils/../math/backend.h:43:
src/core/lib/math/native_int/binint.h:975:88: error: no viable conversion from 'const unsigned long' to 'NTL::wide_double'
this->m_value = (uint_type)NTL::MulModPrecon(this->m_value,b.m_value,modulus.m_value,bInv.m_value);
^~~~~~~~~~~~
src/core/lib/math/transfrm.cpp:313:21: note: in instantiation of member function 'native_int::NativeInteger<unsigned long>::ModMulPreconOptimizedEq' requested here
(*OpIFFT)[i].ModMulPreconOptimizedEq((*rootOfUnityITable)[i],nativeModulus,preconTable[i]);
^
third-party/include/NTL/sp_arith.h:405:4: note: candidate constructor not viable: no known conversion from 'const unsigned long' to 'const NTL::wide_double &' for 1st argument
wide_double(const wide_double& x) : data(x.data) { }
^
third-party/include/NTL/sp_arith.h:812:62: note: passing argument to parameter 'bninv' here
inline long MulModPrecon(long a, long b, long n, wide_double bninv)
^
3 errors generated.
make[1]: *** [bin/build/core/lib/math/benative-math-impl.o] Error 1
make: *** [all] Error 2
We would greatly appreciate any help in getting this library to build for Android.
EDIT: Spelling
This is a little late in response, but if you are still interested, newer versions of Palisade do not require GMP or NTL (those are only enabled when the user explicitly enables them in the CMake build process), so it may be easier to build now. You should be using the newest stable version at https://gitlab.com/palisade/palisade-release or if you are willing to try it out, the development version at https://gitlab.com/palisade/palisade-development
Cross compiling is a bit tricky, but it can be done. We are working on some embedded targets but they are not yet in the release stream.
We are looking into supporting an Android port in a future release, so any progress you make that you can share with us is most appreciated.
Dave Cousins -- PALISADE Development team.

Android - NDK strange error

I start getting funny errors with NDK with fairly complex program:
#include <stdio.h>
#include <iostream>
int main( int argc, char **argv ) {
return 0;
}
>call c:\android-ndk-r9\ndk-build.cmd
"Compile++ thumb : test <= test.cpp
In file included from C:/workspace/c++11_test//jni/test.cpp:11:
In file included from c:/android-ndk-r9/sources/cxx-stl/stlport/stlport\iostream:43:
In file included from c:/android-ndk-r9/sources/cxx-stl/stlport/stlport\stl/_istream.h:31:
In file included from c:/android-ndk-r9/sources/cxx-stl/stlport/stlport\stl/_ostream.h:380:
In file included from c:/android-ndk-r9/sources/cxx-stl/stlport/stlport\stl/_ostream.c:26:
In file included from c:/android-ndk-r9/sources/cxx-stl/stlport/stlport\stl/_num_put.h:180:
In file included from c:/android-ndk-r9/sources/cxx-stl/stlport/stlport\stl/_num_put.c:26:
c:/android-ndk-r9/sources/cxx-stl/stlport/stlport\stl/_limits.h:217:48: error: non-type template argument evaluates to -2147483648, which cannot be narrowed to type 'wchar_t'
[-Wc++11-narrowing]
: public _STLP_PRIV _Integer_limits<wchar_t, WCHAR_MIN, WCHAR_MAX, -1, true>
^
c:/android-ndk-r9/platforms/android-14/arch-arm/usr/include\../include/wchar.h:76:22: note: expanded from macro 'WCHAR_MIN'
#define WCHAR_MIN INT_MIN
^
c:/android-ndk-r9/platforms/android-14/arch-arm/usr/include\sys/limits.h:69:18: note: expanded from macro 'INT_MIN'
#define INT_MIN (-0x7fffffff-1) /* min value for an int */
^
1 error generated.
make: * [C:/workspace/c++11_test//obj/local/armeabi/objs/test/test.o] Error 1
It's ndk-r9. 4.8 complie it just fine, only clang stumbles on it.
Do I need to define something to make clang work?
I've tried to Google errors, but got nothing relevant...
Obviously, I can turn it off with -Wno-c++11-narrowing, but I don't want disable narrowing checks.
And it's only shows with stlport_static, there is NO error with gnustl_static
You appear to have enabled C++11, since you are getting this warning.
STLport support for C++11 is not very good. I suspect this is the reason for your woes.
A fix requires changes to STLport, or removing the "-std=c++11" switch from the clang command-line.
IMHO, I would recommend switching to the gnustl (aka. libstdc++), unless there are other reasons that prevent you from doing so (licensing: libstdc++ is GPL3 with some significant exceptions that may or may not be valid for clang - you should determine that for yourself), legacy support, size etc.). I have had very good experiences with that.

how to execute qadd command in inline assembly in arm?

I got error when i tried to compile inline assembly with qadd command.
Error: cannot honor width suffix -- `qadd r7,r7,r1'
I know that qadd is supported in ARMv5TE
These ARM instructions are available in ARMv6 and above, and E
variants of ARMv5T.
C/asm code:
inline int __qadd(int a, int b) {
__asm__ (
"qadd %0, %1, %2" : "=r" (a) : "r" (a), "r" (b));
return a;
}
My cpu features is:
LOGI("__ARM_ARCH__='%d'", __ARM_ARCH__);
LOGI("__ARM_HAVE_5TE='%d'", __ARM_HAVE_5TE);
Output:
__ARM_ARCH__='5'
__ARM_HAVE_5TE='1'
I have next compiler flags:
LOCAL_CFLAGS += -std=c99 -ffast-math -march=armv5te
Besides i have tried replace add instead of qadd - nicely works but with qadd code not compiles.
What i'm doing wrong? Who can provide worked example of qadd command in assembly?
Solution here No qsort_r for Android (or how to disable force Thumb to use CLZ in Android ARM code)
In your Android.mk file, add ".arm" to the filenames and they will get
compiled as ARM mode instead of Thumb mode (e.g. sort.c.arm). I've had
mixed Thumb/ARM code in an Android native library and it worked fine.
Question is closed.

cross compiling for android using NDK fails with compiler error

I'm compiling a nexus one android kernel from source as found on HTCs developer website. I've obtained an ARM tool chain by DLing the android NDK from the android dev site. I am able to run make clean and make defconfig without incident, but when I run make, it only gets so fare before running into compiler errors.
Currently i see the following:
$MY_DIR/nexus_one/arch/arm/include/asm/glue.h:156:29: error: '#' is not followed by a macro parameter
The offending line is:
1 /*
2 * Instruction Fault Status Register. (New register as of ARMv6)
3 * If processor has IFSR then set value, else set translation fault
4 */
5 #if defined(CONFIG_CPU_ABRT_EV7) || defined(CONFIG_CPU_ABRT_EV6)
6 # define CPU_PABORT_IFSR(reg) mrc p15, 0, reg, cr5, cr0, 1 #asm macro;
7 #else
8 # define CPU_PABORT_IFSR(reg) mov reg, #5 #asm macro;
9 #endif
Specifically, line 8 above is what hoses the compiler. Apparently you can't have that second # sign, but i'm not really sure whats going on in this code, and it looks pretty important so i don't want to touch it.
I'm guessing i'm compiling with the wrong tool chain maybe? Or perhaps i have configured things wrong somehow? Does any one have any idea what this is all about?
thanks,
brian
I strongly recommend you to use CodeSourcery toolchain for Linux for compiling Linux kernel.
CodeSourcery GNU Toolchain for ARM Processors: 2008q1-126 version
Turns out it was nothing to do with the specific toolchain. The # sign needed 'escaping' of some sort. The solution was as follows:
/* this is needed to get the mov reg, 5 macro to compile and function correctly */
#define hash_hackery #
#define f(x) x
#if defined(CONFIG_CPU_ABRT_EV7) || defined(CONFIG_CPU_ABRT_EV6)
# define CPU_PABORT_IFSR(reg) mrc p15, 0, reg, cr5, cr0, 1 #asm macro;
#else
# define CPU_PABORT_IFSR(reg) mov reg, f(hash_hackery)5 #asm macro;
#endif
This post was very informative in finding the answer.

Categories

Resources