Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> android4.0編譯錯誤集(一)

android4.0編譯錯誤集(一)

編輯:關於Android編程

1、Android library 'XXX.so' not in prelink map 錯誤解決
在編譯自己的Android library時可能會出現
library 'XXX.so' not in prelink map 錯誤,
這是由於Android的預編譯設置引起的,/build/core/prelink-linux-arm.map文件描述了預編譯的模塊


需要修改所在文件夾下的android.mk文件
增加
LOCAL_PRELINK_MODULE := false
將預編譯關閉,即可通過。


2、錯誤一:error: ‘ptrdiff_t’ does not name a type
In file included from external/gtest/src/../include/gtest/gtest-param-test.h:157:0,
                 from external/gtest/src/../include/gtest/gtest.h:69,
                 from external/gtest/src/gtest_main.cc:32:
external/gtest/src/../include/gtest/internal/gtest-param-util.h:122:11: error: ‘ptrdiff_t’ does not name a type
In file included from external/gtest/src/../include/gtest/gtest-param-test.h:157:0,
                 from external/gtest/src/../include/gtest/gtest.h:69,
                 from external/gtest/src/../src/gtest.cc:34,
                 from external/gtest/src/gtest-all.cc:36:
external/gtest/src/../include/gtest/internal/gtest-param-util.h:122:11: error: ‘ptrdiff_t’ does not name a type
In file included from external/gtest/src/gtest-all.cc:38:0:
解決方法:
$vi external/gtest/src/../include/gtest/internal/gtest-param-util.h
#include <cstddef>


