All Oculus Quest developers MUST PASS the concept review prior to gaining publishing access to the Quest Store and additional resources. Submit a concept document for review as early in your Quest application development cycle as possible:

For additional information and context, please see "Submitting Your App to the Oculus Quest Store".
Welcome to the Oculus Developer Forums!

Your participation on the forum is subject to the Oculus Code of Conduct.

In general, please be respectful and kind. If you violate the Oculus Code of Conduct, your access to the developer forums may be revoked at the discretion of Oculus staff.

Why it seems it's not possible to use CPP in the NDK sources ?

GilesGoatGilesGoat Posts: 151
Hiro Protagonist
edited January 15 in Oculus Quest Development
I am still messing up with code and trying to get my things work.

My stuff is entirely done in CPP however I noticed all sources in the NDK samples are plain C-99 ..

If I take the VrCubeWorld_Vulkan sample and I try to add to the project a simple "Banana.cpp" file that contains as simple as :

#include <stdio.h>
#include <stdbool.h>
bool InitWorld (void *p)
return true;
Then I modify the file as :

LOCAL_MODULE          := vrcubeworldvk
#LOCAL_CFLAGS := -std=c99 -Werror

LOCAL_SRC_FILES := ../../../Src/VrCubeWorld_Vulkan.c \
../../../Src/Banana.cpp \
And then from within I call :
extern bool InitWorld (void *p);

void android_main( struct android_app * app )
    ALOGV( "----------------------------------------------------------------" );
    ALOGV( "android_app_entry()" );
    ALOGV( "    android_main()" );


When I try to compile it spews those sort of errors :

Build command failed.
Error while executing process /home/gilesgoat/Android/Sdk/ndk/20.1.5948944/ndk-build with arguments {NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=/home/gilesgoat/OVR-SDK-Mobile/VrSamples/VrCubeWorld_Vulkan/Projects/Android/jni/ NDK_APPLICATION_MK=/home/gilesgoat/OVR-SDK-Mobile/VrSamples/VrCubeWorld_Vulkan/Projects/Android/jni/ APP_ABI=arm64-v8a NDK_ALL_ABIS=arm64-v8a NDK_DEBUG=1 APP_PLATFORM=android-21 NDK_OUT=/home/gilesgoat/OVR-SDK-Mobile/VrSamples/VrCubeWorld_Vulkan/Projects/Android/build/intermediates/ndkBuild/debug/obj NDK_LIBS_OUT=/home/gilesgoat/OVR-SDK-Mobile/VrSamples/VrCubeWorld_Vulkan/Projects/Android/build/intermediates/ndkBuild/debug/lib V=0 -j4 -C/home/gilesgoat/OVR-SDK-Mobile/VrSamples/VrCubeWorld_Vulkan/Projects/Android APP_PLATFORM=android-21 NDK_TOOLCHAIN_VERSION=clang APP_STL=c++_static NDK_DEBUG=1 OVR_DEBUG=1 USE_ASAN=1 /home/gilesgoat/OVR-SDK-Mobile/VrSamples/VrCubeWorld_Vulkan/Projects/Android/build/intermediates/ndkBuild/debug/obj/local/arm64-v8a/}
make: Entering directory `/home/gilesgoat/OVR-SDK-Mobile/VrSamples/VrCubeWorld_Vulkan/Projects/Android'
[arm64-v8a] Compile        : vrcubeworldvk <= VrCubeWorld_Vulkan.c
[arm64-v8a] Compile++      : vrcubeworldvk <= Banana.cpp
[arm64-v8a] Compile        : vrcubeworldvk <= Framework_Vulkan.c
[arm64-v8a] Prebuilt       : <= /home/gilesgoat/OVR-SDK-Mobile/VrSamples/VrCubeWorld_Vulkan/Projects/Android/jni/../../../../../VrApi/Projects/AndroidPrebuilt/jni/../../../Libs/Android/arm64-v8a/Debug/
[arm64-v8a] StaticLibrary  : libandroid_native_app_glue.a
[arm64-v8a] SharedLibrary  :
/home/gilesgoat/OVR-SDK-Mobile/VrSamples/VrCubeWorld_Vulkan/Projects/Android/build/intermediates/ndkBuild/debug/obj/local/arm64-v8a/objs-debug/vrcubeworldvk/__/__/__/Src/VrCubeWorld_Vulkan.o: In function `android_main':
/home/gilesgoat/OVR-SDK-Mobile/VrSamples/VrCubeWorld_Vulkan/Projects/Android/jni/../../../Src/VrCubeWorld_Vulkan.c:1429: undefined reference to `InitWorld'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [/home/gilesgoat/OVR-SDK-Mobile/VrSamples/VrCubeWorld_Vulkan/Projects/Android/build/intermediates/ndkBuild/debug/obj/local/arm64-v8a/] Error 1
make: Leaving directory `/home/gilesgoat/OVR-SDK-Mobile/VrSamples/VrCubeWorld_Vulkan/Projects/Android'

If I "transform" all in .cpp gets even worse, it cannot find all the ovrVK... functions.
Is any way to "properly MIX" cpp and C in the VRAPI samples or the only solution would be to "confine" all the CPP code into a precompiled lib and call the few needed functions via some C wrapper ?

Why the examples do not support CPP ?

If that Banana.cpp is renamed in Banana.c all works ( but you can't use CPP stuff in ).



  • GilesGoatGilesGoat Posts: 151
    Hiro Protagonist
    Well .. in some way I managed to get it working ..

    Basically I ended up with a "C wrapper" and quite a few " extern "C" { } " and #ifdef _csplus and stuff like that, I still don't know why the sources are not "natively in CPP" but I wonder if I has to do with the JNI interface ?

    So yeah seems to be fine as long as you keep the native_glue and such in pure C calling just pure C functions from there leaving the CPP stuff "outside".

    Today 15:57 GMT first time I manage to actually run some Vulkan code on the Quest.

Sign In or Register to comment.