When I compiled a test Android program by enabling the AddressSanitizier, I got this error:
error: undefined reference to __asan_report_load4
Does anyone know what happened here?
This is my Android.mk:
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := asan_boom.c
LOCAL_SHARED_LIBRARIES := libc
LOCAL_CFLAGS := -O1 -g -fsanitize=address -fno-omit-frame-pointer
LOCAL_MODULE := asan_boom
include $(BUILD_EXECUTABLE)
Related
I get this error while running build-ndk for my ffmpeg android project
make: *** [obj/local/armeabi-v7a/libffmpeg-test-jni.so]
undefined reference to 'av_close_input_file'
undefined reference to 'av_find_stream_info'
undefined reference to 'av_open_input_file'
undefined reference to 'avcodec_open'
Any solutions to get rid of this error ? I am very new to ffmpeg and Android NDK
This is my Android MK file
LOCAL_PATH := $(call my-dir)
#declare the prebuilt library
include $(CLEAR_VARS)
LOCAL_MODULE := ffmpeg-prebuilt
LOCAL_SRC_FILES := ffmpeg-2.5.4/android/armv7-a/libffmpeg.so
LOCAL_EXPORT_C_INCLUDES := ffmpeg-2.5.4/android/armv7-a/include
LOCAL_EXPORT_LDLIBS := ffmpeg-2.5.4/android/armv7-a/libffmpeg.so
LOCAL_LDLIBS += -llog -lavutil -lavformat -lavcodec -lz -lavutil -lm
LOCAL_PRELINK_MODULE := true
include $(PREBUILT_SHARED_LIBRARY)
#the andzop library
include $(CLEAR_VARS)
LOCAL_ALLOW_UNDEFINED_SYMBOLS=false
LOCAL_MODULE := ffmpeg-test-jni
LOCAL_SRC_FILES := ffmpeg-test-jni.c
LOCAL_C_INCLUDES := $(LOCAL_PATH)/ffmpeg-2.5.4/android/armv7-a/include
LOCAL_SHARED_LIBRARY := ffmpeg-prebuilt
LOCAL_LDLIBS := -llog -ljnigraphics -lz -lm $(LOCAL_PATH)/ffmpeg-2.5.4/android/armv7-a/libffmpeg.so
include $(BUILD_SHARED_LIBRARY)
Any Pointers much appreciated
Thanks!
Hi I would like to add protobufs to my project. So far I am only trying with android and have not been lucky so far.
I have placed my libs : libprotobuf.a , libprotobuf-lite.a, libprotoc.a in "Protobuf" folder right where "Classes" folder can be found.
I have generated one Proto named "Msg.pb.cc" and placed it in Classes folder.
I have placed the Protobuf .h files in the classes folder. i.e. Classes/google/protobuf/....
This is what my Android.mk looks right now.
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libprotoc
LOCAL_SRC_FILES := ../../Protobuf/libprotoc.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := libprotobuf-lite
LOCAL_SRC_FILES := ../../Protobuf/libprotobuf-lite.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := libprotobuf.a
LOCAL_SRC_FILES := ../../Protobuf/libprotobuf.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := cocos2dcpp_shared
LOCAL_MODULE_FILENAME := libcocos2dcpp
LOCAL_CPP_EXTENSION := .cxx .cpp .cc
LOCAL_SRC_FILES += hellocpp/main.cpp \
../../Classes/AppDelegate.cpp \
../../Classes/GameSprite.cpp \
../../Classes/GameLayer.cpp \
../../Classes/Control.cpp \
../../Classes/HelloWorldScene.cpp \
../../Classes/NativeInterface.cpp \
../../Classes/Msg.pb.cc
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes
LOCAL_WHOLE_STATIC_LIBRARIES += cocos2dx_static
LOCAL_WHOLE_STATIC_LIBRARIES += cocosdenshion_static
LOCAL_WHOLE_STATIC_LIBRARIES += box2d_static
LOCAL_WHOLE_STATIC_LIBRARIES += chipmunk_static
include $(BUILD_SHARED_LIBRARY)
$(call import-module,cocos2dx)
$(call import-module,cocos2dx/platform/third_party/android/prebuilt/libcurl)
$(call import-module,CocosDenshion/android)
$(call import-module,extensions)
$(call import-module,external/Box2D)
$(call import-module,external/chipmunk)
I get a lot of errors as soon as it compiles the Msg.pb.cc. Here's a few:
E:/Android/android-ndk-r8e/toolchains/arm-linux-androideabi-4.6/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe: ./obj/local/armeabi/objs/cocos2dcpp_shared/__/__/Classes/Msg.pb.o: in function env10us::Msg::ByteSize() const:jni/../../Classes/google/protobuf/io/coded_stream.h:1091: error: undefined reference to 'google::protobuf::io::CodedOutputStream::VarintSize32Fallback(unsigned int)'
E:/Android/android-ndk-r8e/toolchains/arm-linux-androideabi-4.6/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe: ./obj/local/armeabi/objs/cocos2dcpp_shared/__/__/Classes/Msg.pb.o: in function env10us::Msg::ByteSize() const:jni/../../Classes/google/protobuf/io/coded_stream.h:1091: error: undefined reference to 'google::protobuf::io::CodedOutputStream::VarintSize32Fallback(unsigned int)'
E:/Android/android-ndk-r8e/toolchains/arm-linux-androideabi-4.6/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld.exe: ./obj/local/armeabi/objs/cocos2dcpp_shared/__/__/Classes/Msg.pb.o: in function env10us::Msg::ByteSize() const:jni/../../Classes/google/protobuf/io/coded_stream.h:1091: error: undefined reference to 'google::protobuf::io::CodedOutputStream::VarintSize32Fallback(unsigned int)'
Somehow, I guess the files are not linked. The code is unable to find the protobuf library.
I don't know how Android.mk files are written and do not have much experience with cpp as well. This is just the result of some google searches and reading the original Android.mk file.
Any help is appreciated.
-cocos2dx-2.2.5
-eclipse+ADT.
-sdk 5.0.1
-ndk r8e
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 have tried to compile very simple code for android:
#include <iostream>
void foo()
{
}
But I get some linking errors:
/home/l/android-ndk-r7b/sources/cxx-stl/gnu-libstdc++/include/iostream:72: undefined reference to `std::ios_base::Init::Init()'
/home/l/eclipse_workspace/android_bt_test1/jni/native.cpp:33: undefined reference to `std::ios_base::Init::~Init()'
My Application.mk is:
APP_OPTIM := debug
APP_MODULES := native_lab
APP_STL := gnustl_static
My Android.mk is:
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := native_lab
LOCAL_C_INCLUDES := $(LOCAL_PATH)
LOCAL_SRC_FILES := native.cpp
LOCAL_LDLIBS := -ldl -lstdc++ -llog
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include /home/l/android-ndk-r7b/sources/cxx-stl/gnu-libstdc++/include/ /home/l/android-ndk-r7b/sources/cxx-stl/gnu-libstdc++/libs/armeabi/include
include $(BUILD_SHARED_LIBRARY)
I know this problem is very easy, but I have't found a resolution.
Could anybody help me please?
I started off creating libraries as shared libraries, but I considered it would be more efficient to create one shared libraries and the rest static. When it was all shared, it compiled and linked fine, but moving to static, I get on linking "undefined reference".
Edit: I build all the libraries in one Android.mk
Android.mk:
MY_LOCAL_PATH := $(call my-dir)
MY_LOCAL_CFLAGS := -DDEBUG
TARGET_PLATFORM := 'android-4'
LOCAL_PATH := $(MY_LOCAL_PATH)/../../Base
include $(CLEAR_VARS)
LOCAL_MODULE := Base
LOCAL_SRC_FILES := <Base src files>
include $(BUILD_STATIC_LIBRARY)
MY_LOCAL_STATIC_LIBRARIES := Base
MY_LOCAL_C_INCLUDES := $(MY_LOCAL_PATH)/../../Base
LOCAL_PATH := $(MY_LOCAL_PATH)/../../Framework
include $(CLEAR_VARS)
LOCAL_MODULE := Framework
LOCAL_C_INCLUDES := $(MY_LOCAL_C_INCLUDES)
LOCAL_SRC_FILES := <Framework src files>
LOCAL_CFLAGS := $(MY_LOCAL_CFLAGS)
include $(BUILD_STATIC_LIBRARY)
MY_LOCAL_STATIC_LIBRARIES += Framework
MY_LOCAL_C_INCLUDES += $(MY_LOCAL_PATH)/../../Framework
LOCAL_PATH := $(MY_LOCAL_PATH)/Graphics
include $(CLEAR_VARS)
LOCAL_MODULE := Graphics
LOCAL_SRC_FILES := <Graphics src files>
LOCAL_EXPORT_LDLIBS := -lGLESv1_CM
LOCAL_CFLAGS := $(MY_LOCAL_CFLAGS)
LOCAL_C_INCLUDES := $(MY_LOCAL_C_INCLUDES)
include $(BUILD_STATIC_LIBRARY)
MY_LOCAL_STATIC_LIBRARIES += Graphics
MY_LOCAL_C_INCLUDES += $(MY_LOCAL_PATH)/Graphics
LOCAL_PATH := $(MY_LOCAL_PATH)/Platform
include $(CLEAR_VARS)
LOCAL_MODULE := Platform
LOCAL_SRC_FILES := <Platform src files>
LOCAL_CFLAGS := $(MY_LOCAL_CFLAGS)
LOCAL_C_INCLUDES := $(MY_LOCAL_C_INCLUDES)
include $(BUILD_STATIC_LIBRARY)
MY_LOCAL_STATIC_LIBRARIES += Platform
MY_LOCAL_C_INCLUDES += $(MY_LOCAL_PATH)/Platform
LOCAL_PATH := $(MY_LOCAL_PATH)
include $(CLEAR_VARS)
LOCAL_MODULE := Final
LOCAL_SRC_FILES := <Final src files>
LOCAL_STATIC_LIBRARIES := $(MY_LOCAL_STATIC_LIBRARIES)
LOCAL_LDLIBS := -llog
LOCAL_CFLAGS := $(MY_LOCAL_CFLAGS)
LOCAL_C_INCLUDES := $(MY_LOCAL_C_INCLUDES)
include $(BUILD_SHARED_LIBRARY)
Last line of ndk-build V=1 -B:
SharedLibrary : libFinal.so
/Users/robbie/Library/Frameworks/Android-NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/darwin-x86/bin/arm-linux-androideabi-g++ -Wl,-soname,libFinal.so -shared --sysroot=/Users/robbie/Library/Frameworks/Android-NDK/platforms/android-4/arch-arm <object files> /Users/robbie/Documents/Apps/Revolution/Android/obj/local/armeabi/libBase.a /Users/robbie/Documents/Apps/Revolution/Android/obj/local/armeabi/libFramework.a /Users/robbie/Documents/Apps/Revolution/Android/obj/local/armeabi/libGraphics.a /Users/robbie/Documents/Apps/Revolution/Android/obj/local/armeabi/libPlatform.a /Users/robbie/Documents/Apps/Revolution/Android/obj/local/armeabi/libstdc++.a /Users/robbie/Library/Frameworks/Android-NDK/platforms/android-4/arch-arm/usr/lib/libc.so /Users/robbie/Library/Frameworks/Android-NDK/platforms/android-4/arch-arm/usr/lib/libstdc++.so /Users/robbie/Library/Frameworks/Android-NDK/platforms/android-4/arch-arm/usr/lib/libm.so -Wl,--no-undefined -Wl,-z,noexecstack -L/Users/robbie/Library/Frameworks/Android-NDK/platforms/android-4/arch-arm/usr/lib -llog -lGLESv1_CM -lstdc++ -Wl,-rpath-link=/Users/robbie/Library/Frameworks/Android-NDK/platforms/android-4/arch-arm/usr/lib -lsupc++ -o /Users/robbie/Documents/Apps/Revolution/Android/obj/local/armeabi/libFinal.so
/Users/robbie/Documents/Apps/Revolution/Android/obj/local/armeabi/libPlatform.a(ATexture.o): In function `ATexture':
/Users/robbie/Documents/Apps/Revolution/Android/jni/SpinTap/ATexture.cpp:9: undefined reference to `TextureRenderer::TextureRenderer(unsigned int)'
/Users/robbie/Documents/Apps/Revolution/Android/jni/SpinTap/ATexture.cpp:9: undefined reference to `TextureRenderer::TextureRenderer(unsigned int)'
Edit2: TextureRenderer is in Graphics, which is included.
Does anyone have an idea why it may not be working and how to fix it?
This looks like an order-of-linking issue to me.
Your command line is:
arm-linux-androideabi-g++ -Wl,-soname,libFinal.so -shared \
libBase.a libFramework.a libGraphics.a libPlatform.a -o libFinal.so
and the error is
libPlatform.a(ATexture.o): In function `ATexture':
ATexture.cpp:9: undefined reference to `TextureRenderer'
ATexture.cpp:9: undefined reference to `TextureRenderer'
TextureRenderer is in Graphics. But libGraphics is before libPlatform on the command line. g++ will search each library on the command line in the order they are given, loading functions to resolve external references. It will read libGraphics once, load the functions that resolve external references and move on to libPlatform.
Try changing LOCAL_STATIC_LIBRARIES := $(MY_LOCAL_STATIC_LIBRARIES) to LOCAL_STATIC_LIBRARIES := Platform Graphics Framework Base and see how you get on.
In your Android.mk, make sure you are referencing the static library with the proper call:
LOCAL_STATIC_LIBRARIES := mystaticlibproj
before calling include $(BUILD_SHARED_LIBRARY).
Then, at the end of the file, place the call to import the static lib module
$(call import-module, mystaticlibproj)
If you're still having trouble, post the verbose build log (ndk-build V=1 -B) and your Android.mk