Using Qt codes in Android application - android

I have an Android application in Android Studio and I want to use Qt C++ codes in my app. I have used pure C++ codes in my android app using cmake and NDK recently and I could interact with my pure C++ and now I want to use Qt C++ codes.
To do this, I have installed Qt with Android capability. After that I copied Qt5.12.7/5.12.7/android_arm64_v8a/lib/*.so and includes file to my Android App /etc/ folder and I created a simple main.cpp and CMakeLists.txt files as follow:
main.cpp
#include <QString>
#include <QDebug>
int main(int argc, char *argv[])
{
QString test="HELLO WORLD!";
qDebug()<<test;
return 0;
}
CMakeLists.txt
cmake_minimum_required(VERSION 3.4.1)
include_directories(etc/headerFile)
link_directories(etc/libs)
add_library(po-lib SHARED main.cpp)
target_link_libraries(po-lib -lQt5Core)
As seen in the above files, I want to compile a simple Qt C++ code with dependency on libQtCore.so in my Android App, but after compiling the App, the following errors occur:
Build command failed.
Error while executing process C:\Users\User1\AppData\Local\Android\Sdk\cmake\3.10.2.4988404\bin\ninja.exe with arguments {-C D:\WorkProjects\Horizon\Ga\po\.cxx\cmake\debug\armeabi-v7a po-lib}
ninja: Entering directory `D:\WorkProjects\Horizon\Ga\po\.cxx\cmake\debug\armeabi-v7a'
[1/2] Building CXX object CMakeFiles/po-lib.dir/main.cpp.o
[2/2] Linking CXX shared library D:\WorkProjects\Horizon\Ga\po\build\intermediates\cmake\debug\obj\armeabi-v7a\libpo-lib.so
FAILED: D:/WorkProjects/Horizon/Ga/po/build/intermediates/cmake/debug/obj/armeabi-v7a/libpo-lib.so
cmd.exe /C "cd . && C:\Users\User1\AppData\Local\Android\Sdk\ndk\21.0.6113669\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=armv7-none-linux-androideabi21 --gcc-toolchain=C:/Users/User1/AppData/Local/Android/Sdk/ndk/21.0.6113669/toolchains/llvm/prebuilt/windows-x86_64 --sysroot=C:/Users/User1/AppData/Local/Android/Sdk/ndk/21.0.6113669/toolchains/llvm/prebuilt/windows-x86_64/sysroot -fPIC -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -march=armv7-a -mthumb -Wformat -Werror=format-security -O0 -fno-limit-debug-info -Wl,--exclude-libs,libgcc_real.a -Wl,--exclude-libs,libatomic.a -static-libstdc++ -Wl,--build-id -Wl,--fatal-warnings -Wl,--exclude-libs,libunwind.a -Wl,--no-undefined -Qunused-arguments -shared -Wl,-soname,libpo-lib.so -o D:\WorkProjects\Horizon\Ga\po\build\intermediates\cmake\debug\obj\armeabi-v7a\libpo-lib.so CMakeFiles/po-lib.dir/main.cpp.o -LD:/WorkProjects/Horizon/Ga/po/src/main/cpp/etc/libs_a -LD:/WorkProjects/Horizon/Ga/po/src/main/cpp/etc/libs_so -lQt5Core -latomic -lm && cd ."
C:/Users/User1/AppData/Local/Android/Sdk/ndk/21.0.6113669/toolchains/llvm/prebuilt/windows-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin\ld: warning: skipping incompatible D:/WorkProjects/Horizon/Ga/po/src/main/cpp/etc/libs_so/libQt5Core.so while searching for Qt5Core
C:/Users/User1/AppData/Local/Android/Sdk/ndk/21.0.6113669/toolchains/llvm/prebuilt/windows-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin\ld: error: cannot find -lQt5Core
D:/WorkProjects/Horizon/Ga/po/src/main/cpp/main.cpp:25: error: undefined reference to 'QMessageLogger::debug() const'
D:/WorkProjects/Horizon/Ga/po/src/main/cpp/main.cpp:25: error: undefined reference to 'QDebug::~QDebug()'
D:/WorkProjects/Horizon/Ga/po/src/main/cpp/main.cpp:25: error: undefined reference to 'QDebug::~QDebug()'
D:/WorkProjects/Horizon/Ga/po/src/main/cpp/etc/headerFile\QtCore/qstring.h:700: error: undefined reference to 'QString::fromAscii_helper(char const*, int)'
D:/WorkProjects/Horizon/Ga/po/src/main/cpp/etc/headerFile\QtCore/qdebug.h:155: error: undefined reference to 'QDebug::putString(QChar const*, unsigned int)'
D:/WorkProjects/Horizon/Ga/po/src/main/cpp/etc/headerFile\QtCore/qdebug.h:125: error: undefined reference to 'QTextStream::operator<<(char)'
D:/WorkProjects/Horizon/Ga/po/src/main/cpp/etc/headerFile\QtCore/qarraydata.h:59: error: undefined reference to 'qt_assert(char const*, char const*, int)'
D:/WorkProjects/Horizon/Ga/po/src/main/cpp/etc/headerFile\QtCore/qarraydata.h:239: error: undefined reference to 'QArrayData::deallocate(QArrayData*, unsigned int, unsigned int)'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
I have used both arm64_v8a and armv7 libs in Qt folders but the same errors appear. How can I solve this linker error (incompatible lib)?

Your Qt libraries don't have the same ABI as the binaries you are building (armeabi-v7a). This can be even seen in the error message:
/../../arm-linux-androideabi/bin\ld: warning: skipping incompatible D:/WorkProjects/Horizon/Ga/po/src/main/cpp/etc/libs_so/libQt5Core.so while searching for Qt5Core
To properly run it either install armeabi-v7a version of Qt and make cmake find it, rather than the arm64-v8a (hard-coding the path is a temporary way to do it).
If you are using NDK's cmake toolchain to compile, you can pass ANDROID_ABI variable to cmake while configuring by -DANDROID_ABI=arm64-v8a.

Related

ld: Unknown symbol error when trying to run a C++ library - incorrect CMakeLists.txt settings [duplicate]

This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed last month.
I've downloaded an external c++ library for use inside a Flutter program via FFI. I've set up the FFI correctly, but I'm getting an error whenever I have the use the function from the external library. Here's the function:
#include <iostream>
#include "aoo/include/aoo/aoo.h"
#include "aoo/include/aoo/aoo_server.h"
#include "aoo/include/aoo/aoo_net.h"
extern "C" void initAoo(){
aoo_initialize(0);
std::cout << "Called from init AOO!" << std::endl;
}
When I compile and run to an android device, I get this error:
* What went wrong:
Execution failed for task ':app:externalNativeBuildDebug'.
> Build command failed.
Error while executing process /Users/zacharyhaslam/Library/Android/sdk/cmake/3.10.2.4988404/bin/ninja with arguments {-C /Users/zacharyhaslam/FlutterApplications/state_management_example/android/app/.cxx/cmake/debug/armeabi-v7a add}
ninja: Entering directory `/Users/zacharyhaslam/FlutterApplications/state_management_example/android/app/.cxx/cmake/debug/armeabi-v7a'
[1/2] Building CXX object CMakeFiles/add.dir/cpp/add.cpp.o
[2/2] Linking CXX shared library /Users/zacharyhaslam/FlutterApplications/state_management_example/build/app/intermediates/cmake/debug/obj/armeabi-v7a/libadd.so
FAILED: /Users/zacharyhaslam/FlutterApplications/state_management_example/build/app/intermediates/cmake/debug/obj/armeabi-v7a/libadd.so
: && /Users/zacharyhaslam/Library/Android/sdk/ndk/25.1.8937393/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ --target=armv7-none-linux-androideabi19 --sysroot=/Users/zacharyhaslam/Library/Android/sdk/ndk/25.1.8937393/toolchains/llvm/prebuilt/darwin-x86_64/sysroot -fPIC -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -march=armv7-a -mthumb -Wformat -Werror=format-security -fno-limit-debug-info -static-libstdc++ -Wl,--build-id=sha1 -Wl,--no-rosegment -Wl,--fatal-warnings -Wl,--gc-sections -Wl,--no-undefined -Qunused-arguments -shared -Wl,-soname,libadd.so -o /Users/zacharyhaslam/FlutterApplications/state_management_example/build/app/intermediates/cmake/debug/obj/armeabi-v7a/libadd.so CMakeFiles/add.dir/cpp/add.cpp.o -latomic -lm && :
ld: error: undefined symbol: aoo_initialize
>>> referenced by add.cpp:11 (../../../../../cpp/add.cpp:11)
>>> CMakeFiles/add.dir/cpp/add.cpp.o:(initAoo)
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed
It says ld: error: undefined symbol: aoo_initialize. From my research, I think the problem must be from the way that I set up the compilation settings, so here's my CMakeLists.txt:
cmake_minimum_required(VERSION 3.10.2)
add_library( add
SHARED
cpp/add.cpp
)
include_directories(cpp/aoo/include/aoo/aoo.h)
add_library(aoo cpp/aoo/include/aoo/aoo.h)
set_target_properties(aoo PROPERTIES LINKER_LANGUAGE CXX)
What is wrong with CMakeLists.txt? Am I properly including the files for compilation?
The basic problem is that aoo is not built. You'll need to take care of that.
I assume that your program is the target "add" and the source above is in cpp/add.cpp
Basically need to setup the aoo library correctly and then tell CMake to link your program against it.
add_library(aoo)
target_include_directories(aoo PUBLIC aoo/include)
target_sources(aoo PRIVATE aoo/src/library-source1.cc
aoo/src/library-source2.cc
...)
add_library(add SHARED)
target_sources(add PRIVATE cpp/add.cpp)
target_link_libraries(add PRIVATE aoo)
You will need to find out how aoo needs to be built though.
However, if you setup it well, you can #include <aoo/aoo.h> as CMake will also tell the compiler where to find the includes.
If aoo provides CMake integration, it may also be possible to just use that.

Android Native: CMake linking error: undefined reference to GL functions - even though EGL & GLESv3 included and linked

I am trying to update a GitHub repo, which is a basic OpenGL rendered cube, to a current Android version and project structure. The CMake script seems to be missing something, which I can't figure out. Is it a simple issue of lines in the wrong order?
System: Arch Linux - Kernel 5.0.9, Android Studio 3.5 Canary 13, CMake 3.14.3, Ninja 1.9.0
I created a new Native project in Android Studio and filled in the configurations with the old data. You can see the progress here. I am stuck at trying to link the GL function libraries to the .cpp files, as the terminal output tells me there are undefined references to certain gl... functions.
Terminal output:
Build command failed.
Error while executing process /usr/bin/ninja with arguments {-C /home/snobo/projects/AndroidNativeExample/app/.cxx/cmake/debug/armeabi-v7a nativeegl}
ninja: Entering directory `/home/snobo/projects/AndroidNativeExample/app/.cxx/cmake/debug/armeabi-v7a'
[1/2] Building CXX object CMakeFiles/nativeegl.dir/renderer.cpp.o
[2/2] Linking CXX shared library /home/snobo/projects/AndroidNativeExample/app/build/intermediates/cmake/debug/obj/armeabi-v7a/libnativeegl.so
FAILED: /home/snobo/projects/AndroidNativeExample/app/build/intermediates/cmake/debug/obj/armeabi-v7a/libnativeegl.so
: && /home/snobo/Android/android-ndk-r19c/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ --target=armv7-none-linux-androideabi28 --gcc-toolchain=/home/snobo/Android/android-ndk-r19c/toolchains/llvm/prebuilt/linux-x86_64 --sysroot=/home/snobo/Android/android-ndk-r19c/toolchains/llvm/prebuilt/linux-x86_64/sysroot -fPIC -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -mfpu=vfpv3-d16 -fno-addrsig -march=armv7-a -mthumb -mfpu=neon -Wa,--noexecstack -Wformat -Werror=format-security -stdlib=libc++ -std=c++14 -O0 -fno-limit-debug-info -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -static-libstdc++ -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--exclude-libs,libunwind.a -Wl,--no-undefined -Qunused-arguments -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,libnativeegl.so -o /home/snobo/projects/AndroidNativeExample/app/build/intermediates/cmake/debug/obj/armeabi-v7a/libnativeegl.so CMakeFiles/nativeegl.dir/jniapi.cpp.o CMakeFiles/nativeegl.dir/renderer.cpp.o /home/snobo/Android/android-ndk-r19c/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/arm-linux-androideabi/28/liblog.so -landroid -lGLESv3 -lEGL -latomic -lm && :
/home/snobo/projects/AndroidNativeExample/app/src/main/jni/renderer.cpp:230: error: undefined reference to 'glShadeModel'
/home/snobo/projects/AndroidNativeExample/app/src/main/jni/renderer.cpp:236: error: undefined reference to 'glMatrixMode'
/home/snobo/projects/AndroidNativeExample/app/src/main/jni/renderer.cpp:237: error: undefined reference to 'glLoadIdentity'
/home/snobo/projects/AndroidNativeExample/app/src/main/jni/renderer.cpp:238: error: undefined reference to 'glFrustumf'
/home/snobo/projects/AndroidNativeExample/app/src/main/jni/renderer.cpp:262: error: undefined reference to 'glMatrixMode'
/home/snobo/projects/AndroidNativeExample/app/src/main/jni/renderer.cpp:263: error: undefined reference to 'glLoadIdentity'
/home/snobo/projects/AndroidNativeExample/app/src/main/jni/renderer.cpp:264: error: undefined reference to 'glTranslatef'
/home/snobo/projects/AndroidNativeExample/app/src/main/jni/renderer.cpp:265: error: undefined reference to 'glRotatef'
/home/snobo/projects/AndroidNativeExample/app/src/main/jni/renderer.cpp:266: error: undefined reference to 'glRotatef'
/home/snobo/projects/AndroidNativeExample/app/src/main/jni/renderer.cpp:268: error: undefined reference to 'glEnableClientState'
/home/snobo/projects/AndroidNativeExample/app/src/main/jni/renderer.cpp:269: error: undefined reference to 'glEnableClientState'
/home/snobo/projects/AndroidNativeExample/app/src/main/jni/renderer.cpp:272: error: undefined reference to 'glVertexPointer'
/home/snobo/projects/AndroidNativeExample/app/src/main/jni/renderer.cpp:273: error: undefined reference to 'glColorPointer'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
Here is one of the methods that includes the errors from above:
void Renderer::drawFrame()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0, 0, -3.0f);
glRotatef(_angle, 0, 1, 0);
glRotatef(_angle*0.25f, 1, 0, 0);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glFrontFace(GL_CW);
glVertexPointer(3, GL_FIXED, 0, vertices);
glColorPointer(4, GL_FIXED, 0, colors);
glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_BYTE, indices);
_angle += 1.2f;
}
CMakeLists.txt:
project(AndroidNativeExample C CXX)
cmake_minimum_required(VERSION 3.4.1)
add_library(
nativeegl
SHARED
jniapi.cpp renderer.cpp)
include_directories(src/main/cpp/include/)
find_library( # Sets the name of the path variable.
log-lib
log)
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package(Threads REQUIRED)
target_link_libraries(nativeegl Threads::Threads)
add_library(app-glue
STATIC
${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c)
target_link_libraries(nativeegl ${app-glue})
target_link_libraries(nativeegl ${log-lib})
target_link_libraries(nativeegl android)
target_link_libraries(nativeegl GLESv3)
target_link_libraries(nativeegl EGL)
To my knowledge (which indeed is quite limited) this should link all necessary libraries and not result in an error. But somehow a few function references are undefined.
Please let me know if you have any ideas, I will try each and give feedback.
The missing functions glShadeModel etc are OpenGL functions and are not available in OpenGL ES.
As your project managed to compile (and failed when linking) you must be including OpenGL headers from another source instead of the OpenGL ES header from the Android NDK.

Android OpenCV Linking CXX shared library fails

I had a working Android Studio installation where I was programming an app with native C++ code and OpenCV. I stopped for kind of one year the development and resumed it a few days ago.
Since Android Studio was complaining that there were updates available I decided to update everything (Gradle, CMake, NDK...), and this was my error. Now the build stops at the linking phase:
Build command failed.
Error while executing process C:\Users\Marco\AppData\Local\Android\Sdk\cmake\3.6.4111459\bin\cmake.exe with arguments {--build C:\Users\Marco\AndroidStudioProjects\MyProject\app\.externalNativeBuild\cmake\debug\x86_64 --target CppFilter}
[1/2] Building CXX object CMakeFiles/CppFilter.dir/src/main/cpp/CppFilter.cpp.o
[2/2] Linking CXX shared library ..\..\..\..\build\intermediates\cmake\debug\obj\x86_64\libCppFilter.so
FAILED: cmd.exe /C "cd . && C:\Users\Marco\AppData\Local\Android\Sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=x86_64-none-linux-android21 --gcc-toolchain=C:/Users/Marco/AppData/Local/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64 --sysroot=C:/Users/Marco/AppData/Local/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/sysroot -fPIC -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fno-addrsig -Wa,--noexecstack -Wformat -Werror=format-security -stdlib=libc++ -O3 -O0 -fno-limit-debug-info -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -static-libstdc++ -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined -Qunused-arguments -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -Wl,--exclude-libs,libippicv.a -Wl,--exclude-libs,libippiw.a -shared -Wl,-soname,libCppFilter.so -o ..\..\..\..\build\intermediates\cmake\debug\obj\x86_64\libCppFilter.so #CMakeFiles/CppFilter.rsp && cd ."
D:/Downloads/opencv-3.3.1-android-sdk/OpenCV-android-sdk/sdk/native/libs/x86_64/libopencv_core.a(system.cpp.o):system.cpp:function cv::ipp::IPPInitSingleton::IPPInitSingleton(): error: undefined reference to 'std::cerr'
D:/Downloads/opencv-3.3.1-android-sdk/OpenCV-android-sdk/sdk/native/libs/x86_64/libopencv_core.a(system.cpp.o):system.cpp:function cv::ipp::IPPInitSingleton::IPPInitSingleton(): error: undefined reference to 'std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, long)'
D:/Downloads/opencv-3.3.1-android-sdk/OpenCV-android-sdk/sdk/native/libs/x86_64/libopencv_core.a(system.cpp.o):system.cpp:function cv::ipp::IPPInitSingleton::IPPInitSingleton(): error: undefined reference to 'std::ostream::put(char)'
D:/Downloads/opencv-3.3.1-android-sdk/OpenCV-android-sdk/sdk/native/libs/x86_64/libopencv_core.a(system.cpp.o):system.cpp:function cv::ipp::IPPInitSingleton::IPPInitSingleton(): error: undefined reference to 'std::ostream::flush()'
... many more of the same type ...
clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
I basically followed the default setup steps explained, for example:
https://android.jlelse.eu/a-beginners-guide-to-setting-up-opencv-android-library-on-android-studio-19794e220f3c
Can OpenCV for Android leverage the standard C++ Support to get native build support on Android Studio 2.2 for Windows?
Any ideas about what can be the cause of this error?
Actual version of Android Studio: 3.4, former: 2.something
Apparently it was due to the OpenCV version (3.3.1) being compiled in a way that was not compatible with newer versions of NDK or the Android SDK Build tools, check for example: Why am I still getting undefined reference errors linking a static library with CMake in Android NDK?
I downgraded NDK and Android SDK Build tools. Now it's working.

ROLI JUCE Android CMake Error, Generated blank demo app fails to compile in Android Studio

Having downloaded the Projucer I generated a blank application, I exported it to Android (in debug mode) and opened it in Android studio.
After fixing errors to do with the versions of the SDK and NDK (I updated the references to build with the most recent version) the code fails to build at the CMake stage with the below error output:
Build command failed.
Error while executing process /Users/user/Library/Android/sdk/cmake/3.6.4111459/bin/cmake with arguments {--build /Users/user/Documents/Blank/Builds/Android/app/.externalNativeBuild/cmake/debug_Debug/x86 --target juce_jni}
[1/16] Building C object CMakeFiles/cpufeatures.dir/Users/user/Library/Android/sdk/ndk-bundle/sources/android/cpufeatures/cpu-features.c.o
[2/16] Linking C static library libcpufeatures.a
[3/16] Building CXX object CMakeFiles/juce_jni.dir/Users/user/Documents/Blank/JuceLibraryCode/include_juce_audio_basics.cpp.o
[4/16] Building CXX object CMakeFiles/juce_jni.dir/Users/user/Documents/Blank/JuceLibraryCode/include_juce_audio_devices.cpp.o
[5/16] Building CXX object CMakeFiles/juce_jni.dir/Users/user/Documents/Blank/JuceLibraryCode/include_juce_audio_formats.cpp.o
[6/16] Building CXX object CMakeFiles/juce_jni.dir/Users/user/Documents/Blank/JuceLibraryCode/include_juce_audio_processors.cpp.o
[7/16] Building CXX object CMakeFiles/juce_jni.dir/Users/user/Documents/Blank/JuceLibraryCode/include_juce_core.cpp.o
[8/16] Building CXX object CMakeFiles/juce_jni.dir/Users/user/Documents/Blank/JuceLibraryCode/include_juce_cryptography.cpp.o
[9/16] Building CXX object CMakeFiles/juce_jni.dir/Users/user/Documents/Blank/JuceLibraryCode/include_juce_data_structures.cpp.o
[10/16] Building CXX object CMakeFiles/juce_jni.dir/Users/user/Documents/Blank/JuceLibraryCode/include_juce_events.cpp.o
[11/16] Building CXX object CMakeFiles/juce_jni.dir/Users/user/Documents/Blank/JuceLibraryCode/include_juce_graphics.cpp.o
[12/16] Building CXX object CMakeFiles/juce_jni.dir/Users/user/Documents/Blank/JuceLibraryCode/include_juce_gui_basics.cpp.o
[13/16] Building CXX object CMakeFiles/juce_jni.dir/Users/user/Documents/Blank/JuceLibraryCode/include_juce_gui_extra.cpp.o
[14/16] Building CXX object CMakeFiles/juce_jni.dir/Users/user/Documents/Blank/JuceLibraryCode/include_juce_opengl.cpp.o
FAILED: /Users/user/Library/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ --target=i686-none-linux-android28 --gcc-toolchain=/Users/user/Library/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64 -DDEBUG=1 -DJUCER_ANDROIDSTUDIO_7F0E4A25=1 -DJUCE_ANDROID=1 -DJUCE_ANDROID_ACTIVITY_CLASSNAME=com_yourcompany_blank_Blank -DJUCE_ANDROID_ACTIVITY_CLASSPATH=\"com/yourcompany/blank/Blank\" -DJUCE_ANDROID_API_VERSION=10 -DJUCE_ANDROID_SHARING_CONTENT_PROVIDER_CLASSNAME=com_yourcompany_blank_SharingContentProvider -DJUCE_ANDROID_SHARING_CONTENT_PROVIDER_CLASSPATH=\"com/yourcompany/blank/SharingContentProvider\" -DJUCE_APP_VERSION=1.0.0 -DJUCE_APP_VERSION_HEX=0x10000 -DJUCE_PUSH_NOTIFICATIONS=1 -D_DEBUG=1 -Djuce_jni_EXPORTS -I../../../../../../../JuceLibraryCode -I/Users/user/Downloads/JUCE/modules -I/Users/molly/Library/Android/sdk/ndk-bundle/sources/android/cpufeatures --sysroot /Users/user/Library/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/sysroot -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -Wa,--noexecstack -Wformat -Werror=format-security -stdlib=libc++ -std=c++11 -fexceptions -frtti -fsigned-char -std=c++14 -O0 -fno-limit-debug-info -O0 -fPIC -MD -MT CMakeFiles/juce_jni.dir/Users/user/Documents/Blank/JuceLibraryCode/include_juce_opengl.cpp.o -MF CMakeFiles/juce_jni.dir/Users/user/Documents/Blank/JuceLibraryCode/include_juce_opengl.cpp.o.d -o CMakeFiles/juce_jni.dir/Users/user/Documents/Blank/JuceLibraryCode/include_juce_opengl.cpp.o -c /Users/user/Documents/Blank/JuceLibraryCode/include_juce_opengl.cpp
In file included from /Users/user/Documents/Blank/JuceLibraryCode/include_juce_opengl.cpp:9:
/Users/user/Downloads/JUCE/modules/juce_opengl/juce_opengl.cpp:118:26: error: no member named 'glDrawBuffer' in the global namespace; did you mean simply 'glDrawBuffer'?
JUCE_GL_BASE_FUNCTIONS (JUCE_DECLARE_GL_FUNCTION)
~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
/Users/user/Downloads/JUCE/modules/juce_opengl/native/juce_OpenGLExtensions.h:69:5: note: expanded from macro 'JUCE_GL_BASE_FUNCTIONS'
USE_FUNCTION (glDrawBuffer, void, (GLsizei p1, const GLenum* p2), (p1, p2))
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/user/Downloads/JUCE/modules/juce_opengl/juce_opengl.cpp:116:72: note: expanded from macro 'JUCE_DECLARE_GL_FUNCTION'
returnType OpenGLExtensionFunctions::name params noexcept { return ::name callparams; }
^~
/Users/user/Downloads/JUCE/modules/juce_opengl/juce_opengl.cpp:118:2: note: 'glDrawBuffer' declared here
JUCE_GL_BASE_FUNCTIONS (JUCE_DECLARE_GL_FUNCTION)
^
/Users/user/Downloads/JUCE/modules/juce_opengl/native/juce_OpenGLExtensions.h:69:19: note: expanded from macro 'JUCE_GL_BASE_FUNCTIONS'
USE_FUNCTION (glDrawBuffer, void, (GLsizei p1, const GLenum* p2), (p1, p2))
^
1 error generated.
ninja: build stopped: subcommand failed.
I have tried reinstalling the Projucer, running different versions of Android Studio and generating different Demo projects but they all fail at the same point. When generating an Xcode file on the same computer (macOS) and same Projucer download the code does compile and run on an emulated iOS.
Am I missing some library or is there an incorrect file path somewhere?
The file that throws the error is from their own library so I am unsure what could be causing the issue, any help would be much appreciated!
The error occurs specifically on the line USE_FUCNTION(glDrawBuffer ...) as I have tried moving this line of code in the library file and the error moves with it (it is at the end of a code block so I wanted to see if it was that code block that was failing but it seems to be specifically that line)
Set the “Minimum SDK Version” in the Android exporter to something like 24, rather than the default of 10.
The current default is a little low and will be bumped up to 28 in the next JUCE release.

Android NDK CMakeLists.txt: error: undefined reference to:

I've looked around but I've only been able to find solutions that use Android.mk and Application.mk. Am I right in thinking that by using CMakeLists.txt I don't need either of those files? This is my first venture into using the Android NDK.
I've based my CMakeLists.txt off of the SuperpoweredExample and I have called my library nativelib. It seems the .cpp file cannot pick up the references in the header file. Am I doing something wrong? It builds fine but it just throws these errors on compilation.
CMakeLists.txt:
cmake_minimum_required(VERSION 3.4.1)
# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds it for you.
# Gradle automatically packages shared libraries with your APK.
add_library( # Sets the name of the library.
nativelib
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
# Associated headers in the same location as their source
# file are automatically included.
G:/Git/NDKTest/app/src/main/jni/nativelib.cpp )
# Searches for a specified prebuilt library and stores the path as a
# variable. Because system libraries are included in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.
find_library( # Sets the name of the path variable.
log-lib
# Specifies the name of the NDK library that
# you want CMake to locate.
log )
# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in the
# build script, prebuilt third-party libraries, or system libraries.
target_link_libraries( # Specifies the target library.
nativelib
# Links the target library to the log library
# included in the NDK.
${log-lib} )
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
// Below here is copy and pasted from the SuperpoweredExample
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
set(
PATH_TO_SUPERPOWERED
"C:/Users/j/Downloads/Superpowered/Superpowered"
)
message(${ANDROID_ABI})
file(GLOB CPP_FILES "*.cpp")
add_library(
SuperpoweredExample
SHARED
${CPP_FILES}
${PATH_TO_SUPERPOWERED}/AndroidIO/SuperpoweredAndroidAudioIO.cpp
)
include_directories(src/main/jni)
include_directories(${PATH_TO_SUPERPOWERED})
target_link_libraries(
SuperpoweredExample
log
android
OpenSLES
${PATH_TO_SUPERPOWERED}/libSuperpoweredAndroid${ANDROID_ABI}.a
nativelib
)
Stacktrace:
Error:FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:externalNativeBuildDebug'.
> Build command failed.
Error while executing 'G:\sdk1\cmake\3.6.3155560\bin\cmake.exe' with arguments {--build G:\Git\NDKTest\app\.externalNativeBuild\cmake\debug\x86 --target nativelib}
[1/2] Building CXX object CMakeFiles/nativelib.dir/nativelib.cpp.o
[2/2] Linking CXX shared library G:\Git\NDKTest\app\build\intermediates\cmake\debug\obj\x86\libnativelib.so
FAILED: cmd.exe /C "cd . && G:\sdk1\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe -target i686-none-linux-android -gcc-toolchain G:/sdk1/ndk-bundle/toolchains/x86-4.9/prebuilt/windows-x86_64 --sysroot=G:/sdk1/ndk-bundle/platforms/android-16/arch-x86 -fPIC -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -Wa,--noexecstack -Wformat -Werror=format-security -fno-exceptions -fno-rtti -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -Wa,--noexecstack -Wformat -Werror=format-security -fno-exceptions -fno-rtti -fsigned-char -Inull -O0 -fno-limit-debug-info -O0 -fno-limit-debug-info -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,libnativelib.so -o G:\Git\NDKTest\app\build\intermediates\cmake\debug\obj\x86\libnativelib.so CMakeFiles/nativelib.dir/nativelib.cpp.o -llog -lm "G:/sdk1/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/libs/x86/libgnustl_static.a" && cd ."
G:\Git\NDKTest\app\src\main\jni/nativelib.cpp:16: error: undefined reference to 'SuperpoweredRoll::SuperpoweredRoll(unsigned int)'
G:\Git\NDKTest\app\src\main\jni/nativelib.cpp:17: error: undefined reference to 'SuperpoweredFilter::SuperpoweredFilter(SuperpoweredFilterType, unsigned int)'
G:\Git\NDKTest\app\src\main\jni/nativelib.cpp:18: error: undefined reference to 'SuperpoweredFlanger::SuperpoweredFlanger(unsigned int)'
G:\Git\NDKTest\app\src\main\jni/nativelib.cpp:19: error: undefined reference to 'SuperpoweredRecorder::SuperpoweredRecorder(char const*, unsigned int, unsigned int)'
G:\Git\NDKTest\app\src\main\jni/nativelib.cpp:21: error: undefined reference to 'SuperpoweredAndroidAudioIO::SuperpoweredAndroidAudioIO(int, int, bool, bool, bool (*)(void*, short*, int, int), void*, int, int, int)'
G:\Git\NDKTest\app\src\main\jni/nativelib.cpp:28: error: undefined reference to 'SuperpoweredRecorder::stop()'
G:\Git\NDKTest\app\src\main\jni/nativelib.cpp:30: error: undefined reference to 'SuperpoweredRecorder::start(char const*)'
G:\Git\NDKTest\app\src\main\jni/nativelib.cpp:37: error: undefined reference to 'SuperpoweredRecorder::process(float*, float*, unsigned int)'
G:\Git\NDKTest\app\src\main\jni/nativelib.cpp:38: error: undefined reference to 'SuperpoweredFloatToShortInt(float*, short*, unsigned int, unsigned int)'
G:\Git\NDKTest\app\src\main\jni/nativelib.cpp:43: error: undefined reference to 'SuperpoweredAndroidAudioIO::~SuperpoweredAndroidAudioIO()'
G:\Git\NDKTest\app\src\main\jni/nativelib.cpp:44: error: undefined reference to 'SuperpoweredRecorder::~SuperpoweredRecorder()'
clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Changed name from native-lib to nativelib, same error.
I have a feeling the error is around the target_link_libraries() of CMakeLists.txt. I am trying to link my NativeLib code with the existing SuperpoweredExample code.
I think linking your "nativelib" happens before linking the Superpowered example, therefore your linker can't find the Superpowered parts used by "nativelib".

Categories

Resources