gpt4 book ai didi

android - 将 C 程序迁移到 Android NDK

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:05:42 28 4
gpt4 key购买 nike

我是 C/C++ 和 Android NDK 的初学者,我在尝试创建原生库时遇到了问题。我的代码在 CDT 上使用 MinGW 编译,但是当我在 JNI 文件上编写相同的代码时,出现错误。

我的代码是:

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

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

插件显示:

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

这是来自 CDT 上 MinGW 的 header :

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

这是来自 Android NDK 的 header :

extern void*  memcpy(void *, const void *, size_t);

最佳答案

使用 Eclipse 进行 NDK 开发时存在一个已知的索引问题。

在这里阅读:https://code.google.com/p/android/issues/detail?id=33788

在底部附近有一个我自己使用的合理解决方法:

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.

然后我必须在 Project Properties -> C/C++ General -> Paths and Symbols 下手动添加我自己的包含目录和定义

值得注意的是,您的代码编译 良好。如果愿意,您可以关闭索引,但如果您仍然想要索引的优势,则必须解决这个问题。

关于android - 将 C 程序迁移到 Android NDK,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13924184/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com