2

I am writing a C code which I wish to run in android using ndk. I have glibc library in the code which as I understood is difficult to port directly. Hence I tried to use libc instead from the bionic repository in github. I am facing numerous errors while building it.

Could anyone explain how to include libc in a step by step procedure(or guide me to some source). I have searched a lot and was unable to find a tutorial anywhere.

These are the errors I get:

In file included from jni/libc/private/ScopedPthreadMutexLocker.h:22:0,
                     from jni/libc/bionic/malloc_debug_common.cpp:47:
    jni/libc/private/bionic_macros.h:27:31: warning: defaulted and deleted functions only available with -std=c++11 or -std=gnu++11 [enabled by default]
       TypeName(const TypeName&) = delete;      \
                                   ^
    jni/libc/private/ScopedPthreadMutexLocker.h:37:3: note: in expansion of macro 'DISALLOW_COPY_AND_ASSIGN'
       DISALLOW_COPY_AND_ASSIGN(ScopedPthreadMutexLocker);
       ^
    jni/libc/private/bionic_macros.h:28:37: warning: defaulted and deleted functions only available with -std=c++11 or -std=gnu++11 [enabled by default]
       void operator=(const TypeName&) = delete
                                         ^
    jni/libc/private/ScopedPthreadMutexLocker.h:37:3: note: in expansion of macro 'DISALLOW_COPY_AND_ASSIGN'
       DISALLOW_COPY_AND_ASSIGN(ScopedPthreadMutexLocker);
       ^
    In file included from jni/libc/bionic/jemalloc.h:20:0,
                     from jni/libc/bionic/malloc_debug_common.cpp:50:
    jni/libc/jemalloc/jemalloc.h:108:36: error: declaration of C function 'size_t malloc_usable_size(void*)' conflicts with
     #  define JEMALLOC_CXX_THROW throw()
                                        ^
    jni/libc/jemalloc/jemalloc.h:231:43: note: in expansion of macro 'JEMALLOC_CXX_THROW'
         JEMALLOC_USABLE_SIZE_CONST void *ptr) JEMALLOC_CXX_THROW;
                                               ^
    In file included from /home/yogi/android-ndk/platforms/android-21/arch-arm/usr/include/string.h:33:0,
                     from /home/yogi/android-ndk/platforms/android-21/arch-arm/usr/include/signal.h:35,
                     from /home/yogi/android-ndk/platforms/android-21/arch-arm/usr/include/pthread.h:33,
                     from jni/libc/bionic/malloc_debug_common.h:36,
                     from jni/libc/bionic/malloc_debug_common.cpp:40:
    /home/yogi/android-ndk/platforms/android-21/arch-arm/usr/include/malloc.h:36:15: error: previous declaration 'size_t malloc_usable_size(const void*)' here
     extern size_t malloc_usable_size(const void* p);
                   ^
    jni/libc/bionic/malloc_debug_common.cpp:51:27: error: 'je_calloc' was not declared in this scope
     #define Malloc(function)  je_ ## function
                               ^
    jni/libc/bionic/malloc_debug_common.cpp:67:3: note: in expansion of macro 'Malloc'
       Malloc(calloc),
       ^
    jni/libc/bionic/malloc_debug_common.cpp:51:27: error: 'je_free' was not declared in this scope
     #define Malloc(function)  je_ ## function
                               ^
    jni/libc/bionic/malloc_debug_common.cpp:68:3: note: in expansion of macro 'Malloc'
       Malloc(free),
       ^
    jni/libc/bionic/malloc_debug_common.cpp:51:27: error: 'je_malloc' was not declared in this scope
     #define Malloc(function)  je_ ## function
                               ^
    jni/libc/bionic/malloc_debug_common.cpp:70:3: note: in expansion of macro 'Malloc'
       Malloc(malloc),
       ^
    jni/libc/bionic/malloc_debug_common.cpp:51:27: error: 'je_malloc_usable_size' was not declared in this scope
     #define Malloc(function)  je_ ## function
                               ^
    jni/libc/bionic/malloc_debug_common.cpp:71:3: note: in expansion of macro 'Malloc'
       Malloc(malloc_usable_size),
       ^
    jni/libc/bionic/malloc_debug_common.cpp:51:27: error: 'je_posix_memalign' was not declared in this scope
     #define Malloc(function)  je_ ## function
                               ^
    jni/libc/bionic/malloc_debug_common.cpp:73:3: note: in expansion of macro 'Malloc'
       Malloc(posix_memalign),
       ^
    jni/libc/bionic/malloc_debug_common.cpp:51:27: error: 'je_realloc' was not declared in this scope
     #define Malloc(function)  je_ ## function
                               ^
    jni/libc/bionic/malloc_debug_common.cpp:77:3: note: in expansion of macro 'Malloc'
       Malloc(realloc),
       ^
    jni/libc/bionic/malloc_debug_common.cpp:51:27: error: 'je_valloc' was not declared in this scope
     #define Malloc(function)  je_ ## function
                               ^
    jni/libc/bionic/malloc_debug_common.cpp:79:3: note: in expansion of macro 'Malloc'
       Malloc(valloc),
       ^
    jni/libc/bionic/malloc_debug_common.cpp: In function 'void get_malloc_leak_info(uint8_t**, size_t*, size_t*, size_t*, size_t*)':
    jni/libc/bionic/malloc_debug_common.cpp:191:96: error: 'je_malloc' was not declared in this scope
       HashEntry** list = static_cast<HashEntry**>(Malloc(malloc)(sizeof(void*) * g_hash_table.count));
                                                                                                    ^
    jni/libc/bionic/malloc_debug_common.cpp:214:22: error: 'je_free' was not declared in this scope
         Malloc(free)(list);
                          ^
    jni/libc/bionic/malloc_debug_common.cpp:236:20: error: 'je_free' was not declared in this scope
       Malloc(free)(list);
                        ^
    jni/libc/bionic/malloc_debug_common.cpp: In function 'void free_malloc_leak_info(uint8_t*)':
    jni/libc/bionic/malloc_debug_common.cpp:240:20: error: 'je_free' was not declared in this scope
       Malloc(free)(info);
                        ^
    jni/libc/bionic/malloc_debug_common.cpp: In function 'size_t malloc_usable_size(const void*)':
    jni/libc/bionic/malloc_debug_common.cpp:262:53: error: declaration of C function 'size_t malloc_usable_size(const void*)' conflicts with
     extern "C" size_t malloc_usable_size(const void* mem) {
                                                         ^
    In file included from jni/libc/bionic/jemalloc.h:20:0,
                     from jni/libc/bionic/malloc_debug_common.cpp:50:
    jni/libc/jemalloc/jemalloc.h:70:33: error: previous declaration 'size_t malloc_usable_size(void*)' here
     #  define je_malloc_usable_size malloc_usable_size
                                     ^
    jni/libc/jemalloc/jemalloc.h:230:41: note: in expansion of macro 'je_malloc_usable_size'
     JEMALLOC_EXPORT size_t JEMALLOC_NOTHROW je_malloc_usable_size(
                                             ^
    make: *** [obj/local/armeabi-v7a/objs/c/bionic/malloc_debug_common.o] Error 1

How to fix it? Thanks!

re3el
  • 735
  • 2
  • 12
  • 28
  • What sort of errors? – 18446744073709551615 Oct 12 '15 at 09:23
  • @18446744073709551615: edited the question. Please have a look – re3el Oct 12 '15 at 09:34
  • Some of them are warnings; they suggest you should add the switch `-std=gnu++11` to the build parameters. As to je_* stuff, you have not posted the most interesting error message, it looks like the code tries to define it, but something does not work. What is that `Error 1`? – 18446744073709551615 Oct 12 '15 at 10:42
  • @18446744073709551615: for the je_* stuff, has it got anything to do with [syntax error] (https://stackoverflow.com/questions/33078953/extern-c-c-confusion-in-ndk-syntax-error-eclipse) shown at the `extern C` statements in `jemalloc.h` header? I don't know about error 1. Nothing else is printed there. – re3el Oct 12 '15 at 10:50

1 Answers1

3

I tried to use libc instead from the bionic repository in github.

It appears that you've copied Bionic libc into your project, and are trying to build it.

Don't. A prebuilt copy is already provided to you as part of the ndk, and you don't need to do anything special to use it: the ndk-provided compiler will do that automatically.

You should concentrate on building your application, not copying random libc variants and trying to build them.

Employed Russian
  • 199,314
  • 34
  • 295
  • 362