My C/C ++ program can be compiled to ZTE and run on the beacon set-top box. I thought it would be a simple task to compile it to Android, but it is far more complicated than I think.
In my program. c file and. CPP file, where. the STL string is used in the CPP file. After compilation, the STD: String library cannot be linked. The error undefined reference to 'std: basic_string is returned.
It took two days to compile the stlport library, but ended in failure. The error is as follows:
[Root @ localhost JNI] #/home/android-ndk-r6b/ndk-build
Compile ++ thumb: stlport_shared <= dll_main.cpp
In File sorted ded from/home/android-ndk-r6b/samples/STLport-5.2.1/JNI/stlport/STL/_ stdexcept_base.h: 25,
From/home/android-ndk-r6b/samples/STLport-5.2.1/JNI/stlport/STL/_ ios_base.h: 22,
From/home/android-ndk-r6b/samples/STLport-5.2.1/JNI/stlport/STL/_ Ios. h: 23,
From/home/android-ndk-r6b/samples/STLport-5.2.1/JNI/stlport/STL/_ ostream. h: 24,
From/home/android-ndk-r6b/samples/STLport-5.2.1/JNI/stlport/STL/_ string_io.h: 23,
From/home/android-ndk-r6b/samples/STLport-5.2.1/JNI/stlport/string: 37,
From/home/android-ndk-r6b/samples/STLport-5.2.1/JNI/src/dll_main.cpp: 49:
/Home/android-ndk-r6b/samples/STLport-5.2.1/JNI/stlport/STL/_ exception. h: 56: 34: Error: exception: no such file or directory
Compile the android SDK of stlport. the contents of the MK file are listed as follows. I don't know why the above error is reported. I didn't find a solution. If any hero finds the cause and compiled stlport, I hope to thank you for your help.
LOCAL_PATH := $(call my-dir)include $(CLEAR_VARS)libstlport_path := $(call my-dir)libstlport_src_files := \ src/dll_main.cpp \ src/fstream.cpp \ src/strstream.cpp \ src/sstream.cpp \ src/ios.cpp \ src/stdio_streambuf.cpp \ src/istream.cpp \ src/ostream.cpp \ src/iostream.cpp \ src/codecvt.cpp \ src/collate.cpp \ src/ctype.cpp \ src/monetary.cpp \ src/num_get.cpp \ src/num_put.cpp \ src/num_get_float.cpp \ src/num_put_float.cpp \ src/numpunct.cpp \ src/time_facets.cpp \ src/messages.cpp \ src/locale.cpp \ src/locale_impl.cpp \ src/locale_catalog.cpp \ src/facets_byname.cpp \ src/complex.cpp \ src/complex_io.cpp \ src/complex_trig.cpp \ src/string.cpp \ src/bitset.cpp \ src/allocators.cpp \ src/c_locale.c \ src/cxa.c \libstlport_cflags := -D_GNU_SOURCElibstlport_cppflags := -fuse-cxa-atexitlibstlport_c_includes := $(libstlport_path) \ $(libstlport_path)/stlport /home/android-ndk-r6b/samples/STLport-5.2.1/jni \ /home/android-ndk-r6b/samples/STLport-5.2.1/jni/stlport \ /home/android-ndk-r6b/samples/STLport-5.2.1/jni/stlport/stlLOCAL_MODULE := stlport_staticLOCAL_SRC_FILES := $(libstlport_src_files)LOCAL_CFLAGS := $(libstlport_cflags)LOCAL_CPPFLAGS := $(libstlport_cppflags)LOCAL_C_INCLUDES := $(libstlport_c_includes)LOCAL_EXPORT_C_INCLUDES := $(LOCAL_C_INCLUDES)include $(BUILD_STATIC_LIBRARY)include $(CLEAR_VARS)LOCAL_MODULE := stlport_sharedLOCAL_SRC_FILES := $(libstlport_src_files)LOCAL_CFLAGS := $(libstlport_cflags)LOCAL_CPPFLAGS := $(libstlport_cppflags)LOCAL_C_INCLUDES := $(libstlport_c_includes)LOCAL_EXPORT_C_INCLUDES := $(LOCAL_C_INCLUDES)include $(BUILD_SHARED_LIBRARY)
Stlport compilation failed. I had to find another solution, and finally found the problem. After modifying the. c file suffix to. CPP, the problem was solved.
The android. mk file of my application is as follows:
LOCAL_PATH := $(call my-dir)include $(CLEAR_VARS)LOCAL_MODULE := cloudstore_MTDLOCAL_SRC_FILES := debug.cpp hash.cpp listex.cpp md5.cpp main.cpp http_fetcher.cpp spthreadpool.cpp storex.cpp markup.cpp fusex.cppLOCAL_C_INCLUDES := /home/android-ndk-r6b/samples/fuse-android/jni/include \ /home/android-ndk-r6b/samples/sqlite-android/jni# /home/android-ndk-r6b/platforms/android-9/arch-arm/usr/include \# /home/android-ndk-r6b/sources/cxx-stl/gnu-libstdc++/include \# /home/android-ndk-r6b/samples/fuse-android/jni/include $(INCDIR)LOCAL_CFLAGS := -Wall -lulockmgr -pipe -D_FILE_OFFSET_BITS=64 -D_DEBUG -DANDROID_SDK -DUSE_OPEN -DUSE_THREAD -DDEBUG -O2INCLIB := /home/android-ndk-r6b/samplesLOCAL_LDLIBS := $(INCLIB)/fuse-android/obj/local/armeabi/libfuse.a \ $(INCLIB)/libiconv/obj/local/armeabi/libiconv.a \ $(INCLIB)/sqlite-android/obj/local/armeabi/libsqlite3.ainclude $(BUILD_EXECUTABLE)
My application uses STL, So I need an application. mk file with the following content:
APP_CFLAGS += -fexceptionsAPP_STL := gnustl_static
In addition, because the library libiconv. A is required for my application, but Android does not support it, I downloaded the libiconv source code to compile it through ndk.
The android. mk file for compiling libiconv is as follows:
LOCAL_PATH:= $(call my-dir)# first lib, which will be built staticallyinclude $(CLEAR_VARS)LOCAL_MODULE := iconvLOCAL_SRC_FILES := libcharset/lib/localcharset.c lib/iconv.c lib/relocatable.cLOCAL_C_INCLUDES := include lib libcharset/includeLOCAL_CFLAGS := -Wno-multichar -D_ANDROID -DLIBDIR="c" -DBUILDING_LIBICONV -DIN_LIBRARY#LOCAL_PRELINK_MODULE := falseinclude $(BUILD_STATIC_LIBRARY)
The content of the application. mk file for compiling libiconv is as follows:
APP_MODULES := libiconv
At this point, the application compilation is complete, and you can debug it on the Android platform. I hope there will be no problems.