brCore (Core elements, Manager (Singletons), Logger (Singleton) ect.) STATIC
brGrapics (Generic graphics) uses brCore STATIC
brOpenGLES (GLES renderer) uses brCore, brGraphics DYNAMIC
04-08 06:47:24.601: I/NativeActivitySimpleExample(1059): brSingleton getInstance called
04-08 06:47:24.611: I/NativeActivitySimpleExample(1059): Singleton constructor invoked : brFileHandler
04-08 06:47:24.611: I/NativeActivitySimpleExample(1059): brFileHandler set internal data path: /data/data/com.binrev/files
04-08 06:47:24.611: I/NativeActivitySimpleExample(1059): brSingleton getInstance called
04-08 06:47:24.031: I/NativeActivitySimpleExample(1059): Try to initialize Render API
04-08 06:47:24.031: I/NativeActivitySimpleExample(1059): brSingleton getInstance called
04-08 06:47:24.051: I/NativeActivitySimpleExample(1059): Singleton constructor invoked : brRessourceManager
04-08 06:47:24.051: I/NativeActivitySimpleExample(1059): brSingleton getInstance called
04-08 06:47:24.251: I/NativeActivitySimpleExample(1059): Try to init Logger: brCore
04-08 06:47:24.251: I/NativeActivitySimpleExample(1059): Search for existing logger
04-08 06:47:24.282: I/NativeActivitySimpleExample(1059): brSingleton getInstance called
04-08 06:47:24.282: I/NativeActivitySimpleExample(1059): Singleton constructor invoked : brRessourceManager
04-08 06:47:24.282: I/NativeActivitySimpleExample(1059): brSingleton getInstance called
04-08 06:47:24.282: I/NativeActivitySimpleExample(1059): Singleton constructor invoked : brConfigManager
04-08 06:47:24.601: I/NativeActivitySimpleExample(1059): brSingleton getInstance called
04-08 06:47:24.611: I/NativeActivitySimpleExample(1059): Singleton constructor invoked : brFileHandler
04-08 06:47:24.611: I/NativeActivitySimpleExample(1059): brSingleton getInstance called
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk...@googlegroups.com.
To post to this group, send email to andro...@googlegroups.com.
Visit this group at http://groups.google.com/group/android-ndk?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
#define BINREV_SINGLETON_H__
#include <mutex>
#include <memory>
#include <thread>
#include <android/log.h>
#include <android_native_app_glue.h>
#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "NativeActivitySimpleExample", __VA_ARGS__))
namespace binrev{
namespace brCore{
template <typename T>
class brSingleton
{
public:
static T& getInstance()
{
LOGI("brSingleton getInstance called");
std::call_once(m_once, safe_create);
return *m_instance;
}
protected:
brSingleton(const std::string& name)
: m_name(name)
{
LOGI("Singleton constructor invoked : %s", m_name.c_str());
}
static void safe_create() {
brSingleton::m_instance.reset(new T());
}
brSingleton(const brSingleton& rs) = delete;
brSingleton& operator = (const brSingleton& rs) = delete;
virtual ~brSingleton(){}
protected:
static std::unique_ptr<T> m_instance;
static std::once_flag m_once;
std::string m_name;
};
template<typename T>
std::once_flag brSingleton<T>::m_once;
}// ns-brCore
}// ns-binrev
namespace binrev{
namespace brCore{
class CORE_LIBRARY_API brApplication : public brCore::brSingleton<brApplication>
{
friend class brCore::brSingleton<brApplication>;
public:
enum eState
{
STATE_UNINITIALIZED=0,
STATE_RUNNING,
STATE_PAUSED
};
virtual ~brApplication(void);
static brApplication& getInstance();
#ifdef ANDROID
const std::string& getInternalFilePath(void) const;
const std::string& getInternalLibraryPath(void) const;
ANativeWindow* getNativeWindow(void) const;
void setNativeWindow(ANativeWindow* window);
ANativeActivity* getNativeActivity(void) const;
void init(struct android_app* state);
#endif
protected:
brApplication(void);
#ifdef ANDROID
std::string m_filePath;
std::string m_libPath;
ANativeActivity* m_nativeActivity;
ANativeWindow* m_nativeWindow;
#endif
};
} // ns brCore
} // ns binrev
#endif//BINREV_APPLICATION_H__
#define CORE_LIBRARY_EXPORT
#include <brCore/brApplication.h>
#include <brCore/brAssert.h>
#include <brCore/brLog.h>
#include <brCore/brStringUtils.h>
#include <brCore/exceptions/brIllegalArgumentException.h>
#include <brCore/exceptions/brIllegalStateException.h>
#include <android/log.h>
#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, "NativeActivitySimpleExample", __VA_ARGS__))
namespace binrev{
namespace brCore {
// Zero initialization of the static singleton instance
template <> std::unique_ptr<brApplication> brSingleton<brApplication>::m_instance = nullptr;
/** @brief Default Constructor */
brApplication::brApplication()
: brSingleton<brApplication>("brApplication")
{}
/** @brief Destructor */
brApplication::~brApplication()
{}
/*! @copydoc brCore::brSingleton::getInstance()
@note
Override standard Singleton creation. We have to do this to avoid
linker errors on Windows platforms when trying to use the brSingleton
base class from outside of a dll.
*/
brApplication& brApplication::getInstance()
{
// create instance calling parent method
brCore::brSingleton<brApplication>::getInstance();
return *m_instance;
}
APP_MODULES := NativeActivitySimpleExample
APP_CPPFLAGS := -std=gnu++0x
APP_CPPFLAGS += -frtti
APP_CPPFLAGS += -fexceptions
APP_CPPFLAGS += -DDEBUG
APP_CPPFLAGS += -rdynamic
APP_ABI := armeabi-v7a
APP_PLATFORM:=android-14
APP_STL := gnustl_static
APP_GNUSTL_CPP_FEATURES := rtti exceptions
NDK_TOOLCHAIN_VERSION=4.7
APP_CPPFLAGS += -rdynamic
APP_CPPFLAGS += -fpic
d:\development\android\workspace\NdkTest-native>d:\development\android\ndk-r8e\n
dk-build V=1 -B
d:/development/android/ndk-r8e/build/core/add-application.mk:128: Android NDK: W
ARNING: APP_PLATFORM android-14 is larger than android:minSdkVersion 10 in ./And
roidManifest.xml
del /f/q .\libs\armeabi-v7a\libbrOpenGLES2.so .\libs\armeabi-v7a\libgnustl_share
d.so .\libs\armeabi-v7a\libNativeActivitySimpleExample.so >NUL 2>NUL
"Compile++ thumb : NativeActivitySimpleExample <= main.cpp
d:/development/android/ndk-r8e/toolchains/arm-linux-androideabi-4.7/prebuilt/win
dows/bin/arm-linux-androideabi-g++ -MMD -MP -MF ./obj/local/armeabi-v7a/objs/Nat
iveActivitySimpleExample/main.o.d -fpic -ffunction-sections -funwind-tables -fst
ack-protector -no-canonical-prefixes -march=armv7-a -mfloat-abi=softfp -mfpu=vfp
v3-d16 -fno-exceptions -fno-rtti -mthumb -Os -g -DNDEBUG -fomit-frame-pointer -f
no-strict-aliasing -finline-limit=64 -Ijni/brGraphics/include -Ijni/brMath/inclu
de -Ijni/brCore/include -Id:/development/android/ndk-r8e/sources/android/native_
app_glue -Id:/development/android/ndk-r8e/sources/cxx-stl/gnu-libstdc++/4.7/incl
ude -Id:/development/android/ndk-r8e/sources/cxx-stl/gnu-libstdc++/4.7/libs/arme
abi-v7a/include -Ijni -DANDROID -Wa,--noexecstack -std=gnu++0x -frtti -fexce
ptions -DDEBUG -rdynamic -Id:/development/android/ndk-r8e/platforms/android-14/
arch-arm/usr/include -c jni/main.cpp -o ./obj/local/armeabi-v7a/objs/NativeActi
vitySimpleExample/main.o
Prebuilt : libgnustl_shared.so <= <NDK>/sources/cxx-stl/gnu-libstdc++/4.7/
libs/armeabi-v7a/
copy /b/y "d:\development\android\ndk-r8e\sources\cxx-stl\gnu-libstdc++\4.7\libs
\armeabi-v7a\libgnustl_shared.so" "obj\local\armeabi-v7a\libgnustl_shared.so" >
NUL
"Compile thumb : android_native_app_glue <= android_native_app_glue.c
d:/development/android/ndk-r8e/toolchains/arm-linux-androideabi-4.7/prebuilt/win
dows/bin/arm-linux-androideabi-gcc -MMD -MP -MF ./obj/local/armeabi-v7a/objs/and
roid_native_app_glue/android_native_app_glue.o.d -fpic -ffunction-sections -funw
ind-tables -fstack-protector -no-canonical-prefixes -march=armv7-a -mfloat-abi=s
oftfp -mfpu=vfpv3-d16 -mthumb -Os -g -DNDEBUG -fomit-frame-pointer -fno-strict-a
liasing -finline-limit=64 -Id:/development/android/ndk-r8e/sources/android/nativ
e_app_glue -DANDROID -Wa,--noexecstack -Id:/development/android/ndk-r8e/platfo
rms/android-14/arch-arm/usr/include -c d:/development/android/ndk-r8e/sources/a
ndroid/native_app_glue/android_native_app_glue.c -o ./obj/local/armeabi-v7a/objs
/android_native_app_glue/android_native_app_glue.o
StaticLibrary : libandroid_native_app_glue.a
del /f/q obj\local\armeabi-v7a\libandroid_native_app_glue.a >NUL 2>NUL
d:/development/android/ndk-r8e/toolchains/arm-linux-androideabi-4.7/prebuilt/win
dows/bin/arm-linux-androideabi-ar crs ./obj/local/armeabi-v7a/libandroid_native_
app_glue.a ./obj/local/armeabi-v7a/objs/android_native_app_glue/android_native_a
pp_glue.o
SharedLibrary : libNativeActivitySimpleExample.so
d:/development/android/ndk-r8e/toolchains/arm-linux-androideabi-4.7/prebuilt/win
dows/bin/arm-linux-androideabi-g++ -Wl,-soname,libNativeActivitySimpleExample.so
-shared --sysroot=d:/development/android/ndk-r8e/platforms/android-14/arch-arm
./obj/local/armeabi-v7a/objs/NativeActivitySimpleExample/main.o jni/brGraphics/l
ibbrGraphics.a jni/brMath/libbrMath.a jni/brCore/libbrCore.a ./obj/local/armeabi
-v7a/libandroid_native_app_glue.a -lgcc ./obj/local/armeabi-v7a/libgnustl_shared
.so -no-canonical-prefixes -march=armv7-a -Wl,--fix-cortex-a8 -Wl,--no-undefine
d -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -Ld:/development/android/ndk-r8e/p
latforms/android-14/arch-arm/usr/lib -llog -landroid -lEGL -lGLESv2 jni/jsoncpp/
libjsoncpp.a -lgnustl_shared -llog d:/development/android/ndk-r8e/sources/cxx-st
l/gnu-libstdc++/4.7/libs/armeabi-v7a/libsupc++.a -lc -lm -o ./obj/local/armeabi-
v7a/libNativeActivitySimpleExample.so
d:/development/android/ndk-r8e/toolchains/arm-linux-androideabi-4.7/prebuilt/win
dows/bin/../lib/gcc/arm-linux-androideabi/4.7/../../../../arm-linux-androideabi/
bin/ld.exe: error: cannot find -lgnustl_shared
collect2.exe: error: ld returned 1 exit status
make: *** [obj/local/armeabi-v7a/libNativeActivitySimpleExample.so] Error 1
d:\development\android\workspace\NdkTest-native>d:\development\android\ndk-r8e\n
dk-build V=1 -B
d:/development/android/ndk-r8e/build/core/add-application.mk:128: Android NDK: W
ARNING: APP_PLATFORM android-14 is larger than android:minSdkVersion 10 in ./And
roidManifest.xml
"Compile++ thumb : NativeActivitySimpleExample <= main.cpp
d:/development/android/ndk-r8e/toolchains/arm-linux-androideabi-4.7/prebuilt/win
dows/bin/arm-linux-androideabi-g++ -MMD -MP -MF ./obj/local/armeabi-v7a/objs/Nat
iveActivitySimpleExample/main.o.d -fpic -ffunction-sections -funwind-tables -fst
ack-protector -no-canonical-prefixes -march=armv7-a -mfloat-abi=softfp -mfpu=vfp
v3-d16 -fno-exceptions -fno-rtti -mthumb -Os -g -DNDEBUG -fomit-frame-pointer -f
no-strict-aliasing -finline-limit=64 -Ijni/brGraphics/include -Ijni/brMath/inclu
de -Ijni/brCore/include -Id:/development/android/ndk-r8e/sources/android/native_
app_glue -Id:/development/android/ndk-r8e/sources/cxx-stl/gnu-libstdc++/4.7/incl
ude -Id:/development/android/ndk-r8e/sources/cxx-stl/gnu-libstdc++/4.7/libs/arme
abi-v7a/include -Ijni -DANDROID -Wa,--noexecstack -std=gnu++0x -frtti -fexce
ptions -DDEBUG -rdynamic -Id:/development/android/ndk-r8e/platforms/android-14/
arch-arm/usr/include -c jni/main.cpp -o ./obj/local/armeabi-v7a/objs/NativeActi
vitySimpleExample/main.o
"Compile thumb : android_native_app_glue <= android_native_app_glue.c
d:/development/android/ndk-r8e/toolchains/arm-linux-androideabi-4.7/prebuilt/win
dows/bin/arm-linux-androideabi-gcc -MMD -MP -MF ./obj/local/armeabi-v7a/objs/and
roid_native_app_glue/android_native_app_glue.o.d -fpic -ffunction-sections -funw
ind-tables -fstack-protector -no-canonical-prefixes -march=armv7-a -mfloat-abi=s
oftfp -mfpu=vfpv3-d16 -mthumb -Os -g -DNDEBUG -fomit-frame-pointer -fno-strict-a
liasing -finline-limit=64 -Id:/development/android/ndk-r8e/sources/android/nativ
e_app_glue -DANDROID -Wa,--noexecstack -Id:/development/android/ndk-r8e/platfo
rms/android-14/arch-arm/usr/include -c d:/development/android/ndk-r8e/sources/a
ndroid/native_app_glue/android_native_app_glue.c -o ./obj/local/armeabi-v7a/objs
/android_native_app_glue/android_native_app_glue.o
StaticLibrary : libandroid_native_app_glue.a
del /f/q obj\local\armeabi-v7a\libandroid_native_app_glue.a >NUL 2>NUL
d:/development/android/ndk-r8e/toolchains/arm-linux-androideabi-4.7/prebuilt/win
dows/bin/arm-linux-androideabi-ar crs ./obj/local/armeabi-v7a/libandroid_native_
app_glue.a ./obj/local/armeabi-v7a/objs/android_native_app_glue/android_native_a
pp_glue.o
SharedLibrary : libNativeActivitySimpleExample.so
d:/development/android/ndk-r8e/toolchains/arm-linux-androideabi-4.7/prebuilt/win
dows/bin/arm-linux-androideabi-g++ -Wl,-soname,libNativeActivitySimpleExample.so
-shared --sysroot=d:/development/android/ndk-r8e/platforms/android-14/arch-arm
./obj/local/armeabi-v7a/objs/NativeActivitySimpleExample/main.o jni/brGraphics/l
ibbrGraphics.a jni/brMath/libbrMath.a jni/brCore/libbrCore.a ./obj/local/armeabi
-v7a/libandroid_native_app_glue.a d:/development/android/ndk-r8e/sources/cxx-stl
/gnu-libstdc++/4.7/libs/armeabi-v7a/libgnustl_static.a -lgcc -no-canonical-prefi
xes -march=armv7-a -Wl,--fix-cortex-a8 -Wl,--no-undefined -Wl,-z,noexecstack -W
l,-z,relro -Wl,-z,now -Ld:/development/android/ndk-r8e/platforms/android-14/arc
h-arm/usr/lib -llog -landroid -lEGL -lGLESv2 jni/jsoncpp/libjsoncpp.a -llog -lc
-lm -o ./obj/local/armeabi-v7a/libNativeActivitySimpleExample.so
Install : libNativeActivitySimpleExample.so => libs/armeabi-v7a/libNative
ActivitySimpleExample.so
copy /b/y ".\obj\local\armeabi-v7a\libNativeActivitySimpleExample.so" ".\libs\ar
meabi-v7a\libNativeActivitySimpleExample.so" > NUL
d:/development/android/ndk-r8e/toolchains/arm-linux-androideabi-4.7/prebuilt/win
dows/bin/arm-linux-androideabi-strip --strip-unneeded ./libs/armeabi-v7a/libNat
iveActivitySimpleExample.so
LOCAL_PATH := $(call my-dir)
LOCAL_CFLAGS += -DDEBUG
LOCAL_CFLAGS += -DANDROID
include $(CLEAR_VARS)
LOCAL_MODULE := brCore
LOCAL_SRC_FILES := brCore/libbrCore.a
LOCAL_EXPORT_C_INCLUDES += $(LOCAL_PATH)/brCore/include
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := brMath
LOCAL_SRC_FILES := brMath/libbrMath.a
LOCAL_EXPORT_C_INCLUDES += $(LOCAL_PATH)/brMath/include
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := brGraphics
LOCAL_SRC_FILES := brGraphics/libbrGraphics.a
LOCAL_EXPORT_C_INCLUDES += $(LOCAL_PATH)/brGraphics/include
LOCAL_LDLIBS += $(LOCAL_PATH)/brCore/libbrCore.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := brOpenGLES2
LOCAL_SRC_FILES := EGL/brEGLContext.cpp \
EGL/brEGLSupport.cpp \
EGL/brEGLWindow.cpp \
EGL/Android\brEGLAndroidSupport.cpp \
EGL/Android\brEGLAndroidWindow.cpp \
GLSL/brGLSLLinker.cpp \
GLSL/brGLSLProgram.cpp \
GLSL/brGLSLShader.cpp \
GLSL/brGLSLShaderFactory.cpp \
GLSL/brGLSLSupport.cpp \
brGLES2Context.cpp \
brGLES2DataBufferFactory.cpp \
brGLES2Mapping.cpp \
brGLES2Plugin.cpp \
brGLES2Renderer.cpp \
brGLES2Support.cpp \
brGLES2VertexBuffer.cpp \
extension/brGLVertexBufferObject.cpp
LOCAL_LDLIBS := -llog -landroid -lEGL -lGLESv2
LOCAL_LDLIBS += $(LOCAL_PATH)/jsoncpp/libjsoncpp.a
LOCAL_STATIC_LIBRARIES += brGraphics
LOCAL_STATIC_LIBRARIES += brMath
LOCAL_STATIC_LIBRARIES += brCore
LOCAL_STATIC_LIBRARIES += android_native_app_glue
include $(BUILD_SHARED_LIBRARY)
$(call import-module, android/native_app_glue)
Thanks for the informations. I try to show, how I actually build my project. Actually I use in each module
a prebuild of any dependency:
brCore --> Prebuild jsoncpp
brGraphics --> Prebuild brCore
brGLES --> Prebuild brCore, brGraphics
Application --> Prebuild brCore, brGraphics dynamically load brGLES
Is there a way to integrate those dependencies without an explicitly prebuild in each module?
So it looks like you're generating both a shared library and an executable. You should really use gnustl_shared to avoid problems then.
Another issue is that you're statically linking jsoncpp, brCore and brGraphics into both brGLES and Application, it means that both ELF binaries
will get an independent copy of every global variable present in these static libraries (including a _different_ singleton instance in each one of them).
I'm not sure what you mean, but normally, you should be able to build these static libraries directly if there is a valid Android.mk for them.
What's the reason for using prebuilt binaries exactly?
Where does this extra -lgnustl_shared comes from? You should not need this in your LOCAL_LDLIBS as long
as you used APP_STL := gnustl_shared. It's the reason for your linking error.
Yes, GLES is the shared library and the Application is the executable. I will change to gnustl_shared.
So it looks like you're generating both a shared library and an executable. You should really use gnustl_shared to avoid problems then.
Ok, may it be a solution to build any library with Singleton as shared library? On Linux and Windows I already use shared libs for thoseAnother issue is that you're statically linking jsoncpp, brCore and brGraphics into both brGLES and Application, it means that both ELF binaries
will get an independent copy of every global variable present in these static libraries (including a _different_ singleton instance in each one of them).
modules. I've switched on android to static modules, while I've to load those libraries explicitly before I could use them, which is not required
on Linux and Windows platform.
My engine is split in modules, and plug-ins which are build separately. On Linux and Windows I install those libraries before usage. AnyI'm not sure what you mean, but normally, you should be able to build these static libraries directly if there is a valid Android.mk for them.
What's the reason for using prebuilt binaries exactly?
dependency between those modules is solved by the installation path. While this is not possible on Android I use prebuilds. This is the only
mechanism I know to integrate modular sources.