3.錯誤二:undefined reference to `pthread_mutexattr_destroy'
host C++: libgtest_host <= external/gtest/src/gtest-all.cc
true
host C++: libgtest_main_host <= external/gtest/src/gtest_main.cc
out/host/linux-x86/obj/STATIC_LIBRARIES/libLLVMSupport_intermediates/libLLVMSupport.a(Signals.o): In function `PrintStackTrace':
/home/aa/project/android4.0.1/external/llvm/lib/Support/Unix/Signals.inc:219: undefined reference to `dladdr'
/home/aa/project/android4.0.1/external/llvm/lib/Support/Unix/Signals.inc:231: undefined reference to `dladdr'
out/host/linux-x86/obj/STATIC_LIBRARIES/libLLVMSupport_intermediates/libLLVMSupport.a(Threading.o): In function `llvm::llvm_execute_on_thread(void (*)(void*), void*, unsigned int)':
/home/aa/project/android4.0.1/external/llvm/lib/Support/Threading.cpp:96: undefined reference to `pthread_create'
/home/aa/project/android4.0.1/external/llvm/lib/Support/Threading.cpp:91: undefined reference to `pthread_attr_setstacksize'
/home/aa/project/android4.0.1/external/llvm/lib/Support/Threading.cpp:100: undefined reference to `pthread_join'
out/host/linux-x86/obj/STATIC_LIBRARIES/libLLVMSupport_intermediates/libLLVMSupport.a(Mutex.o): In function `MutexImpl':
/home/aa/project/android4.0.1/external/llvm/lib/Support/Mutex.cpp:69: undefined reference to `pthread_mutexattr_init'
/home/aa/project/android4.0.1/external/llvm/lib/Support/Mutex.cpp:75: undefined reference to `pthread_mutexattr_settype'
/home/aa/project/android4.0.1/external/llvm/lib/Support/Mutex.cpp:80: undefined reference to `pthread_mutexattr_setpshared'
/home/aa/project/android4.0.1/external/llvm/lib/Support/Mutex.cpp:89: undefined reference to `pthread_mutexattr_destroy'
out/host/linux-x86/obj/STATIC_LIBRARIES/libLLVMSupport_intermediates/libLLVMSupport.a(Mutex.o): In function `llvm::sys::MutexImpl::tryacquire()':
/home/aa/project/android4.0.1/external/llvm/lib/Support/Mutex.cpp:143: undefined reference to `pthread_mutex_trylock'
collect2: ld returned 1 exit status
make: *** [out/host/linux-x86/obj/EXECUTABLES/test-librsloader_intermediates/test-librsloader] Error 1
make: *** Waiting for unfinished jobs....
解決方法:
$vi external/llvm/llvm-host-build.mk
LOCAL_LDLIBS := -lpthread -ldl


下面這個解決方法沒成功,會有新的錯誤:errors again :can't find threads.h file or dir.
$ vi external/llvm/lib/Support/Android.mk
LOCAL_C_INCLUDES += system/core/include/cutils
LOCAL_SHARED_LIBRARIES := libcutil
$ vi external/llvm/lib/Support/Mutex.cpp
#include <threads.h>
$ vi external/llvm/lib/Support/Threading.cpp
#include <threads.h>


4.錯誤三:error: variable ‘ParamName’ set but not used [-Werror=unused-but-set-variable]
frameworks/compile/slang/slang_rs_export_foreach.cpp:247:23: error: variable ‘ParamName’ set but not used [-Werror=unused-but-set-variable]
cc1plus: all warnings being treated as errors
解決方法:
$ vi frameworks/compile/slang/Android.mk
#local_cflags_for_slang := -Wno-sign-promo -Wall -Wno-unused-parameter -Werror
local_cflags_for_slang := -Wno-sign-promo -Wall -Wno-unused-parameter


5、2.3以上系統使用JDK1.6,所以必須下載並設定其編譯環境
vi ~/.bashrc


export JAVA_HOME=/usr/java/jdk1.6.0_23
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export PATH=$PATH:$JAVA_HOME/bin:$JAVA_HOME/bin/tools.jar:$JRE_HOME/bin
export ANDROID_JAVA_HOME=$JAVA_HOME


6、Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
解決:
內存不足


7、external/jsilver/src/com/google/streamhtmlparser/util/JavascriptTokenBuffer.java:80: cannot find symbol
symbol  : method copyOf(char[],int)
解決:
把sdk從1.5升級到1.6


8、arm-eabi-4.4.3 version `GLIBC_2.11' not found
解決方法
prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/arm-eabi-gcc -mthumb-interwork -Ibionic/libc/private -o out/target/product/generic/obj/lib/crtbegin_dynamic.o -c bionic/libc/arch-arm/bionic/crtbegin_dynamic.S
prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/arm-eabi-gcc: /lib/tls/i686/cmov/libc.so.6: version `GLIBC_2.11' not found (required by prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/arm-eabi-gcc)
make: *** [out/target/product/generic/obj/lib/crtbegin_dynamic.o] 錯誤 1


這是在32位Ubuntu上編譯引起的arm-eabi-4.4.3版本問題,所以需要修改arm-eabi-4.4.0:
$ mv arm-eabi-4.4.3 to arm-eabi-4.4.3.old
$ ln -s arm-eabi-4.4.0 arm-eabi-4.4.3


or:
升級glibc或者系統


9、
PassFailButtons.java:191: onCreateDialog(int,android.os.Bundle) in android.app.Activity cannot implement onCreateDialog(int,android.os.Bundle) in com.android.cts.verifier.PassFailButtons.PassFailActivity; attempting to assign weaker access privileges;
解決:
很可能是因為使用了openjdk,而非sun-java6-jdk,

 


10、
undefined reference to  __asprintf_chk
解決:
可能會由於stdio2.h導致編譯錯誤。正確的stdio2.h是./prebuilt/linux-x86/toolchain/i686-linux-glibc2.7-4.4.3/sysroot/usr/bits/stdio2.h文件,請重新設置PATH環境變量,將./prebuilt/linux-x86/toolchain/i686-linux-glibc2.7-4.4.3/sysroot/usr放在PATH的最前。
cp ./prebuilt/linux-x86/ toolchain/i686-unknown-linux-gnu-4.2.1/lib/libbfd.a ./out/host/linux-
x86/obj/STATIC_LIBRARIES/libbfd_intermediates/libbfd.a
可能 glibc版本不是最新的


11、
SDL init failure, reason is: No available video device .
解決:
原因是他依賴X11,可以進入圖形化界面來運行。


12、
In file included from frameworks/base/include/utils/Vector.h:26,
                 from frameworks/base/include/utils/SortedVector.h:24,
                 from frameworks/base/include/utils/KeyedVector.h:24,
                 from frameworks/base/include/media/AudioParameter.h:21,
                 from frameworks/base/media/libmedia/AudioParameter.cpp:22:
frameworks/base/include/utils/TypeHelpers.h:33: error: template with C linkage
解決:
將definitionss.mk 文件中transform-cpp-to-o -isystem 改為 -I  如果有 -isystem好像其指定的目錄
會當作標准系統庫目錄
後面又出現類似問題,干脆將這個文件中所有的-isystem都改成了-I


13、
external/icu4c/common/rbbi.cpp:295: error: cannot use typeid with -fno-rtti
external/icu4c/common/rbbi.cpp:295: error: cannot use typeid with -fno-rtti
解決:
去掉definitionss.mk 文件中 define transform-cpp-to-o 中的-fno-rtti \  行


16、
abi/cpp/include/cxxabi.h:44: error: invalid use of incomplete type 'struct std::type_info'
<built-in>:0: error: forward declaration of 'struct std::type_info'
abi/cpp/include/cxxabi.h:51: error: invalid use of incomplete type 'struct std::type_info'
<built-in>:0: error: forward declaration of 'struct std::type_info'
abi/cpp/include/cxxabi.h:58: error: invalid use of incomplete type 'struct std::type_info'
<built-in>:0: error: forward declaration of 'struct std::type_info'
abi/cpp/include/cxxabi.h:65: error: invalid use of incomplete type 'struct std::type_info'
<built-in>:0: error: forward declaration of 'struct std::type_info'
abi/cpp/include/cxxabi.h:72: error: invalid use of incomplete type 'struct std::type_info'
<built-in>:0: error: forward declaration of 'struct std::type_info'
解決:
4.0比2.3根目錄下多了abi目錄,裡面只有幾個文件,type_info在該目錄下typeinfo文件中定義了,
cxxabi.h也包含了這個文件,但不知道為什麼報錯,在cxxabi.h中添加class type_info 也不行,
後來把typeinfo文件和cxxabi.h中的定義都抽出,定義到一個common.h文件中,兩個文件都包含這個文件,暫時規避了這個問題。


14、
ake:進入目錄'/home/lijj/android/android-4.0.1'
target thumb C++: binderAddInts <= system/extras/tests/binder/benchmarks/binderAddInts.cpp
system/extras/tests/binder/benchmarks/binderAddInts.cpp:96: error: ISO C++ forbids declaration of 'cpu_set_t' with no type
system/extras/tests/binder/benchmarks/binderAddInts.cpp:96: error: expected ',' or '...' before '&' token
system/extras/tests/binder/benchmarks/binderAddInts.cpp: In function 'int main(int, char**)':
解決:
在binderAddInts.cpp文件開頭添加
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
並包含頭文件#include <sched.h>


15、
prebuilt/linux-x86/toolchain/arm-eabi-4.4.0_hisi/bin/arm-eabi-gcc -mthumb-interwork -Ibionic/libc/private -DCRT_LEGACY_WORKAROUND -Ibionic/libc/private -o out/target/product/generic/obj/lib/crtbegin_so.o -c bionic/libc/arch-arm/bionic/crtbegin_so.S
prebuilt/linux-x86/toolchain/arm-eabi-4.4.0_hisi/bin/arm-eabi-gcc -mthumb-interwork -Ibionic/libc/private -DCRT_LEGACY_WORKAROUND -Ibionic/libc/private -o out/target/product/generic/obj/lib/crtend_so.o -c bionic/libc/arch-arm/bionic/crtend_so.S
target SharedLib: libdl (out/target/product/generic/obj/SHARED_LIBRARIES/libdl_intermediates/LINKED/libdl.so)
/home/lijj/android/android-4.0.1/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0_hisi/bin/../lib/gcc/arm-eabi/4.4.0/../../../../arm-eabi/bin/ld: unrecognized option '--icf=safe'
/home/lijj/android/android-4.0.1/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0_hisi/bin/../lib/gcc/arm-eabi/4.4.0/../../../../arm-eabi/bin/ld: use the --help option for usage information
collect2: ld returned 1 exit status
解決:
修改TARGET_linux-arm.mk中P134行對TARGET_GLOBAL_LDFLAGS的賦值,去掉--icf=safe


16、
In file included from frameworks/base/media/libstagefright/AACWriter.cpp:21:
frameworks/base/include/media/stagefright/AACWriter.h:70: error: ISO C++ forbids declaration of 'DISALLOW_EVIL_CONSTRUCTORS' with no type
make: *** [out/target/product/generic/obj/SHARED_LIBRARIES/libstagefright_intermediates/AACWriter.o] 錯誤 1
解決:
添加包含頭文件#include <media/stagefright/foundation/ABase.h>


17、
In file included from frameworks/base/media/libstagefright/SurfaceMediaSource.cpp:19:
frameworks/base/include/media/stagefright/SurfaceMediaSource.h:363: error: ISO C++ forbids declaration of 'DISALLOW_IMPLICIT_CONSTRUCTORS' with no type
frameworks/base/include/media/stagefright/SurfaceMediaSource.h: In member function 'virtual android::status_t android::SurfaceMediaSource::setScalingMode(int)':
frameworks/base/include/media/stagefright/SurfaceMediaSource.h:114: error: no return statement in function returning non-void
make: *** [out/target/product/generic/obj/SHARED_LIBRARIES/libstagefright_intermediates/SurfaceMediaSource.o] 錯誤 1
make: *** 正在等待未完成的任務....
解決:
將DISALLOW_IMPLICIT_CONSTRUCTORS 改為SurfaceMediaSource( );
這個宏的作用好像就是定義構造函數,在frameworks目錄下沒有找到該宏的定義,且只看到這一個地方用到了這個宏
external目錄有這個宏的定義


18、
In file included from frameworks/base/media/libstagefright/SurfaceMediaSource.cpp:19:
frameworks/base/include/media/stagefright/SurfaceMediaSource.h: In member function 'virtual android::status_t android::SurfaceMediaSource::setScalingMode(int)':
frameworks/base/include/media/stagefright/SurfaceMediaSource.h:114: error: no return statement in function returning non-void
make: *** [out/target/product/generic/obj/SHARED_LIBRARIES/libstagefright_intermediates/SurfaceMediaSource.o] 錯誤 1
make: *** 正在等待未完成的任務....
解決:
setScalingMode函數添加return OK;


19、
external/ipsec-tools/src/racoon/isakmp.c: In function 'isakmp_handler':
external/ipsec-tools/src/racoon/isakmp.c:214: error: field 'ip' has incomplete type
external/ipsec-tools/src/racoon/isakmp.c:230: warning: pointer targets in passing argument 6 of 'recvfromto' differ in signedness
external/ipsec-tools/src/racoon/sockmisc.h:68: note: expected 'socklen_t *' but argument is of type 'unsigned int *'
解決:
參照2.3裡面在isakmp.c前面 添加
#ifdef ANDROID_CHANGES
#define __linux
#endif
這個文件2.3和4.0裡面有了蠻多變化,不知道這麼改會不會有問題


20、
target arm C: libwebrtc_aecm <= external/webrtc/src/modules/audio_processing/aecm/main/source/aecm_core.c
/tmp/ccyInhhH.s: Assembler messages:
/tmp/ccyInhhH.s:3864: Error: co-processor offset out of range
/tmp/ccyInhhH.s:3865: Error: co-processor offset out of range
解決:
對比2.3,修改TARGET_linux-arm.mk相關編譯選項

 


21、
/home/lijj/android/android-4.0.1/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0_hisi/bin/../lib/gcc/arm-eabi/4.4.0/../../../../arm-eabi/bin/ld: unrecognized option '--icf=none'
/home/lijj/android/android-4.0.1/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0_hisi/bin/../lib/gcc/arm-eabi/4.4.0/../../../../arm-eabi/bin/ld: use the --help option for usage information
collect2: ld returned 1 exit status
make: *** [out/target/product/generic/obj/SHARED_LIBRARIES/libdynamic_annotations_intermediates/LINKED/libdynamic_annotations.so] 錯誤 1
make: *** 正在等待未完成的任務....
解決:
以下幾個文件去掉--icf=none
/external/valgrind/dynamic_annotations/Android.mk:27:  LOCAL_LDFLAGS += -Wl,--icf=none
./external/valgrind/tsan/Android.mk:49:  preload_ldflags += -Wl,--icf=none
./external/valgrind/main/Android.mk:52:  preload_ldflags += -Wl,--icf=none


22、
frameworks/base/native/include/android/native_window.h:36: error: redefinition of typedef 'ANativeWindow'
system/core/include/system/window.h:429: note: previous declaration of 'ANativeWindow' was here
make: *** [out/target/product/generic/obj/SHARED_LIBRARIES/libEGL_VIVANTE_intermediates/driver/openGL/egl/os/gc_egl_linux.o] 錯誤 1
make: *** 正在等待未完成的任務....
解決:
android_natives.h中包含了兩個頭文件
#include <system/window.h>www.2cto.com
#include <android/native_window.h>

這兩個頭文件中都定義了ANativeWindow 去掉了下面個頭文件

 


 


作者:andyhuabing
  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved