I'm trying to build some features of WebRTC into a project. We had previously gotten some C-only code functioning, and I'm trying to add more files. The new files are C++, and when I run ndk-build
I'm getting errors related to the C++ includes:
[armeabi] Compile++ thumb: zello.webrtc <= audio_frame.cc
In file included from libwebrtc/jni/libwebrtc/api/audio/audio_frame.cc:15:
libwebrtc/jni/libwebrtc/rtc_base/checks.h:36:10: fatal error:
'sstream' file not found
#include <sstream>
^~~~~~~~~
1 error generated.
My Application.mk
files includes
APP_ABI := armeabi armeabi-v7a arm64-v8a x86 x86_64
APP_OPTIM := release
APP_PLATFORM := android-15
APP_STL := c++_shared
APP_CPPFLAGS := -fexceptions
NDK_TOOLCHAIN_VERSION := clang
and my Android.mk
file includes
LOCAL_CPPFLAGS := -std=c++11
LOCAL_CPP_EXTENSION := .cpp .cc
LOCAL_SRC_FILES := \
webrtc-jni.cpp \
libwebrtc/api/audio/audio_frame.cc \
...
I've tried explicitly adding
LOCAL_C_INCLUDES += $(NDK_ROOT)/sources/cxx-stl/llvm-libc++/include
but that just leads to more errors about undefined functions, and doesn't seem like it should be necessary in the first place. I've also tried specifying all the other values for APP_STL
with no effect.
I am building with NDK 16b, since we still need to support armeabi
devices.
Thanks in advance for any suggestions.
EDIT: When I run ndk-build V=1
I see that ndk-build
is probably using the wrong STL header directory:
... -I${NDK_ROOT}/sources/cxx-stl/system/include ...
but I've defined APP_STL
as c++_shared
, which I think should be looking in a different directory.
The solution was to put the APP_STL
definition in the top-level Application.mk
file. Our app is structured like
top/Application.mk
top/Android.mk
top/...
top/submodule1/jni/Application.mk
top/submodule1/jni/Android.mk
top/submodule1/jni/...
top/submodule2/jni/Application.mk
top/submodule2/jni/Android.mk
top/submodule2/jni/...
...
I'd defined APP_STL
in one of the submodule Application.mk
files, which may have been entirely ignored? Moving the definition to the top level file got the build working correctly.