Undefined reference error while compiling project (ANDROID NDK) - android

I am working with the Android NDK and I am facing this problem. I am getting following error;
22:30:09 **** Incremental Build of configuration Default for project MrBlueFramework ****
"D:\\Android_Development\\Android_NDK\\ndk-build.cmd" all
Android NDK: WARNING: APP_PLATFORM android-19 is larger than android:minSdkVersion 8 in ./AndroidManifest.xml
[armeabi] Compile++ thumb: MrBlueFramework <= MrBlueFramework.cpp
[armeabi] SharedLibrary : libMrBlueFramework.so
D:/Android_Development/Android_NDK/toolchains/arm-linux-androideabi-4.6/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe: ./obj/local/armeabi/objs/MrBlueFramework/MrBlueFramework.o: in function android_main:jni/MrBlueFramework.cpp:11: error: undefined reference to 'Framework::Application::Application(android_app*)'
D:/Android_Development/Android_NDK/toolchains/arm-linux-androideabi-4.6/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe: ./obj/local/armeabi/objs/MrBlueFramework/MrBlueFramework.o: in function android_main:jni/MrBlueFramework.cpp:11: error: undefined reference to 'Framework::Application::~Application()'
collect2: ld returned 1 exit status
make.exe: *** [obj/local/armeabi/libMrBlueFramework.so] Error 1
Here is what my hierarchy looks like;
Here is my android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := MrBlueFramework
LOCAL_SRC_FILES := MrBlueFramework.cpp \
Framework/Application/Application.cpp\
LOCAL_C_INCLUDES := $(LOCAL_PATH)
LOCAL_LDLIBS := -llog -landroid -lEGL -lGLESv2
LOCAL_STATIC_LIBRARIES := android_native_app_glue
include $(BUILD_SHARED_LIBRARY)
$(call import-module,android/native_app_glue)
Here is content of Application.h
#include <android_native_app_glue.h>
namespace Framework
{
class Application
{
private:
public:
Application(android_app *state);
virtual ~Application();
bool Initialize();
void Run();
};
}
And here is main class (mrblueframework.cpp)
#include <jni.h>
#include <android_native_app_glue.h>
#include "Framework\Application\Application.h"
using namespace Framework;
void android_main(android_app *state)
{
app_dummy();
Application app(state);
}
I don't understand what I am doing wrong, I am including my Application.h file on top but stills it didn't find it. Please help me regarding this.

LOCAL_SRC_FILES := MrBlueFramework.cpp
Application.cpp is not there.

Related

Building Android Command Line Executable with Prebuilt Shared Library

I'm trying to cross-compile an Android executable (command line) that calls a method inside a proprietary android prebuilt shared object (.so aarch64)
I'm using an Ubuntu 20.04 x86_64 and I want cross-compile an executable for Android 10 aarch64.
The method is defined from the relative JNI in the following way:
public static native int getScore();
I build a simple C program:
#include <stdio.h>
extern int getScore();
int main(){
getScore();
return(1);
}
Then I develop an Android.mk file like the following:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := mygame
LOCAL_SRC_FILES := libmygame.so
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := getscore
LOCAL_SRC_FILES := getscore.c
LOCAL_SHARED_LIBRARIES := mygame
include $(BUILD_EXECUTABLE)
Then I try to compile with:
ndk-build NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=./Android.mk
But I get the follwoing error:
./obj/local/arm64-v8a/objs/getscore/getscore.o: In function `main':
/tmp/cross-compile-test/./getscore.c:24: undefined reference to `getScore'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [/home/mark01/Android/Sdk/ndk/21.3.6528147/build/core/build-binary.mk:738: obj/local/arm64-v8a/getscore] Error 1

C++ library with Tensorflow on Android

