I’m writing an Android App fully in C++. Using OpenGL E.S. 2, Android-NDK r7 (platform-9), OpenJDK, and Ubuntu 12.04.
The issue that I’m running into is that my main library which is supposed to make calls to the engine I’m developing is spitting out “undefined reference to android_main” errors. Why it is doing this I have no idea, but I’m almost positive it has some thing to do with my Android.mk. For whatever reason, I can’t quite figure it out.
While the engine library builds perfectly fine, the main Android.mk which references the files used which make up the actual game isn’t building in the way I’d like it to.
The Goal
-I’d like this to link up with -loptim so it may reference and call functions from the engine as a separate library. Because of this, I should be able to port this engine to various other projects and simply link it. This appears to have been done, though if someone else has a better way of accomplishing this I’m all ears.
-I’d also like to figure out why my android_main is not being referenced, and what can be done to fix it.
Main.cpp
#include "engine/stdafx.hpp"
#include "engine/AppData.hpp"
#include "engine/Engine.hpp"
#include "glm/glm.hpp"
using namespace optim;
void android_main( android_app* application )
{
AppData appData;
appData.mApplication = application;
appData.mGraphicsService = new GraphicsService( application );
Engine app( &appData );
}
Android.mk
MY_LOCAL_PATH := $(call my-dir)
LOCAL_PATH := $(MY_LOCAL_PATH)
include $(CLEAR_VARS)
include $(LOCAL_PATH)/engine/Android.mk
include $(CLEAR_VARS)
LOCAL_PATH := $(MY_LOCAL_PATH)
LOCAL_CFLAGS := -I$(LOCAL_PATH)/glm -I$(ANDROID_NDK)/sources/cxx-stl/stlport/stlport -I$(LOCAL_PATH)/ -I$(LOCAL_PATH)/engine
LOCAL_MODULE := pongdroid
LOCAL_SRC_FILES := Main.cpp PongDroid.cpp
LOCAL_LDLIBS := -landroid -llog -lEGL -lGLESv2 -L$(PONGDROID_DEV)/obj/local/armeabi/ -loptim
LOCAL_STATIC_LIBRARIES := android_native_app_glue
include $(BUILD_SHARED_LIBRARY)
$(call import-module,android/native_app_glue)
Note that -loptim is the shared library of the engine I’m linking the main module to. The problem is that, while it appears to link perfectly fine, the library for this makefile in particular won’t produce a shared_library. Everything else seems to compile just fine, however.
NDK-BUILD
**** Build of configuration Default for project pongdroid ****
ndk-build all
Gdbserver : [arm-linux-androideabi-4.4.3] libs/armeabi/gdbserver
Gdbsetup : libs/armeabi/gdb.setup
Compile++ thumb : optim <= Engine.cpp
Compile++ thumb : optim <= Config.cpp
Compile++ thumb : optim <= GraphicsService.cpp
Compile thumb : android_native_app_glue <= android_native_app_glue.c
StaticLibrary : libandroid_native_app_glue.a
StaticLibrary : libstdc++.a
SharedLibrary : liboptim.so
./obj/local/armeabi/libandroid_native_app_glue.a(android_native_app_glue.o): In function `android_app_entry':
/home/amsterdam/Android/android-ndk/sources/android/native_app_glue/android_native_app_glue.c:234: undefined reference to `android_main'
collect2: ld returned 1 exit status
make: *** [obj/local/armeabi/liboptim.so] Error 1
**** Build Finished ****
Update
So, I’ve narrowed down the problem a bit. The issue lies in the fact that the root Android.mk file for some reason seems to be ignoring its own library. What’s even stranger is that when I comment out include $(LOCAL_PATH)/engine/Android.mk, the error output gets worse.
So, I’m posting my engine/Android.mk file for clarity to see if anyone can make sense of this mess…
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_CFLAGS := -I$(LOCAL_PATH)/
LOCAL_MODULE := optim
LOCAL_SRC_FILES := Engine.cpp Config.cpp GraphicsService.cpp
LOCAL_LDLIBS := -landroid -llog -lEGL -lGLESv2
LOCAL_STATIC_LIBRARIES := android_native_app_glue
include $(BUILD_SHARED_LIBRARY)
$(call import-module,android/native_app_glue)
Update 2
A call to ndk-build pongdroid from the shell.
ndk-build pongdroid
Compile++ thumb : pongdroid <= Main.cpp
Compile++ thumb : pongdroid <= PongDroid.cpp
SharedLibrary : liboptim.so
/home/amsterdam/Programming/Android/pongdroid/obj/local/armeabi/libandroid_native_app_glue.a(android_native_app_glue.o): In function `android_app_entry':
/home/amsterdam/Android/android-ndk/sources/android/native_app_glue/android_native_app_glue.c:234: undefined reference to `android_main'
collect2: ld returned 1 exit status
make: *** [/home/amsterdam/Programming/Android/pongdroid/obj/local/armeabi/liboptim.so] Error 1
Are you including “android_native_app_glue.h” header in Main.cpp or one of its included headers?