如何用android ndk和eclipse编译c++11代码?
我正在使用 android NDK r8d 和 eclipse Juno.我正在尝试在原生 android 项目中编译使用 C++11 内容的 C++ 代码,例如 mutex
、lock_guard
、shared_ptr
等在日食中.
I'm using android NDK r8d, and eclipse Juno. I'm trying to compile C++ code which uses C++11 stuff like mutex
, lock_guard
, shared_ptr
, etc. in a native android project in eclipse.
我收到如下错误:
错误:‘shared_ptr’不是‘std’的成员"
"error: 'shared_ptr' is not a member of 'std'"
致命错误:互斥锁:没有这样的文件或目录"
"fatal error: mutex: No such file or directory"
我在这里遇到了类似的问题.它似乎对他们有用,但那里的解释不完整,所以我无法让它对我有用.
I came across a similar question here. It seems to work for them, but the explanation there is not complete so I can't get it to work for me.
我将 "NDK_TOOLCHAIN_VERSION=4.7"
添加到 Application.mk
和 "LOCAL_CFLAGS += -std=c++11"
到Android.mk
文件.仍然无法编译.
I added "NDK_TOOLCHAIN_VERSION=4.7"
to the Application.mk
and "LOCAL_CFLAGS += -std=c++11"
to Android.mk
file. Still, it doesn't compile.
在上面的链接中说:
"确保标准库包含路径(如/android-ndk-r8d/sources/cxx-stl/gnu-libstdc++/4.7/include) 在目标设置."
"Be sure that the standard library include path (like /android-ndk-r8d/sources/cxx-stl/gnu-libstdc++/4.7/include) is in the target settings."
如何以及在何处插入?
我还在 Eclipse IDE 中遇到错误(在源代码上,在编译之前).我知道我应该定义 "__GXX_EXPERIMENTAL_CXX0X__"
来解决它们,但我只是不知道把它放在哪里.
I also get errors in eclipse IDE (on the source, before compiling). I know I should define "__GXX_EXPERIMENTAL_CXX0X__"
to resolve them but I just don't know where to put it.
所以,如果有人可以发布一个答案,并完整解释如何编译和使 eclipse 与 C++11 一起工作,那就太好了.
So, if someone could post an answer with a full explanation of how to compile and make eclipse work with C++11 it would be great.
推荐答案
关于你的第一个问题:
转到项目 > 属性 > C/C++ 常规/路径和符号
Go to Project > Properties > C/C++ General / Paths and Symbols
在包含"选项卡中,添加正确的目录,例如/android-ndk-r8d/sources/cxx-stl/gnu-libstdc++/4.7/include
In the "Includes" tab, add the proper directory, e.g. /android-ndk-r8d/sources/cxx-stl/gnu-libstdc++/4.7/include
关于你的第二个问题,我也在寻找答案.绝对不清楚如何在 Eclipse 中定义 GXX_EXPERIMENTAL_CXX0X 宏.
Regarding your second question, I'm also looking for an answer. It is absolutely not clear how to define the GXX_EXPERIMENTAL_CXX0X macro in Eclipse.
有人说它应该作为预定义的宏添加到索引器中",但看起来我们都找不到实现它的方法......
Some say that it should be "added as a predefined macro to the indexer", but it looks like we both could not find a way to implement that...
我在其他地方读到它应该被添加到C/C++ General/Paths and Symbols/Symbols/GNU C++",但我在我的 Indigo 版本中找不到Symbols/GNU C++"部分.
I have read elsewhere that it should be added to "C/C++ General / Paths and Symbols / Symbols / GNU C++" but I can't find the "Symbols / GNU C++" part in my version of Indigo.
相关文章