1
votes

I have a big project with hundreds of c++ files that I am supposed to port to Android. I am new to the project and NDK as well. I got rid of most errors and the ndk build progresses up to here:

Compile++ thumb : mylib <= MyApp.cpp

SharedLibrary : libmylib.so

./obj/local/armeabi/objs/mylib/MyApp.o: In function `MyClass::MyFunction(unsigned long, void*, unsigned long long)':

C:\Development/./jni/AClass.h:249: undefined reference to `MyClass::Function(unsigned long, void*, unsigned long long)'

.... plenty of these error messages here...

collect2: ld returned 1 exit status

/cygdrive/c/Android/android-ndk/android-ndk-r8/build/core/build-binary.mk:369: recipe for target `obj/local/armeabi/libmylib.so' failed

make: * [obj/local/armeabi/libmylib.so] Error 1

it even goes to "SharedLibrary : libmylib.so" now but then I get heaps of these errors "undefined reference" like above. The classes are included and the functions defined.

line 369 in build-binary.mk is:

@ $(call host-mkdir,$(dir $@))

but I don't know what that means. I read something about permission problems with shared libraries and set all files to allow everything but that didnt change anything. could it be that mkdir fails for some reason? Does anyone know what the problem could be?

Any help is greatly appreciated!

Here is my Android.mk file:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := mylib

LOCAL_SRC_FILES := MyApp.cpp

LOCAL_CFLAGS := -D_Android_ -D_Debug_

include $(BUILD_SHARED_LIBRARY)

2

2 Answers

0
votes

Likely one of three things are happening:

  • You are not actually compiling the code for these functions, perhaps because it is surrounded by #ifdef or because the files in question are not being built. You can check for the presence of .o files corresponding to their source. You can also put #error in the body of the function and verify that the build fails there (I know it sounds silly, but it catches silly mistakes that waste your time)

  • The functions are in an object file or library that is not being linked in. In this case you need to add the missing piece to the linkage.

  • The functions are in a different dynamic library which will be preloaded before the library you are building is loaded, or at least will get loaded before the functions which depend on them are loaded. There is a special flag you can use to allow undefined symbols in shared libraries - I forget what it is, but you can look it up.

0
votes

Is the class MyClass defined in the MyApp.cpp?

If not, you need to add the MyClass source file in the LOCAL_SRC_FILES too, for example,

LOCAL_SRC_FILES := MyApp.cpp AClass.cpp.