迁移C程序到Android NDK [英] Migrate a C program to Android NDK

查看:188
本文介绍了迁移C程序到Android NDK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用C / C ++和Android NDK一个初学者,我有一个问题想创建一个本地库。我的code编译使用MinGW的CDT上,但是当我写一个JNI文件的同一code,有一个错误。

我的code是:

  INT N = 7;
INT位置[N];
INT final_order [N];

的memcpy(位置,final_order,的sizeof(final_order));
 

该插件显示我:

 的参数无效候选人是:void *的的memcpy(?无效*,常量无效*,)'
 

该从对MinGW的CDT头:

  _CRTIMP无效* __cdecl __MINGW_NOTHROW的memcpy(void *的,常量无效*,为size_t);
 

这从Android NDK头:

 的extern无效*的memcpy(void *时,常量无效*,为size_t);
 

解决方案

有使用Eclipse做NDK开发的时候是一个已知的索引问题。

在这里阅读有关:<一href="https://$c$c.google.com/p/android/issues/detail?id=33788">https://$c$c.google.com/p/android/issues/detail?id=33788

靠近底部有一个合理的解决方法,我自己用的:

  

我们要的是使用Android工具链的GCC,但改变实际的工具和修改发现选项,以使包括路径和符号是正确的。

     

走进C / C ++打造专业化\工具链编辑器

     

确认Android的GCC是所选择的工具链和Android Builder是选定的建设者。

     

点击选择工具   选择允许所有更改   除去Android的GCC编译   加入GCC C编译器和GCC C ++编译器,这样我们可以索引C和CPP头。

     

如果你会看路径和符号,你会看到我们既有GNU C和GNU C ++语言中,但当然内置的包括路径是错误的。幸运的是有一个固定的这一点。

     

走进C / C ++编译\查找选项   更改寻找配置文件范围的配置范围   确保发现配置文件使用AndroidPerProjectProfile,并确保这两个复选框被选中。

我那么必须手动添加自己的包括在目录和definies项目属性 - &GT; C / C ++一般 - &GT;路径和符号

值得一提的是,您code 编译罚款。您可以关闭索引,如果你喜欢,但如果你仍想索引的优势,你必须要解决的问题。

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);

解决方案

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.

这篇关于迁移C程序到Android NDK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