I am confused If I am doing something wrong while using the static library.
For testing,
I'm trying to make a shared library(pal) using a static library(mtwist).
But I am getting undefined reference to the functions of the static library(mtwist)
Compile thumb : mtwist <= mtwist.c
Compile thumb : mtwist <= randistrs.c
StaticLibrary : libmtwist.a
SharedLibrary : libpal.so
F:/afe/obj/local/armeabi/objs-debug/pal/PALrandom.o: In function `CRandom':
F:/afe/jni/PAL/Sources/PALrandom.cpp:47: undefined reference to `mts_seed'
F:/afe/jni/PAL/Sources/PALrandom.cpp:48: undefined reference to `mts_mark_initialized'
F:/afe/jni/PAL/Sources/PALrandom.cpp:47: undefined reference to `mts_seed'
F:/afe/jni/PAL/Sources/PALrandom.cpp:48: undefined reference to `mts_mark_initialized'
F:/afe/obj/local/armeabi/objs-debug/pal/PALrandom.o: In function `PAL::CRandom::
GetRandomInteger16()':
F:/afe/jni/PAL/Sources/PALrandom.cpp:60: undefined reference to `rds_iuniform'
F:/afe/obj/local/armeabi/objs-debug/pal/PALrandom.o: In function `PAL::CRandom::GetRandomInteger32()':
F:/afe/jni/PAL/Sources/PALrandom.cpp:67: undefined reference to `rds_iuniform'
F:/afe/jni/PAL/Sources/PALrandom.cpp:69: undefined reference to `rds_iuniform'
collect2: ld returned 1 exit status
make: *** [/cygdrive/f/afe/obj/local/armeabi/libpal.so] Error 1
**Look libmtwist.a has been built though its giving undefined reference for the mtwist functions.
This is the Android.mk file mtwist(Static Library):
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := mtwist
LOCAL_SRC_FILES := mtwist.c \
randistrs.c \
include $(BUILD_STATIC_LIBRARY)
This is the Android.mk file of pal (Shared Library):
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_C_INCLUDES += $(LOCAL_PATH)/../Headers \
$(LOCAL_PATH)/../../BaseMulti/Headers \
$(LOCAL_PATH)/../../boost \
$(LOCAL_PATH)/../../mtwist-0.7
LOCAL_CFLAGS += -Wno-deprecated -D_LINUX -DBOOST_HAS_PTHREADS -fexceptions
LOCAL_MODULE := pal
LOCAL_SRC_FILES := PALcritsec.cpp \
PALdebug.cpp \
PALdebuglog.cpp \
PALinet.cpp \
PALlocalhostUdpEvent.cpp \
PALnetwork.cpp \
PALpollarray.cpp \
PALprofiler.cpp \
PALrandom.cpp \
PALserializable.cpp \
PALsocket.cpp \
PALstringutil.cpp \
PALsystime.cpp \
PALthread.cpp \
LOCAL_SHARED_LIBRARIES := boostthread
LOCAL_WHOLE_STATIC_LIBRARIES := mtwist
include $(BUILD_SHARED_LIBRARY)
and this is the main Android.mk file:
ROOT_DIR := $(call my-dir)
include $(ROOT_DIR)/PAL/Sources/Android.mk
include $(ROOT_DIR)/mtwist-0.7/Android.mk
include $(ROOT_DIR)/boost/libs/thread/src/Android.mk
include $(ROOT_DIR)/PAL/Sources/Android.mk
include $(ROOT_DIR)/mtwist-0.7/Android.mk
include $(ROOT_DIR)/boost/libs/thread/src/Android.mk
Did you trie to change build order for me it looks like you try to build pal, before mtwist, and i think boost should be at top of it.
include $(ROOT_DIR)/boost/libs/thread/src/Android.mk
include $(ROOT_DIR)/mtwist-0.7/Android.mk
include $(ROOT_DIR)/PAL/Sources/Android.mk
And why use some LOCAL_WHOLE_STATIC_LIBRARIES that's not documented at least not in r5b? ( or at least i can not find ;] )
I would use something like this:
LOCAL_SHARED_LIBRARIES := boostthread
LOCAL_STATIC_LIBRARIES := mtwist
Related
I am trying to compile a module for android using the ndk. The library has a dependency on glib, so I built that using https://github.com/ieei/glib, and everything seemed ok. However, when I try to use the glib module in my Android.mk file I get the following on running ndk-build:
jni/fluidsynth/fluidsynth/fluidsynth/src/fluid_cmd.c:1837: error: undefined reference to 'g_thread_init'
jni/fluidsynth/fluidsynth/fluidsynth/src/fluid_event.c:647: error: undefined reference to 'g_thread_init'
jni/fluidsynth/fluidsynth/fluidsynth/src/fluid_midi_router.c:106: error: undefined reference to 'g_thread_init'
jni/fluidsynth/fluidsynth/fluidsynth/src/fluid_sys.h:161: error: undefined reference to 'g_thread_init'
I looked up solutions to this problem, and I found this: http://ragnermagalhaes.blogspot.com/2007/09/undefined-reference-to-gthreadinit.html, but couldn't seem to get either of the proposed solutions to do anything for me (possibly because I am pretty new to the whole makefile thing)
My Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../PdCore/jni/libpd/pure-data/src \
$(LOCAL_PATH)/../glib \
$(LOCAL_PATH)/../glib/glib \
$(LOCAL_PATH)/../glib/gnulib \
$(LOCAL_PATH)/../glib/android \
$(LOCAL_PATH)/fluidsynth/fluidsynth/fluidsynth/include/fluidsynth \
$(LOCAL_PATH)/fluidsynth/fluidsynth/fluidsynth/include
LOCAL_MODULE := soundfonts
LOCAL_CFLAGS := -DPD
LOCAL_CFLAGS += -std=c11
LOCAL_CFLAGS += -w
LOCAL_CFLAGS +=
FLUID_SRC := $(wildcard $(LOCAL_PATH)/fluidsynth/fluidsynth/fluidsynth/src/*.c)
LOCAL_SRC_FILES := $(FLUID_SRC:$(LOCAL_PATH)/%=%) \
soundfonts.c
LOCAL_LDLIBS := $(LOCAL_PATH)/../glib/libs/armeabi/libglib-2.0.so
LOCAL_LDLIBS += -L$(LOCAL_PATH)/../PdCore/libs/$(TARGET_ARCH_ABI) -lpd -lgthread-2.0 -lglib-2.0
include $(BUILD_SHARED_LIBRARY)
Anybody have ideas for how to get rid of the linker errors? Thanks.
I figured it out! There are actually several shared object libraries being created when you build glib, and the one I was missing was libgthread-2.0.so.
I added libgthread-2.0.so to my LOCAL_LDLIBS and it worked
I am using build_native.py to build to Android platform, but it says
"fatal error: fatal error:'cocos2d.h' file not found".
Before this problem it says can't import import module and I set NDK_MODULD_PATH in environment variable to fix it I don't know if this cause this problem.
In file included from jni/hellocpp/main.cppIn file included from
jni/../../Class
es/AppDelegate.cppIn file included from jni/../../Classes/GameOverScene.cpp:1:
::jni/../../Classes/GameOverScene.h1:
:4:10: jni/../../Classes/AppDelegate.hfatal error: :4'cocos2d.h' file not found1
:
In file included from #include "cocos2d.h"
this is my Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
$(call import-add-path,$(LOCAL_PATH)/../../cocos2d)
$(call import-add-path,$(LOCAL_PATH)/../../cocos2d/external)
$(call import-add-path,$(LOCAL_PATH)/../../cocos2d/cocos)
LOCAL_MODULE := cocos2dcpp_shared
LOCAL_MODULE_FILENAME := libcocos2dcpp
LOCAL_SRC_FILES := hellocpp/main.cpp \
../../Classes/AppDelegate.cpp \
../../Classes/Adapter.cpp \
../../Classes/ControlLayer.cpp \
../../Classes/GameOverScene.cpp \
../../Classes/GameRunScene.cpp \
../../Classes/GameStartScene.cpp \
../../Classes/SceneManager.cpp \
../../Classes/HelloWorldScene.cpp
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../cocos2d/cocos/physics
LOCAL_C_INCLUDES += $(LOCAL_PATH)/../../Classes
LOCAL_C_INCLUDES += $(LOCAL_PATH)/../../libcocos2d
LOCAL_STATIC_LIBRARIES := cocos2dx_static
LOCAL_STATIC_LIBRARIES := cocos2dx_extension_static
LOCAL_LDLIBS += -L$(call host-path,$(NDK_ROOT)/sources/cxx-stl/llvm-libc++/libs/$(TARGET_ARCH_ABI)) -lc++_static
include $(BUILD_SHARED_LIBRARY)
$(call import-module,./prebuilt-mk)
In this situation, most error comes from wrong Path setting of NDK_MODULD_PATH. I once met this error when using Cocos2d-x 2.2.6. And I suggest you checking the path of NDK_MODULE_PATH again to set it to
${COCOS2DX_ROOT}/cocos2dx/platform/third_party/android/source;${COCOS2DX_ROOT}/cocos2dx/platform/third_party/android/prebuilt
replace ${COCOS2DX_ROOT} to your own path. You can also check this article, although it is talking about Cocos2d-x 2.x.
I miss this error also when I use cocos2d-x-3.7.My solution is at jni/Android.mk set:
LOCAL_STATIC_LIBRARIES := cocos2d_lua_static
see more at this FixBug
I have an android project written using the Android NDK. Within the project, I am using two prebuilt shared libraries(GpkgSDK and spatialite) and building two more shared libraries(WFSHelpers and com_example_gpkgviewer_jni_WKTConverter). The only library that interacts with the Java level of the application is the com_example_gpkgviewer_jni_WKTConverter library.
The dependencies between the libraries are shown below:
WFSHelpers is dependent on GpkgSDK and spatialite
com_example_gpkgviewer_jni_WKTConverter is dependent on WFSHelpers
The issue that I am having is that when I try to run ndk-build, I am getting a lot of undefined references when attempting to build the com_example_gpkgviewer_jni_WKTConverter library. The other libraries are successfully built. The way I would normally resolve these undefined references is by including the following in my com_example_gpkgviewer_jni_WKTConverter module definition :
LOCAL_SHARED_LIBRARY := WFSHelpers
I am unsure as to whether I would also need to include the libraries that the WFSHelpers is dependent on like so:
LOCAL_SHARED_LIBRARY := WFSHelpers GpkgSDK spatialite
I have also tried them in a different order like so but it does not seem to resolve my issue:
LOCAL_SHARED_LIBRARY := GpkgSDK spatialite WFSHelpers
My Application.mk is included below:
NDK_TOOLCHAIN_VERSION := 4.8
# APP_STL := stlport_shared --> does not seem to contain C++11 features
APP_STL := gnustl_shared
# Enable c++11 extentions in source code
APP_CPPFLAGS += -std=c++11
APP_CPPFLAGS += -frtti
APP_CPPFLAGS += -fexceptions
APP_MODULES := GpkgSDK spatialite WFSHelpers com_example_gpkgviewer_jni_WKTConverter
APP_ABI := armeabi armeabi-v7a
My Android.mk is shown below:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := GpkgSDK
LOCAL_SRC_FILES := libMP.so
LOCAL_EXPORT_C_INCLUDES := \
$(LOCAL_PATH)/include \
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := spatialite
LOCAL_SRC_FILES := spatialamal/prebuilt/$(TARGET_ARCH_ABI)/libspatialite.so
LOCAL_EXPORT_C_INCLUDES := spatialamal/headers/spatialite \
spatialamal/headers
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := WFSHelpers
LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog
LOCAL_SRC_FILES := \
GPKGReader/Debug.h \
GPKGReader/DLLExport.h \
GPKGReader/DBQueryResult.cpp \
GPKGReader/GeoPackageDB.cpp \
GPKGReader/GPKGReader.cpp \
GPKGReader/order32.h \
GPKGReader/SpecDefinitions.h \
GPKGReader/WKBGenericGeometry.cpp \
GPKGReader/WKBLineString.cpp \
GPKGReader/WKBMultiLineString.cpp \
GPKGReader/WKBMultiPolygon.cpp \
GPKGReader/WKBPoint.cpp \
GPKGReader/WKBPolygon.cpp \
GPKGDataLayer/GPKGDataLayer.cpp
LOCAL_SHARED_LIBRARIES := GpkgSDK spatialite
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog
LOCAL_MODULE := com_example_gpkgviewer_jni_WKTConverter
LOCAL_SRC_FILES := com_example_gpkgviewer_jni_WKTConverter.cpp
LOCAL_SHARED_LIBRARY := WFSHelpers GpkgSDK spatialite
include $(BUILD_SHARED_LIBRARY)
An example of the undefined reference errors that I am getting is shown below:
[armeabi] SharedLibrary : libcom_example_gpkgviewer_jni_WKTConverter.so
jni/com_example_gpkgviewer_jni_WKTConverter.cpp:59: error: undefined reference
o 'WKBGenericGeometry::readInt32(unsigned char, unsigned char*, unsigned int)'
collect2.exe: error: ld returned 1 exit status
make.exe: *** [obj/local/armeabi/libcom_example_gpkgviewer_jni_WKTConverter.so]
Error 1
The line of code within com_example_gpkgviewer_jni_WKTConverter.cpp that causes this error is shown below:
*id_arg = WKBGenericGeometry::readInt32(byte_order, &(bytes[4]), length - 4);
Any suggestions on how I can resolve the dependencies.
After attempting to get this to build for ages, I have finally been able to get it to work. Although, I am not quite sure what the differences are, so anyone who can shed a light on this is welcome to do so. My issue was that I had dependencies on other libraries. The documentation states the following:
LOCAL_SHARED_LIBRARIES
The list of shared libraries modules this
module depends on at runtime. This is necessary at link time and to
embed the corresponding information in the generated file.
LOCAL_LDLIBS
The list of additional linker flags to be used when building your shared library or executable. This is useful to pass the
name of specific system libraries with the '-l' prefix. For example,
the following will tell the linker to generate a module that links to
/system/lib/libz.so at load time:
LOCAL_LDLIBS := -lz
See STABLE-APIS for the list of exposed system libraries you can linked against with this NDK release.
NOTE: This is ignored for static libraries, and ndk-build will print a warning if
you define it in such a module.
Thus in my Android.mk file, I had to use LOCAL_LDLIBS instead of LOCAL_SHARED_LIBRARIES to indicate the dependencies.
My new Android.mk is as shown below:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := GpkgSDK
LOCAL_SRC_FILES := libMP.so
LOCAL_EXPORT_C_INCLUDES := \
$(LOCAL_PATH)/include \
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := spatialite
LOCAL_SRC_FILES := spatialamal/prebuilt/$(TARGET_ARCH_ABI)/libspatialite.so
LOCAL_EXPORT_C_INCLUDES := spatialamal/headers/spatialite \
spatialamal/headers
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := WFSHelpers
LOCAL_SRC_FILES := \
GPKGReader/Debug.h \
GPKGReader/DLLExport.h \
GPKGReader/DBQueryResult.cpp \
GPKGReader/GeoPackageDB.cpp \
GPKGReader/GPKGReader.cpp \
GPKGReader/order32.h \
GPKGReader/SpecDefinitions.h \
GPKGReader/WKBGenericGeometry.cpp \
GPKGReader/WKBLineString.cpp \
GPKGReader/WKBMultiLineString.cpp \
GPKGReader/WKBMultiPolygon.cpp \
GPKGReader/WKBPoint.cpp \
GPKGReader/WKBPolygon.cpp \
GPKGDataLayer/GPKGDataLayer.cpp
LOCAL_LDLIBS := libs/$(TARGET_ARCH_ABI)/libGpkgSDK.so
LOCAL_LDLIBS += libs/$(TARGET_ARCH_ABI)/libspatialite.so
LOCAL_LDLIBS += -L$(SYSROOT)/usr/lib -llog
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := com_example_gpkgviewer_jni_WKTConverter
LOCAL_SRC_FILES := com_example_gpkgviewer_jni_WKTConverter.cpp
LOCAL_LDLIBS := libs/$(TARGET_ARCH_ABI)/libWFSHelpers.so
LOCAL_LDLIBS += libs/$(TARGET_ARCH_ABI)/libGpkgSDK.so
include $(BUILD_SHARED_LIBRARY)
I shall leave this answer open for a while as I am not entirely sure what the difference between LOCAL_LDLIBS and LOCAL_SHARED_LIBRARIES is. If anyone can provide me with an explanation, please do. If not, I shall mark this answer as accepted after giving it some time. Thanks !
I need to use google's protobuf in my cocos2d-x android project. I include headers and C++ files in project. But when I try to compile project via NDK, compiler return me errors:
jni/../../Classes/PromowallLibrary/protocol.pb.cpp:55: error: undefined reference to 'google::protobuf::DescriptorPool::generated_pool()'
jni/../../Classes/PromowallLibrary/protocol.pb.cpp:55: error: undefined reference to 'google::protobuf::DescriptorPool::FindFileByName(std::basic_string, std::allocator > const&) const'
jni/../../Classes/PromowallLibrary/protocol.pb.cpp:56: error: undefined reference to 'google::protobuf::internal::LogMessage::LogMessage(google::protobuf::LogLevel, char const*, int)'
and so on. How can I point to -lprotobuf library? I tried:
LOCAL_LDLIBS := -lprotobuf \ but that is doesn't work
UPDATE:
now I try to do in such way - I create static module:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libprotobuf
LOCAL_SRC_FILES := libprotobuf.a
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := game_shared
LOCAL_MODULE_FILENAME := libgame
LOCAL_CPP_EXTENSION := .cpp \
.cc
LOCAL_SRC_FILES := helloworld/main.cpp \
../../Classes/AppDelegate.cpp \
../../Classes/HelloWorldScene.cpp \
../../Classes/PromowallLibrary/protocol.pb.cc
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes \
$(LOCAL_PATH)
LOCAL_STATIC_LIBRARIES := libprotobuf
LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static cocosdenshion_static
include $(BUILD_SHARED_LIBRARY)
$(call import-module,CocosDenshion/android) $(call import-module,cocos2dx)
Now I get such kind of errors:
/home/ivan/android/android_ndk/toolchains/arm-linux-androideabi-4.6.3/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.6.3/../../../../arm-linux-androideabi/bin/ld: error: ./obj/local/armeabi/libprotobuf.a(common.o): incompatible target
/home/ivan/android/android_ndk/toolchains/arm-linux-androideabi-4.6.3/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.6.3/../../../../arm-linux-androideabi/bin/ld: error: ./obj/local/armeabi/libprotobuf.a(generated_message_util.o): incompatible target
/home/ivan/android/android_ndk/toolchains/arm-linux-androideabi-4.6.3/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.6.3/../../../../arm-linux-androideabi/bin/ld: error: ./obj/local/armeabi/libprotobuf.a(message_lite.o): incompatible target
/home/ivan/android/android_ndk/toolchains/arm-linux-androideabi-4.6.3/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.6.3/../../../../arm-linux-androideabi/bin/ld: error: ./obj/local/armeabi/libprotobuf.a(repeated_field.o): incompatible target
/home/ivan/android/android_ndk/toolchains/arm-linux-androideabi-4.6.3/prebuilt/linux-x86/bin/../lib/gcc/arm-linux-androideabi/4.6.3/../../../../arm-linux-androideabi/bin/ld: error: ./obj/local/armeabi/libprotobuf.a(wire_format_lite.o): incompatible target
I am trying to compile the project which i got from below link .
Github project fmpeg. But while compiling that to create .so files using andriod ndk version 5 i am getting the following issue . Please advice me to solve it .
make: *** No rule to make target `/cygdrive/D/Shakthi/jhotovy/jhotovy-android-ffmpeg-fab1412/Project/jni/ffmpeg/ffmpeg.c', needed by `/cygdrive/D/Shakthi/jhotovy/jhotovy-android-ffmpeg-fab1412/Project/obj/local/armeabi/objs/ffmpeg/ffmpeg/ffmpeg.o'. Stop.
My Android.mk file code.
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := ffmpeg
FFMPEG_LIBS := $(addprefix ffmpeg/, \
libavdevice/libavdevice.a \
libavformat/libavformat.a \
libavcodec/libavcodec.a \
libavfilter/libavfilter.a \
libswscale/libswscale.a \
libavutil/libavutil.a \
libpostproc/libpostproc.a )
OGG_LIBS := $(addprefix libogg/output/lib/, \
libogg.a )
VORBIS_LIBS := $(addprefix libvorbis/output/lib/, \
libvorbis.a \
libvorbisenc.a \
libvorbisfile.a )
THEORA_LIBS := $(addprefix libtheora/output/lib/, \
libtheora.a \
libtheoraenc.a \
libtheoradec.a )
LOCAL_CFLAGS += -g -Iffmpeg -Ivideokit -Wno-deprecated-declarations
LOCAL_LDLIBS += -llog -lz $(FFMPEG_LIBS) $(THEORA_LIBS) $(OGG_LIBS) x264/libx264.a
LOCAL_SRC_FILES := ffmpeg_android/ffmpeg_android.c ffmpeg/ffmpeg.c ffmpeg/cmdutils.c
include $(BUILD_SHARED_LIBRARY)
# Use to safely invoke ffmpeg multiple times from the same Activity
include $(CLEAR_VARS)
LOCAL_MODULE := ffmpeginvoke
LOCAL_SRC_FILES := ffmpeg_invoke/ffmpeg_invoke.c
LOCAL_LDLIBS := -ldl
include $(BUILD_SHARED_LIBRARY)
Did you follow the instructions in "How to build it"?