ndk-build failed to build PocketSphinxAndroidDemo project - android-ndk

I am trying to use "android-ndk-r5b" to build PocketSphinx for Android.
I downloaded PocketSphinxAndroidDemo project from "https://cmusphinx.svn.sourceforge.net/svnroot/cmusphinx/trunk/PocketSphinxAndroidDemo" alone with "pocketsphinx" and "sphinxbase" projects.
I am on Windows 7 and using Cygwin to run "ndk-build" the problem is all static libraries (.a file) are generated but unable to create the .so file due to the following reference error:
$ /cygdrive/c/android-ndk-r5b/ndk-build
Gdbserver : [arm-linux-androideabi-4.4.3] libs/armeabi/gdbserver
Gdbsetup : libs/armeabi/gdb.setup
SharedLibrary : libpocketsphinx_jni.so
C:/eclipse/workspace/PocketSphinxAndroidDemo/obj/local/armeabi/libpocketsphinx.a
(pocketsphinx.o): In function `ps_reinit':
C:/eclipse/workspace/pocketsphinx/src/libpocketsphinx/pocketsphinx.c:228: undefi
ned reference to `logmath_get_base'
C:/eclipse/workspace/pocketsphinx/src/libpocketsphinx/pocketsphinx.c:231: undefi
ned reference to `logmath_free'
C:/eclipse/workspace/pocketsphinx/src/libpocketsphinx/pocketsphinx.c:232: undefi
ned reference to `logmath_init'
C:/eclipse/workspace/pocketsphinx/src/libpocketsphinx/pocketsphinx.c:293: undefi
ned reference to `ptmr_init'
C:/eclipse/workspace/PocketSphinxAndroidDemo/obj/local/armeabi/libpocketsphinx.a
(pocketsphinx.o): In function `ps_free':
C:/eclipse/workspace/pocketsphinx/src/libpocketsphinx/pocketsphinx.c:340: undefi
ned reference to `logmath_free'
C:/eclipse/workspace/PocketSphinxAndroidDemo/obj/local/armeabi/libpocketsphinx.a
(pocketsphinx.o): In function `ps_update_lmset':
C:/eclipse/workspace/pocketsphinx/src/libpocketsphinx/pocketsphinx.c:413: undefi
ned reference to `ngram_model_free'
C:/eclipse/workspace/PocketSphinxAndroidDemo/obj/local/armeabi/libpocketsphinx.a
(pocketsphinx.o): In function `ps_add_word':
C:/eclipse/workspace/pocketsphinx/src/libpocketsphinx/pocketsphinx.c:565: undefi
ned reference to `ngram_model_add_word'
All the header file paths are specified. No problem to create static libraries but has problem to link static libraries to create shared library.
Here is my "Android.mk" file:
# Build the native component of the PocketSphinx library for Android.
# You MUST change this to the absolute path of the directory containing
# sphinxbase and pocketsphinx source code.
#SPHINX_PATH := $(HOME)/Projects/Sphinx/trunk
SPHINX_PATH := /cygdrive/c/eclipse/workspace
# Copy this Android.mk along with pocketsphinx_wrap.c and the contents of the 'edu' folder
# built by swig to the jni/ directory of your Android project.
BASE_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_C_INCLUDES := $(SPHINX_PATH)/sphinxbase/include/android $(SPHINX_PATH)/sphinxbase/include
LOCAL_EXPORT_C_INCLUDES := $(SPHINX_PATH)/sphinxbase/include/android $(SPHINX_PATH)/sphinxbase/include
LOCAL_CFLAGS += -DHAVE_CONFIG_H
LOCAL_CFLAGS += -DANDROID_NDK
LOCAL_PATH := $(SPHINX_PATH)/sphinxbase/src/libsphinxbase/util
LOCAL_MODULE := sphinxutil
LOCAL_SRC_FILES := \
bio.c \
bitvec.c \
case.c \
ckd_alloc.c \
cmd_ln.c \
dtoa.c \
err.c \
errno.c \
f2c_lite.c \
filename.c \
genrand.c \
glist.c \
hash_table.c \
heap.c \
huff_code.c \
info.c \
listelem_alloc.c \
logmath.c.arm \
matrix.c \
mmio.c \
pio.c \
profile.c \
sbthread.c \
strfuncs.c \
utf8.c
include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_C_INCLUDES := $(SPHINX_PATH)/sphinxbase/include/android $(SPHINX_PATH)/sphinxbase/include
LOCAL_CFLAGS += -DHAVE_CONFIG_H
LOCAL_CFLAGS += -DANDROID_NDK
LOCAL_PATH := $(SPHINX_PATH)/sphinxbase/src/libsphinxbase/fe
LOCAL_MODULE := sphinxfe
LOCAL_ARM_MODE := arm
LOCAL_SRC_FILES := \
fe_interface.c \
fe_sigproc.c \
fe_warp_affine.c \
fe_warp.c \
fe_warp_inverse_linear.c \
fe_warp_piecewise_linear.c \
fixlog.c
include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_C_INCLUDES := $(SPHINX_PATH)/sphinxbase/include/android $(SPHINX_PATH)/sphinxbase/include
LOCAL_CFLAGS += -DHAVE_CONFIG_H
LOCAL_CFLAGS += -DANDROID_NDK
LOCAL_PATH := $(SPHINX_PATH)/sphinxbase/src/libsphinxbase/feat
LOCAL_MODULE := sphinxfeat
LOCAL_SRC_FILES := \
agc.c \
cmn.c \
cmn_prior.c \
feat.c \
lda.c
include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_C_INCLUDES := $(SPHINX_PATH)/sphinxbase/include/android $(SPHINX_PATH)/sphinxbase/include
LOCAL_CFLAGS += -DHAVE_CONFIG_H
LOCAL_CFLAGS += -DANDROID_NDK
LOCAL_PATH := $(SPHINX_PATH)/sphinxbase/src/libsphinxbase/lm
LOCAL_MODULE := sphinxlm
LOCAL_SRC_FILES := \
fsg_model.c \
jsgf.c \
jsgf_parser.c \
jsgf_scanner.c \
lm3g_model.c \
ngram_model_arpa.c \
ngram_model_dmp.c \
ngram_model_set.c \
ngram_model.c
include $(BUILD_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_C_INCLUDES := $(SPHINX_PATH)/sphinxbase/include/android $(SPHINX_PATH)/sphinxbase/include \
$(SPHINX_PATH)/pocketsphinx/include $(SPHINX_PATH)/pocketsphinx/src/libpocketsphinx \
$(SPHINX_PATH)/pocketsphinx/src/gst-plugin $(SPHINX_PATH)/sphinxbase/include/sphinxbase
LOCAL_CFLAGS += -DHAVE_CONFIG_H
LOCAL_CFLAGS += -DANDROID_NDK
LOCAL_PATH := $(SPHINX_PATH)/pocketsphinx/src/libpocketsphinx
LOCAL_MODULE := pocketsphinx
LOCAL_SRC_FILES := \
acmod.c \
bin_mdef.c \
blkarray_list.c \
dict.c \
dict2pid.c \
fsg_history.c \
fsg_lextree.c \
fsg_search.c \
hmm.c.arm \
mdef.c \
ms_gauden.c.arm \
ms_mgau.c.arm \
ms_senone.c.arm \
ngram_search.c \
ngram_search_fwdtree.c \
ngram_search_fwdflat.c \
phone_loop_search.c \
pocketsphinx.c \
ps_lattice.c \
ps_mllr.c \
ptm_mgau.c.arm \
s2_semi_mgau.c.arm \
tmat.c \
vector.c
include $(BUILD_STATIC_LIBRARY)
# Create the dynamic library wrapper
include $(CLEAR_VARS)
LOCAL_C_INCLUDES := $(SPHINX_PATH)/sphinxbase/include/android $(SPHINX_PATH)/sphinxbase/include \
$(SPHINX_PATH)/pocketsphinx/include $(SPHINX_PATH)/pocketsphinx/src/libpocketsphinx
LOCAL_CFLAGS += -DHAVE_CONFIG_H
LOCAL_CFLAGS += -DANDROID_NDK
LOCAL_PATH := $(BASE_PATH)
LOCAL_MODULE := pocketsphinx_jni
LOCAL_SRC_FILES := pocketsphinx_wrap.c
# See http://code.google.com/p/android/issues/detail?id=9439
PRIVATE_WHOLE_STATIC_LIBRARIES := \
$(call static-library-path,sphinxutil) \
$(call static-library-path,sphinxfe) \
$(call static-library-path,sphinxfeat) \
$(call static-library-path,sphinxlm) \
$(call static-library-path,pocketsphinx)
LOCAL_STATIC_LIBRARIES := sphinxutil sphinxfe sphinxfeat sphinxlm pocketsphinx
include $(BUILD_SHARED_LIBRARY)
=====================================================================
Thank you in advance for any suggestions!
gwofu

Reverse your LOCAL_STATIC_LIBRARIES Sequence is ok

To expand on user642960's response, I changed the LOCAL_STATIC_LIBRARIES line within Android.mk to:
LOCAL_STATIC_LIBRARIES := pocketsphinx sphinxlm sphinxfeat sphinxfe sphinxutil
After doing so, the errors that the submitter is describing went away for me. I also upgraded NDK, but that didn't seem to fix things on its own.

Related

Android ndk /i686-linux-android/bin\ld: warning: shared library text segment is not shareable

i'm trying to run my android studio(kotlin) project, but there is a problem when ndk build, like this:
> Task :libuvccamera:ndkBuild
> Android NDK: WARNING: APP_PLATFORM android-14 is higher than android:minSdkVersion 1 in ./AndroidManifest.xml. NDK binaries will *not* be comptible with devices older than android-14. See https://android.googlesource.com/platform/ndk/+/master/docs/user/common_problems.md for more information.
> make: Entering directory `C:/Users/Hamzah/AndroidStudioProjects/camera-bts-detector-master/camera-bts-detector-master/libuvccamera/src/main'
> [x86] SharedLibrary : libjpeg-turbo1500.so
> [armeabi-v7a] SharedLibrary : libuvc.so
> [armeabi-v7a] Install : libjpeg-turbo1500.so => libs/armeabi-v7a/libjpeg-turbo1500.so
> [armeabi-v7a] Install : libusb100.so => libs/armeabi-v7a/libusb100.so
> [x86] Install : libusb100.so => libs/x86/libusb100.so
> C:/Users/Hamzah/AppData/Local/Android/Sdk/ndk/16.1.4479499/build//../toolchains/x86-4.9/prebuilt/windows-x86_64/lib/gcc/i686-linux-android/4.9.x/../../../../i686-linux-android/bin\ld: warning: shared library text segment is not shareable
> C:/Users/Hamzah/AppData/Local/Android/Sdk/ndk/24.0.8215888/build//../toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include\bits/fortify/stdio.h:73: error: undefined reference to '__vsprintf_chk'
> clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)
> C:/Users/Hamzah/AppData/Local/Android/Sdk/ndk/24.0.8215888/build//../toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include\bits/fortify/stdio.h:73: error: undefined reference to '__vsprintf_chk'
> clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)
> make: *** [obj/local/armeabi-v7a/libuvc.so] Error 1
> make: *** Waiting for unfinished jobs....
> make: *** [obj/local/x86/libjpeg-turbo1500.so] Error 1
> make: Leaving directory `C:/Users/Hamzah/AndroidStudioProjects/camera-bts-detector-master/camera-bts-detector-master/libuvccamera/src/main'
> Task :libuvccamera:ndkBuild FAILED
Execution failed for task ':libuvccamera:ndkBuild'.
> Process 'command 'C:\Users\Hamzah\AppData\Local\Android\Sdk\ndk\16.1.4479499/ndk-build.cmd'' finished with non-zero exit value 2
and this is my AndroidManifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.serenegiant.uvccamera"
android:versionCode="2"
android:versionName="1.1" >
this is local.properties:
sdk.dir=C\:\\Users\\Hamzah\\AppData\\Local\\Android\\Sdk
ndk.dir=C\:\\Users\\Hamzah\\AppData\\Local\\Android\\Sdk\\ndk\\16.1.4479499
this is Android.mk:
######################################################################
# Make shared library libUVCCamera.so
######################################################################
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
######################################################################
# Make shared library libUVCCamera.so
######################################################################
CFLAGS := -Werror
LOCAL_C_INCLUDES := \
$(LOCAL_PATH)/ \
$(LOCAL_PATH)/../ \
$(LOCAL_PATH)/../rapidjson/include \
LOCAL_CFLAGS := $(LOCAL_C_INCLUDES:%=-I%)
LOCAL_CFLAGS += -DANDROID_NDK
LOCAL_CFLAGS += -DLOG_NDEBUG
LOCAL_CFLAGS += -DACCESS_RAW_DESCRIPTORS
LOCAL_CFLAGS += -O3 -fstrict-aliasing -fprefetch-loop-arrays
LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -ldl
LOCAL_LDLIBS += -llog
LOCAL_LDLIBS += -landroid
LOCAL_SHARED_LIBRARIES += usb100 uvc
LOCAL_ARM_MODE := arm
LOCAL_SRC_FILES := \
_onload.cpp \
utilbase.cpp \
UVCCamera.cpp \
UVCPreview.cpp \
UVCButtonCallback.cpp \
UVCStatusCallback.cpp \
Parameters.cpp \
serenegiant_usb_UVCCamera.cpp
LOCAL_MODULE := UVCCamera
include $(BUILD_SHARED_LIBRARY)
I've tried NDK version 16 and 17, the result is as above.
I've also tried NDK version 18-24, the result is like:
Android NDK: android-14 is unsupported. Using minimum supported version android-16
Android NDK: WARNING: APP_PLATFORM android-16 is higher than android:minSdkVersion 1 in ./AndroidManifest.xml.
any suggestions for me?
sorry i'm a beginner,
all answers i appreciate

ndk-bulid problem with bulit file Macintosh (CR) and Unix (LF)

I'm trying to build my native library (C++) but I always end up with output file as Macintosh (CR) and not Unix (LF)
here's my files:
Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := test1
LOCAL_SRC_FILES := hellocode.cpp
LOCAL_CPPFLAGS := -std=gnu++0x -Wall -fPIE
LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog -fPIE -pie
include $(BUILD_EXECUTABLE)
Application.mk
APP_STL := c++_static
APP_ABI := arm64-v8a armeabi-v7a x86 x86_64
APP_PLATFORM := android-21
APP_OPTIM := release
APP_CPPFLAGS := -std=c++14 -fno-rtti -fno-exceptions -DNDEBUG -Wall -fpermissive -fpic
APP_LDFLAGS := -llog
APP_THIN_ARCHIVE := true
APP_PIE := true
Bulid.bat:
"C:\Users\UserOne\AppData\Local\Android\Sdk\ndk\21.0.6113669\ndk-build"
Output file must be Unix(LF) otherwise it won't work, How I can fix it?

How to use openssl library in cocos2dx?

Now I have libssl.so and libcrypto.so, but I don't know how to use them in cocos2dx. It always gives me the error like this:
jni/../../Classes/Custom_SSL.cpp:18: error: undefined reference to 'RSA_new'
jni/../../Classes/Custom_SSL.cpp:19: error: undefined reference to 'PEM_read_RSA_PUBKEY'
jni/../../Classes/Custom_SSL.cpp:25: error: undefined reference to 'RSA_size'
jni/../../Classes/Custom_SSL.cpp:27: error: undefined reference to 'RSA_public_encrypt'
jni/../../Classes/Custom_SSL.cpp:33: error: undefined reference to 'RSA_free'
How do I solve this problem?
Now I know how to solve this problem. The program can't connect to libssl.so and libcrypto.so, so it will give me the error "undefined reference to ...".
I add the openssl folder to the external folder.
There is the code of Android.mk in openssl folder.
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := openssl
LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/lib/libssl.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := opencrypto
LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/lib/libcrypto.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := openssl_static
LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/lib/libssl.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := opencrypto_static
LOCAL_SRC_FILES := $(TARGET_ARCH_ABI)/lib/libcrypto.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
include $(PREBUILT_STATIC_LIBRARY)
Next, cd ../cocos, I have to change the content of the other Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := cocos2dx_static
LOCAL_MODULE_FILENAME := libcocos2d
LOCAL_SRC_FILES := \
cocos2d.cpp \
2d/CCAction.cpp \
2d/CCActionCamera.cpp \
2d/CCActionCatmullRom.cpp \
2d/CCActionEase.cpp \
2d/CCActionGrid.cpp \
2d/CCActionGrid3D.cpp \
2d/CCActionInstant.cpp \
2d/CCActionInterval.cpp \
2d/CCActionManager.cpp \
2d/CCActionPageTurn3D.cpp \
2d/CCActionProgressTimer.cpp \
2d/CCActionTiledGrid.cpp \
2d/CCActionTween.cpp \
2d/CCAnimation.cpp \
2d/CCAnimationCache.cpp \
2d/CCAtlasNode.cpp \
2d/CCClippingNode.cpp \
2d/CCComponent.cpp \
2d/CCComponentContainer.cpp \
2d/CCDrawNode.cpp \
2d/CCDrawingPrimitives.cpp \
2d/CCFont.cpp \
2d/CCFontAtlas.cpp \
2d/CCFontAtlasCache.cpp \
2d/CCFontCharMap.cpp \
2d/CCFontFNT.cpp \
2d/CCFontFreeType.cpp \
2d/CCGLBufferedNode.cpp \
2d/CCGrabber.cpp \
2d/CCGrid.cpp \
2d/CCLabel.cpp \
2d/CCLabelAtlas.cpp \
2d/CCLabelBMFont.cpp \
2d/CCLabelTTF.cpp \
2d/CCLabelTextFormatter.cpp \
2d/CCLayer.cpp \
2d/CCMenu.cpp \
2d/CCMenuItem.cpp \
2d/CCMotionStreak.cpp \
2d/CCNode.cpp \
2d/CCNodeGrid.cpp \
2d/CCParallaxNode.cpp \
2d/CCParticleBatchNode.cpp \
2d/CCParticleExamples.cpp \
2d/CCParticleSystem.cpp \
2d/CCParticleSystemQuad.cpp \
2d/CCProgressTimer.cpp \
2d/CCRenderTexture.cpp \
2d/CCScene.cpp \
2d/CCSprite.cpp \
2d/CCSpriteBatchNode.cpp \
2d/CCSpriteFrame.cpp \
2d/CCSpriteFrameCache.cpp \
2d/CCTMXLayer.cpp \
2d/CCFastTMXLayer.cpp \
2d/CCTMXObjectGroup.cpp \
2d/CCTMXTiledMap.cpp \
2d/CCFastTMXTiledMap.cpp \
2d/CCTMXXMLParser.cpp \
2d/CCTextFieldTTF.cpp \
2d/CCTileMapAtlas.cpp \
2d/CCTransition.cpp \
2d/CCTransitionPageTurn.cpp \
2d/CCTransitionProgress.cpp \
2d/CCTweenFunction.cpp \
3d/CCAnimate3D.cpp \
3d/CCAnimation3D.cpp \
3d/CCBundle3D.cpp \
3d/CCBundleReader.cpp \
3d/CCMesh.cpp \
3d/CCMeshSkin.cpp \
3d/CCSprite3DMaterial.cpp \
3d/CCObjLoader.cpp \
3d/CCSprite3D.cpp \
platform/CCGLViewProtocol.cpp \
platform/CCFileUtils.cpp \
platform/CCSAXParser.cpp \
platform/CCThread.cpp \
platform/CCImage.cpp \
math/CCAffineTransform.cpp \
math/CCGeometry.cpp \
math/CCVertex.cpp \
math/Mat4.cpp \
math/MathUtil.cpp \
math/Quaternion.cpp \
math/TransformUtils.cpp \
math/Vec2.cpp \
math/Vec3.cpp \
math/Vec4.cpp \
base/CCAutoreleasePool.cpp \
base/CCConfiguration.cpp \
base/CCConsole.cpp \
base/CCData.cpp \
base/CCDataVisitor.cpp \
base/CCDirector.cpp \
base/CCEvent.cpp \
base/CCEventAcceleration.cpp \
base/CCEventCustom.cpp \
base/CCEventDispatcher.cpp \
base/CCEventFocus.cpp \
base/CCEventKeyboard.cpp \
base/CCEventController.cpp \
base/CCEventListener.cpp \
base/CCEventListenerController.cpp \
base/CCEventListenerAcceleration.cpp \
base/CCEventListenerCustom.cpp \
base/CCEventListenerFocus.cpp \
base/CCEventListenerKeyboard.cpp \
base/CCEventListenerMouse.cpp \
base/CCEventListenerTouch.cpp \
base/CCEventMouse.cpp \
base/CCEventTouch.cpp \
base/CCIMEDispatcher.cpp \
base/CCNS.cpp \
base/CCProfiling.cpp \
base/CCRef.cpp \
base/CCScheduler.cpp \
base/CCScriptSupport.cpp \
base/CCTouch.cpp \
base/CCUserDefault.cpp \
base/CCUserDefaultAndroid.cpp \
base/CCValue.cpp \
base/TGAlib.cpp \
base/ZipUtils.cpp \
base/atitc.cpp \
base/base64.cpp \
base/ccCArray.cpp \
base/ccFPSImages.c \
base/ccTypes.cpp \
base/ccUTF8.cpp \
base/ccUtils.cpp \
base/etc1.cpp \
base/s3tc.cpp \
base/CCController.cpp \
base/CCController-android.cpp \
base/ObjectFactory.cpp \
renderer/CCBatchCommand.cpp \
renderer/CCCustomCommand.cpp \
renderer/CCGLProgram.cpp \
renderer/CCGLProgramCache.cpp \
renderer/CCGLProgramState.cpp \
renderer/CCGLProgramStateCache.cpp \
renderer/CCGroupCommand.cpp \
renderer/CCQuadCommand.cpp \
renderer/CCMeshCommand.cpp \
renderer/CCRenderCommand.cpp \
renderer/CCRenderer.cpp \
renderer/CCTexture2D.cpp \
renderer/CCTextureAtlas.cpp \
renderer/CCTextureCache.cpp \
renderer/ccGLStateCache.cpp \
renderer/ccShaders.cpp \
deprecated/CCArray.cpp \
deprecated/CCSet.cpp \
deprecated/CCString.cpp \
deprecated/CCDictionary.cpp \
deprecated/CCDeprecated.cpp \
deprecated/CCNotificationCenter.cpp \
physics/CCPhysicsBody.cpp \
physics/CCPhysicsContact.cpp \
physics/CCPhysicsJoint.cpp \
physics/CCPhysicsShape.cpp \
physics/CCPhysicsWorld.cpp \
physics/chipmunk/CCPhysicsBodyInfo_chipmunk.cpp \
physics/chipmunk/CCPhysicsContactInfo_chipmunk.cpp \
physics/chipmunk/CCPhysicsJointInfo_chipmunk.cpp \
physics/chipmunk/CCPhysicsShapeInfo_chipmunk.cpp \
physics/chipmunk/CCPhysicsWorldInfo_chipmunk.cpp \
../external/ConvertUTF/ConvertUTFWrapper.cpp \
../external/ConvertUTF/ConvertUTF.c \
../external/tinyxml2/tinyxml2.cpp \
../external/unzip/ioapi.cpp \
../external/unzip/unzip.cpp \
../external/edtaa3func/edtaa3func.cpp \
../external/xxhash/xxhash.c
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) \
$(LOCAL_PATH)/. \
$(LOCAL_PATH)/platform/android \
$(LOCAL_PATH)/../external/tinyxml2 \
$(LOCAL_PATH)/../external/unzip \
$(LOCAL_PATH)/../external/chipmunk/include/chipmunk \
$(LOCAL_PATH)/../external/xxhash \
$(LOCAL_PATH)/../external/nslog\
$(LOCAL_PATH)/../external/curl \
$(LOCAL_PATH)/../external/openssl \
$(LOCAL_PATH)/../external
LOCAL_C_INCLUDES := $(LOCAL_PATH) \
$(LOCAL_PATH)/. \
$(LOCAL_PATH)/platform/android \
$(LOCAL_PATH)/../external \
$(LOCAL_PATH)/../external/tinyxml2 \
$(LOCAL_PATH)/../external/unzip \
$(LOCAL_PATH)/../external/chipmunk/include/chipmunk \
$(LOCAL_PATH)/../external/edtaa3func \
$(LOCAL_PATH)/../external/xxhash \
$(LOCAL_PATH)/../external/ConvertUTF \
$(LOCAL_PATH)/../external/openssl \
$(LOCAL_PATH)/../external/nslog
LOCAL_LDLIBS := -lGLESv2 \
-llog \
-lz \
-landroid
LOCAL_EXPORT_LDLIBS := -lGLESv2 \
-llog \
-lz \
-landroid
#add shared library (if you need)
#LOCAL_SHARED_LIBRARIES := opencrypto
#LOCAL_SHARED_LIBRARIES += openssl
LOCAL_WHOLE_STATIC_LIBRARIES := cocos_freetype2_static
LOCAL_WHOLE_STATIC_LIBRARIES += chipmunk_static
LOCAL_WHOLE_STATIC_LIBRARIES += cocos2dxandroid_static
#add static library
LOCAL_WHOLE_STATIC_LIBRARIES += opencrypto_static
LOCAL_WHOLE_STATIC_LIBRARIES += openssl_static
# define the macro to compile through support/zip_support/ioapi.c
LOCAL_CFLAGS := -DUSE_FILE32API
LOCAL_CPPFLAGS := -Wno-deprecated-declarations -Wno-extern-c-compat
LOCAL_EXPORT_CFLAGS := -DUSE_FILE32API
LOCAL_EXPORT_CPPFLAGS := -Wno-deprecated-declarations -Wno-extern-c-compat
include $(BUILD_STATIC_LIBRARY)
$(call import-module,freetype2/prebuilt/android)
$(call import-module,chipmunk)
$(call import-module,platform/android)
#add
$(call import-module,openssl)
Now I can use these libraries in cocos2dx.

Could someone please assist with this NDK linker error? Been working at it for hours. NDK bug?

I am trying to compile and link a simple enough program (basically a hello world example) all day long. I've asked the author of the library and he told me to fix my linker dependencies. Here is the relevant info:
I also tried compiling with the author's build tool and linking it as a static library, but to no avail. I have also tried all variations of the STL build environment. Am I doing anything wrong, or is something else the problem?
testbgfx.cpp
#include <SDL.h>
#include <bgfxplatform.h>
#include <bgfx.h>
int main(int argc, char* args[])
{
// SDL_Init( SDL_INIT_EVERYTHING ); Uncommenting this did nothing
SDL_Rect bounds;
SDL_GetDisplayBounds(0,&bounds);
int height = bounds.h;
int width = bounds.w;
SDL_Window* window = SDL_CreateWindow("TestApp",SDL_WINDOWPOS_UNDEFINED,SDL_WINDOWPOS_UNDEFINED,width,height,SDL_WINDOW_MAXIMIZED);
bgfx_sdlSetWindow(window);
bgfx::init();
return 0;
}
Android.mk (for client app)
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := main
LOCAL_SRC_FILES := testbgfx.cpp
# Switching to static lib did nothing
#LOCAL_STATIC_LIBRARIES := bgfx
LOCAL_SHARED_LIBRARIES := SDL2 bx bgfx
# Required for compilation
LOCAL_CXXFLAGS := $(LOCAL_CFLAGS) -D__STDC_LIMIT_MACRO -D__STDC_FORMAT_MACROS -D__STDC_CONSTANT_MACROS
LOCAL_LDLIBS := -lGLESv1_CM -lGLESv2 -llog -lc -ldl -lm -landroid -lEGL
include $(BUILD_SHARED_LIBRARY)
$(call import-module,bx)
$(call import-module,bgfx)
$(call import-module,SDL2)
The Android.mk for the bgfx library (in ndk sources directory, as required)
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := bgfx
#This did nothing
#LOCAL_C_INCLUDES += src
#Disabled those to see that would happen - nothing
#LOCAL_CFLAGS := -Wall -Wextra -g -Wa,--noexecstack -no-canonical-prefixes -ffunction-sections -Wno-psabi -Wunused-value -Wundef -fstack-protector
#LOCAL_CXXFLAGS := $(LOCAL_CFLAGS) -D__STDC_LIMIT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_CONSTANT_MACROS -MMD -MP -fPIC -std=c++0x
LOCAL_SRC_FILES := src
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
#Enabling the following changed nothing
#LOCAL_C_INCLUDES := $(LOCAL_PATH)/3rdparty
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
# This doesn't work
#LOCAL_EXPORT_C_INCLUDES += $(LOCAL_PATH)/src/*.h
# Neither does this
#LOCAL_EXPORT_C_INCLUDES += $(wildcard $(LOCAL_PATH)/src/*h)
LOCAL_SHARED_LIBRARIES := bx
LOCAL_EXPORT_SHARED_LIBRARIES := bx
#Switching to static did nothing
#include $(BUILD_STATIC_LIBRARY)
include $(BUILD_SHARED_LIBRARY)
$(call import-modules,bx)
Android.mk for bx (utility lib depended on my bgfx, also in the ndk sources dir)
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := bx
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
include $(BUILD_SHARED_LIBRARY)
Here is relevant error log:
/home/noob/android/android-ndk-r10d/toolchains/arm-linux-androideabi- 4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++ -Wl,-soname,libmain.so -shared --sysroot=/home/noob/android/android-ndk-r10d/platforms/android-18/arch-arm ./obj/local/armeabi-v7a/objs/main/testbgfx.o ./obj/local/armeabi-v7a/libSDL2.a -lgcc ./obj/local/armeabi-v7a/libbx.so ./obj/local/armeabi-v7a/libbgfx.so ./obj/local/armeabi-v7a/libgnustl_shared.so -no-canonical-prefixes -march=armv7-a -Wl,--fix-cortex-a8 -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -mthumb -L/home/noob/android/android-ndk-r10d/platforms/android-18/arch-arm/usr/lib -lGLESv1_CM -lGLESv2 -llog -lc -ldl -lm -landroid -lEGL -Wl,--undefined=Java_org_libsdl_app_SDLActivity_nativeInit -ldl -lGLESv1_CM -lGLESv2 -llog -landroid /home/noob/android/android-ndk/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi-v7a/libsupc++.a -lc -lm -o ./obj/local/armeabi-v7a/libmain.so
jni/src/testbgfx.cpp:18: error: undefined reference to 'bgfx::init(bgfx::RendererType::Enum, bgfx::CallbackI*, bx::ReallocatorI*)'
collect2: error: ld returned 1 exit status
make: *** [obj/local/armeabi-v7a/libmain.so] Error 1
The Android.mk for bgfx doesn't actually seem to be listing any source files to compile - you've only listed LOCAL_SRC_FILES := src which seems to be a directory. You need to list all the individual C/C++ source files here.

How to build protocol buffer by Android NDK [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I want to built a native version of Google's protocol buffers library.
How would I do that?
I Use this Android.mk and build SUCCESSFUL
# Copyright (C) 2009 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
CC_LITE_SRC_FILES := \
src/google/protobuf/stubs/common.cc \
src/google/protobuf/stubs/once.cc \
src/google/protobuf/stubs/hash.cc \
src/google/protobuf/extension_set.cc \
src/google/protobuf/generated_message_util.cc \
src/google/protobuf/message_lite.cc \
src/google/protobuf/repeated_field.cc \
src/google/protobuf/wire_format_lite.cc \
src/google/protobuf/io/coded_stream.cc \
src/google/protobuf/io/zero_copy_stream.cc \
src/google/protobuf/io/zero_copy_stream_impl_lite.cc
COMPILER_SRC_FILES := \
src/google/protobuf/descriptor.cc \
src/google/protobuf/descriptor.pb.cc \
src/google/protobuf/descriptor_database.cc \
src/google/protobuf/dynamic_message.cc \
src/google/protobuf/extension_set.cc \
src/google/protobuf/extension_set_heavy.cc \
src/google/protobuf/generated_message_reflection.cc \
src/google/protobuf/generated_message_util.cc \
src/google/protobuf/message.cc \
src/google/protobuf/message_lite.cc \
src/google/protobuf/reflection_ops.cc \
src/google/protobuf/repeated_field.cc \
src/google/protobuf/service.cc \
src/google/protobuf/text_format.cc \
src/google/protobuf/unknown_field_set.cc \
src/google/protobuf/wire_format.cc \
src/google/protobuf/wire_format_lite.cc \
src/google/protobuf/compiler/code_generator.cc \
src/google/protobuf/compiler/command_line_interface.cc \
src/google/protobuf/compiler/importer.cc \
src/google/protobuf/compiler/main.cc \
src/google/protobuf/compiler/parser.cc \
src/google/protobuf/compiler/plugin.cc \
src/google/protobuf/compiler/plugin.pb.cc \
src/google/protobuf/compiler/subprocess.cc \
src/google/protobuf/compiler/zip_writer.cc \
src/google/protobuf/compiler/cpp/cpp_enum.cc \
src/google/protobuf/compiler/cpp/cpp_enum_field.cc \
src/google/protobuf/compiler/cpp/cpp_extension.cc \
src/google/protobuf/compiler/cpp/cpp_field.cc \
src/google/protobuf/compiler/cpp/cpp_file.cc \
src/google/protobuf/compiler/cpp/cpp_generator.cc \
src/google/protobuf/compiler/cpp/cpp_helpers.cc \
src/google/protobuf/compiler/cpp/cpp_message.cc \
src/google/protobuf/compiler/cpp/cpp_message_field.cc \
src/google/protobuf/compiler/cpp/cpp_primitive_field.cc \
src/google/protobuf/compiler/cpp/cpp_service.cc \
src/google/protobuf/compiler/cpp/cpp_string_field.cc \
src/google/protobuf/compiler/java/java_enum.cc \
src/google/protobuf/compiler/java/java_enum_field.cc \
src/google/protobuf/compiler/java/java_extension.cc \
src/google/protobuf/compiler/java/java_field.cc \
src/google/protobuf/compiler/java/java_file.cc \
src/google/protobuf/compiler/java/java_generator.cc \
src/google/protobuf/compiler/java/java_helpers.cc \
src/google/protobuf/compiler/java/java_message.cc \
src/google/protobuf/compiler/java/java_message_field.cc \
src/google/protobuf/compiler/java/java_primitive_field.cc \
src/google/protobuf/compiler/java/java_service.cc \
src/google/protobuf/compiler/javamicro/javamicro_enum.cc \
src/google/protobuf/compiler/javamicro/javamicro_enum_field.cc \
src/google/protobuf/compiler/javamicro/javamicro_field.cc \
src/google/protobuf/compiler/javamicro/javamicro_file.cc \
src/google/protobuf/compiler/javamicro/javamicro_generator.cc \
src/google/protobuf/compiler/javamicro/javamicro_helpers.cc \
src/google/protobuf/compiler/javamicro/javamicro_message.cc \
src/google/protobuf/compiler/javamicro/javamicro_message_field.cc \
src/google/protobuf/compiler/javamicro/javamicro_primitive_field.cc \
src/google/protobuf/compiler/python/python_generator.cc \
src/google/protobuf/io/coded_stream.cc \
src/google/protobuf/io/gzip_stream.cc \
src/google/protobuf/io/printer.cc \
src/google/protobuf/io/tokenizer.cc \
src/google/protobuf/io/zero_copy_stream.cc \
src/google/protobuf/io/zero_copy_stream_impl.cc \
src/google/protobuf/io/zero_copy_stream_impl_lite.cc \
src/google/protobuf/stubs/common.cc \
src/google/protobuf/stubs/hash.cc \
src/google/protobuf/stubs/once.cc \
src/google/protobuf/stubs/structurally_valid.cc \
src/google/protobuf/stubs/strutil.cc \
src/google/protobuf/stubs/substitute.cc
# C++ full library
# =======================================================
#include $(CLEAR_VARS)
LOCAL_MODULE := libprotobuf
LOCAL_MODULE_TAGS := optional
LOCAL_CPP_EXTENSION := .cc
LOCAL_SRC_FILES := \
$(CC_LITE_SRC_FILES) \
src/google/protobuf/stubs/strutil.cc \
src/google/protobuf/stubs/substitute.cc \
src/google/protobuf/stubs/structurally_valid.cc \
src/google/protobuf/descriptor.cc \
src/google/protobuf/descriptor.pb.cc \
src/google/protobuf/descriptor_database.cc \
src/google/protobuf/dynamic_message.cc \
src/google/protobuf/extension_set_heavy.cc \
src/google/protobuf/generated_message_reflection.cc \
src/google/protobuf/message.cc \
src/google/protobuf/reflection_ops.cc \
src/google/protobuf/service.cc \
src/google/protobuf/text_format.cc \
src/google/protobuf/unknown_field_set.cc \
src/google/protobuf/wire_format.cc \
src/google/protobuf/io/gzip_stream.cc \
src/google/protobuf/io/printer.cc \
src/google/protobuf/io/tokenizer.cc \
src/google/protobuf/io/zero_copy_stream_impl.cc \
src/google/protobuf/compiler/importer.cc \
src/google/protobuf/compiler/parser.cc
LOCAL_C_INCLUDES := \
$(LOCAL_PATH)/src
LOCAL_C_INCLUDES := \
$(LOCAL_PATH)/android \
bionic \
$(LOCAL_PATH)/src \
$(JNI_H_INCLUDE)
LOCAL_SHARED_LIBRARIES := \
libz libcutils libutils
LOCAL_LDLIBS := -lz
# stlport conflicts with the host stl library
ifneq ($(TARGET_SIMULATOR),true)
LOCAL_C_INCLUDES += external/stlport/stlport
LOCAL_SHARED_LIBRARIES += libstlport
endif
# Define the header files to be copied
#LOCAL_COPY_HEADERS := \
# src/google/protobuf/stubs/once.h \
# src/google/protobuf/stubs/common.h \
# src/google/protobuf/io/coded_stream.h \
# src/google/protobuf/generated_message_util.h \
# src/google/protobuf/repeated_field.h \
# src/google/protobuf/extension_set.h \
# src/google/protobuf/wire_format_lite_inl.h
#
#LOCAL_COPY_HEADERS_TO := $(LOCAL_MODULE)
LOCAL_CFLAGS := -DGOOGLE_PROTOBUF_NO_RTTI
include $(BUILD_SHARED_LIBRARY)
Android.mk mentioned above works fine, thanks a lot.
I would like to describe all the steps for building protobuf for android.
Configure sources for android.
Use the following script (got it here: http://habrahabr.ru/post/119693/):
PREBUILT=/Users/user/android-ndk-r7b/toolchains/arm-linux-androideabi-4.4.3
PLATFORM=/Users/user/android-ndk-r7b/platforms/android-3/arch-arm/
export CC="/Users/user/android-ndk-r7b/toolchains/arm-linux-androideabi- 4.4.3/prebuilt/darwin-x86/bin/arm-linux-androideabi-gcc"
export CFLAGS="-fPIC -DANDROID -nostdlib"
export ANDROID_ROOT="/Users/user/android-ndk-r7b"
export LDFLAGS="-Wl,-rpath-link=$ANDROID_ROOT/platforms/android-3/arch-arm/usr/lib/ -L$ANDROID_ROOT/platforms/android-3/arch-arm/usr/lib/"
export CPPFLAGS="-I$ANDROID_ROOT/platforms/android-3/arch-arm/usr/include/"
export LIBS="-lc "
./configure --host=arm-eabi
Delete the following lines from mentioned above Android.mk file:
src/google/protobuf/stubs/strutil.cc \
src/google/protobuf/stubs/substitute.cc \
src/google/protobuf/stubs/structurally_valid.cc \
src/google/protobuf/descriptor.cc \
src/google/protobuf/descriptor.pb.cc \
src/google/protobuf/descriptor_database.cc \
src/google/protobuf/dynamic_message.cc \
src/google/protobuf/extension_set_heavy.cc \
src/google/protobuf/generated_message_reflection.cc \
src/google/protobuf/message.cc \
src/google/protobuf/reflection_ops.cc \
src/google/protobuf/service.cc \
src/google/protobuf/text_format.cc \
src/google/protobuf/unknown_field_set.cc \
src/google/protobuf/wire_format.cc \
src/google/protobuf/io/gzip_stream.cc \
src/google/protobuf/io/printer.cc \
src/google/protobuf/io/tokenizer.cc \
src/google/protobuf/io/zero_copy_stream_impl.cc \
src/google/protobuf/compiler/importer.cc \
src/google/protobuf/compiler/parser.cc
It is needed for building lite version of library.
Unfortunately full version of the lib works just from Android 2.3.
I tested lite version for Android 1.6, 2.1, 2.3.
build the library using ndk-build.
for generating c++ files (using protoc compiler) for the lite library it is needed to include: option optimize_for = LITE_RUNTIME; in .proto file.

Resources