Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Migrate a C program to Android NDK

I am a beginner with C/C++ and the Android NDK, and I have a problem trying to create a native library. My code compiles using MinGW on CDT, but when I write the same code on a JNI file, there is an error.

My code is:

int n = 7;
int positions[n];   
int final_order[n];

memcpy(positions, final_order,sizeof(final_order));

The plugin shows me:

Invalid arguments 'Candidates are: void * memcpy(void *, const void *, ?)'

This the header from MinGW on CDT:

_CRTIMP void* __cdecl __MINGW_NOTHROW   memcpy (void*, const void*, size_t);

This the header from the Android NDK:

extern void*  memcpy(void *, const void *, size_t);
like image 926
Ricardo Avatar asked Feb 18 '23 03:02

Ricardo


1 Answers

There is a known indexing problem when using Eclipse to do NDK development.

Read about it here: https://code.google.com/p/android/issues/detail?id=33788

Near the bottom there is a reasonable workaround that I myself use:

What we want is to use the Android GCC toolchain but change the actual tools and modify the discovery options so that the include paths and symbols are correct.

Go into C/C++ Buid \ Tool Chain editor

Make sure Android GCC is the selected toolchain and Android Builder is the selected builder.

Click on "Select Tools" Select "Allow all changes" Remove the Android GCC Compiler Add "GCC C Compiler" and "GCC C++ Compiler" so that we can index both c and cpp headers.

If you would look at "Paths and Symbols" you would see we have both GNU C and GNU C++ languages, but of course the built-in include paths are wrong. luckily there is a fix for that.

Go into C/C++ Build \ Discovery Options Change Discovery profiles scope to "Configuration-wide" Make sure the Discovery profile is using "AndroidPerProjectProfile" and make sure both checkboxes are checked.

I then have to manually add my own include directories and definies under Project Properties -> C/C++ General -> Paths and Symbols

It's worth noting that your code compiles fine. You can turn off indexing if you like, but if you still want the advantages of indexing you'll have to work around the issue.

like image 195
krsteeve Avatar answered Feb 20 '23 18:02

krsteeve