I'm trying to build a native C++ library for the Android app. This lib uses Tensorflow C++ API (version 1.9.0 and 1.10.0) and OpenCV(3.3.0) inside. For generating wrapper I'm using Swig. I'm using Android NDK to build *.so files (I've tried with different versions of the NDK versions 10, 14, 15, 17).
I've built *.a (libtensorflow-core.a, nsync.a, libprotobuf.a)files from sources.
defaultConfig {
minSdkVersion 21
targetSdkVersion 28
}
I have the next files:
Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libnsync
LOCAL_SRC_FILES := $(PATH_TO_TENSORFLOW)/tensorflow/contrib/makefile/downloads/nsync/builds/armeabi-v7a.android.c++11/nsync.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := libprotobuf
LOCAL_SRC_FILES := $(PATH_TO_TENSORFLOW)/tensorflow/contrib/makefile/gen/protobuf_android/armeabi-v7a/lib/libprotobuf.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := libtensorflow
LOCAL_SRC_FILES := $(PATH_TO_TENSORFLOW)/tensorflow/contrib/makefile/gen/lib/android_armeabi-v7a/libtensorflow-core.a
LOCAL_EXPORT_C_INCLUDES := \
$(PATH_TO_TENSORFLOW) \
$(PATH_TO_TENSORFLOW)/tensorflow/contrib/makefile/gen/host_obj \
$(PATH_TO_TENSORFLOW)/tensorflow/contrib/makefile/downloads/eigen \
$(PATH_TO_TENSORFLOW)/tensorflow/contrib/makefile/gen/protobuf_android/armeabi-v7a/include \
$(PATH_TO_TENSORFLOW)/tensorflow/core/public \
$(PATH_TO_TENSORFLOW)/tensorflow/contrib/makefile/downloads/nsync/public
LOCAL_STATIC_LIBRARIES += libprotobuf libnsync
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_ARM_NEON := true
OPENCV_CAMERA_MODULES := off
include $(OPENCV_PACKAGE_DIR)/native/jni/OpenCV.mk
LOCAL_MODULE := libOcr
LOCAL_SRC_FILES := ocr/Ocr_wrap.cxx
LOCAL_LDLIBS += -landroid -llog -ldl
LOCAL_CPPFLAGS += -std=c++11
LOCAL_STATIC_LIBRARIES += libprotobuf libtensorflow
include $(BUILD_SHARED_LIBRARY)
Application.mk
APP_STL := gnustl_shared
APP_CPPFLAGS := -frtti -fexceptions
APP_ABI := armeabi-v7a
APP_PLATFORM := android-21 #updated from 19 to 21
APP_OPTIM := release
LOCAL_ARM_NEON := true
During the build, I've faced a lot of errors, and the last one is:
[armeabi-v7a] SharedLibrary : libOcr.so
[armeabi-v7a] Install : liblept.so => libs/armeabi-v7a/liblept.so
[armeabi-v7a] Install : libtess.so => libs/armeabi-v7a/libtess.so
[armeabi-v7a] Install : libgnustl_shared.so => libs/armeabi-v7a/libgnustl_shared.so
/Users/tensorflow/tensorflow/contrib/makefile/gen/lib/android_armeabi-v7a/libtensorflow-core.a(str_util.o):str_util.cc:function tensorflow::str_util::CUnescape(tensorflow::StringPiece, std::string*, std::string*): error: undefined reference to 'std::__throw_out_of_range_fmt(char const*, ...)'
/Users/tensorflow/tensorflow/contrib/makefile/gen/lib/android_armeabi-v7a/libtensorflow-core.a(log_memory.o):log_memory.cc:function tensorflow::LogMemory::RecordStep(long long, std::string const&): error: undefined reference to 'std::__throw_out_of_range_fmt(char const*, ...)'
/Users/tensorflow/tensorflow/contrib/makefile/gen/lib/android_armeabi-v7a/libtensorflow-core.a(log_memory.o):log_memory.cc:function tensorflow::LogMemory::RecordTensorAllocation(std::string const&, long long, tensorflow::Tensor const&): error: undefined reference to 'std::__throw_out_of_range_fmt(char const*, ...)'
/Users/tensorflow/tensorflow/contrib/makefile/gen/lib/android_armeabi-v7a/libtensorflow-core.a(log_memory.o):log_memory.cc:function tensorflow::LogMemory::RecordTensorDeallocation(long long, std::string const&): error: undefined reference to 'std::__throw_out_of_range_fmt(char const*, ...)'
collect2: error: ld returned 1 exit status
make: *** [/Users/app/app/src/main/obj/local/armeabi-v7a/libOcr.so] Error 1
make: Leaving directory `/Users/app/app/src/main/jni'
:sdk:buildNative FAILED
FAILURE: Build failed with an exception.
For building *.so files I use next task in build.gradle file:
commandLine "$ndkDir/ndk-build",
'-C', file('src/main/jni').absolutePath,
'-j', Runtime.runtime.availableProcessors(),
'all',
'NDK_LOG=1'
Dear community, please help me to figure out these issues. Thank you.
Updated: APP_PLATFORM changed to android-21, better results but still have errors
I had this problem before, it's the poop library

undefined reference to ndk boost android

I have a problem when creating an executable with ndk using the BOOST libraries in c ++ using already mentioned ndk, this is the problem
C:\Users\GENERAL\Downloads\Compressed\tcpproxy\proxy\jni>ndk-build
[armeabi] Compile++ thumb: proxy <= tcpproxy_server.cpp
[armeabi] Executable : proxy
C:/Users/GENERAL/Downloads/Compressed/tcpproxy/proxy//jni/boost_1_56_0/boost/sys
tem/error_code.hpp:322: error: undefined reference to 'boost::system::system_cat
egory()'
C:/Users/GENERAL/Downloads/Compressed/tcpproxy/proxy//jni/boost_1_56_0/boost/thr
ead/exceptions.hpp:51: error: undefined reference to 'boost::system::system_cate
gory()'
C:/Users/GENERAL/Downloads/Compressed/tcpproxy/proxy//jni/boost_1_56_0/boost/asi
o/error.hpp:225: error: undefined reference to 'boost::system::system_category()
'
C:/Users/GENERAL/Downloads/Compressed/tcpproxy/proxy//jni/boost_1_56_0/boost/asi
o/error.hpp:225: error: undefined reference to 'boost::system::system_category()
'
C:/Users/GENERAL/Downloads/Compressed/tcpproxy/proxy//jni/boost_1_56_0/boost/sys
tem/error_code.hpp:221: error: undefined reference to 'boost::system::generic_ca
tegory()'
C:/Users/GENERAL/Downloads/Compressed/tcpproxy/proxy//jni/boost_1_56_0/boost/sys
tem/error_code.hpp:222: error: undefined reference to 'boost::system::generic_ca
tegory()'
collect2.exe: error: ld returned 1 exit status
make.exe: *** [C:/Users/GENERAL/Downloads/Compressed/tcpproxy/proxy//obj/local/a
rmeabi/proxy] Error 1
Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_C_INCLUDES += $(LOCAL_PATH)/boost_1_56_0 #patch of include BOOST
LOCAL_MODULE := proxy
LOCAL_SRC_FILES := tcpproxy_server.cpp
include $(BUILD_EXECUTABLE)
Application.mk
APP_CFLAGS += -fexceptions
APP_STL := gnustl_static
NDK_TOOLCHAIN_VERSION := 4.8
APP_CPPFLAGS := -std=c++11
that is the error that I get when compiling. already investigate but can not find the solution so please thank your answer to be able to repair it and because generating that error thanks
You may need to add the boost_system library. You can add -lboost_system to your linker flags to find related library symbols in Android.mk (Assuming that boost is built as static):
LOCAL_STATIC_LIBRARIES = -lboost_system ...
include $(BUILD_STATIC_LIBRARY)

(Android)How to build a native c helloworld with DynamicLinkLibrary?

I want to make a native c program with a dynamic link library, so I put these files in Android/development/hello/: hello.c, myprint.h,myprint.c, the main() is in hello.c, and the Android.mk is:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := myprint
LOCAL_SRC_FILES := myprint.c
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := helloworld
LOCAL_SRC_FILES := hello.c
LOCAL_SHARED_LIBRARIES := myprint
include $(BUILD_EXECUTABLE)
Then I make helloworld, and the output info is that:
target thumb C: helloworld <= development/hello/hello.c
target thumb C: myprint <= development/hello/myprint.c
target SharedLib: myprint (out/target/product/generic/obj/SHARED_LIBRARIES/myprint_intermediates/LINKED/myprint.so)
target Symbolic: myprint (out/target/product/generic/symbols/system/lib/myprint.so)
target Strip: myprint (out/target/product/generic/obj/lib/myprint.so)
target Executable: helloworld (out/target/product/generic/obj/EXECUTABLES/helloworld_intermediates/LINKED/helloworld)
/home/neil/dev/google_422/prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.7/bin/../lib/gcc/arm-linux-androideabi/4.7/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lmyprint.so
development/hello/hello.c:5: error: undefined reference to 'myprint'
collect2: error: ld returned 1 exit status
Please help me...
And my native code is:
// hello.c
#include "myprint.h"
int main()
{
myprint();
return 0;
}
// myprint.h
void myprint();
// myprint.c
#include <stdio.h>
void myprint()
{
printf("myprint...\n");
}
This is happening because you might not be compiling both files so it is unable to locate/link the declaration of that function.
try this
gcc headerfile.c mainfile.c

Using minizip with android ndk

I need to use minizip with zlib in android ndk.
My jni/MyApp/Android.mk file:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := MyApp
LOCAL_SRC_FILES := MyApp.cpp
LOCAL_LDLIBS := -lz
include $(BUILD_SHARED_LIBRARY)
My jni/Android.mk
LOCAL_PATH := $(call my-dir)
include $(call all-subdir-makefiles)
My jni/MyApp/MyApp.cpp
#include <zlib.h>
#include "minizip/unzip.h" #it's in jni/MyApp/minizip/unzip.h
void unzip(char* file, char* folder) {
unzFile zip = unzOpen(file);
}
My jni/Application.mk
APP_MODULES := MyApp
APP_STL := gnustl_static
But, when I compile it:
Gdbserver : [arm-linux-androideabi-4.6] libs/armeabi/gdbserver
Gdbsetup : libs/armeabi/gdb.setup
SharedLibrary : libMyApp.so
C:/android-ndk-r8d/toolchains/arm-linux-androideabi-4.6/prebuilt/windows/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe:
Z:/workspace/MyApp/obj/local/armeabi/objs-debug/MyApp/MyApp.o: in function unzip(char*, char*):Z:/workspace/MyApp/jni/MyApp/MyApp.cpp:5: error: undefined reference to 'unzOpen' collect2: ld returned 1 exit status make: *** [Z:/workspace/MyApp/obj/local/armeabi/libMyApp.so] Error 1
If I remove the line "unzFile zip = unzOpen(file);" it works
Can you help me? :D
Thanks!
Oh...
I forgot to add the c files in LOCAL_SRC_FILES :D

Categories

Resources