美文网首页
Android So编译错误

Android So编译错误

作者: yanlong107 | 来源:发表于2019-09-30 14:58 被阅读0次

    今天和往常一样调用脚本编译so,突然提示如下错误:

    ../../base/allocator/allocator_extension.h:17:45: error: unknown type name 'size_t'
    using AllocHookFunc = void (*)(const void*, size_t);
                                                ^
    ../../base/allocator/allocator_extension.h:28:55: error: unknown type name 'size_t'
    BASE_EXPORT bool GetNumericProperty(const char* name, size_t* value);
                                                          ^
    In file included from ../../base/allocator/allocator_extension.cc:7:
    In file included from ../../base/logging.h:11:
    In file included from ../../../../../../../tool/android-ndk-r16b/sources/cxx-stl/llvm-libc++/include/cstring:61:
    ../../../../../../../tool/android-ndk-r16b/sources/cxx-stl/llvm-libc++/include/string.h:74:64: error: use of undeclared identifier 'strchr'
    char* __libcpp_strchr(const char* __s, int __c) {return (char*)strchr(__s, __c);}
                                                                   ^
    ../../../../../../../tool/android-ndk-r16b/sources/cxx-stl/llvm-libc++/include/string.h:81:75: error: use of undeclared identifier 'strpbrk'
    char* __libcpp_strpbrk(const char* __s1, const char* __s2) {return (char*)strpbrk(__s1, __s2);}
                                                                              ^
    ../../../../../../../tool/android-ndk-r16b/sources/cxx-stl/llvm-libc++/include/string.h:88:65: error: use of undeclared identifier 'strrchr'; did you mean 'strchr'?
    char* __libcpp_strrchr(const char* __s, int __c) {return (char*)strrchr(__s, __c);}
                                                                    ^
    ../../../../../../../tool/android-ndk-r16b/sources/cxx-stl/llvm-libc++/include/string.h:76:13: note: 'strchr' declared here
    const char* strchr(const char* __s, int __c) {return __libcpp_strchr(__s, __c);}
                ^
    ../../../../../../../tool/android-ndk-r16b/sources/cxx-stl/llvm-libc++/include/string.h:95:49: error: unknown type name 'size_t'
    void* __libcpp_memchr(const void* __s, int __c, size_t __n) {return (void*)memchr(__s, __c, __n);}
                                                    ^
    ../../../../../../../tool/android-ndk-r16b/sources/cxx-stl/llvm-libc++/include/string.h:97:46: error: unknown type name 'size_t'
    const void* memchr(const void* __s, int __c, size_t __n) {return __libcpp_memchr(__s, __c, __n);}
                                                 ^
    ../../../../../../../tool/android-ndk-r16b/sources/cxx-stl/llvm-libc++/include/string.h:99:46: error: unknown type name 'size_t'
          void* memchr(      void* __s, int __c, size_t __n) {return __libcpp_memchr(__s, __c, __n);}
                                                 ^
    ../../../../../../../tool/android-ndk-r16b/sources/cxx-stl/llvm-libc++/include/string.h:102:74: error: use of undeclared identifier 'strstr'; did you mean 'strchr'?
    char* __libcpp_strstr(const char* __s1, const char* __s2) {return (char*)strstr(__s1, __s2);}
                                                                             ^
    ../../../../../../../tool/android-ndk-r16b/sources/cxx-stl/llvm-libc++/include/string.h:78:13: note: 'strchr' declared here
          char* strchr(      char* __s, int __c) {return __libcpp_strchr(__s, __c);}
                ^
    ../../../../../../../tool/android-ndk-r16b/sources/cxx-stl/llvm-libc++/include/string.h:102:74: error: no matching function for call to 'strchr'
    char* __libcpp_strstr(const char* __s1, const char* __s2) {return (char*)strstr(__s1, __s2);}
                                                                             ^
    ../../../../../../../tool/android-ndk-r16b/sources/cxx-stl/llvm-libc++/include/string.h:78:13: note: candidate disabled: <no message provided>
          char* strchr(      char* __s, int __c) {return __libcpp_strchr(__s, __c);}
                ^
    ../../../../../../../tool/android-ndk-r16b/sources/cxx-stl/llvm-libc++/include/string.h:102:81: error: cannot initialize a parameter of type 'char *' with an lvalue of type 'const char *'
    char* __libcpp_strstr(const char* __s1, const char* __s2) {return (char*)strstr(__s1, __s2);}
                                                                                    ^~~~
    ../../../../../../../tool/android-ndk-r16b/sources/cxx-stl/llvm-libc++/include/string.h:78:32: note: passing argument to parameter '__s' here
          char* strchr(      char* __s, int __c) {return __libcpp_strchr(__s, __c);}
                                   ^
    In file included from ../../base/allocator/allocator_extension.cc:7:
    In file included from ../../base/logging.h:11:
    ../../../../../../../tool/android-ndk-r16b/sources/cxx-stl/llvm-libc++/include/cstring:69:9: error: no member named 'size_t' in the global namespace
    using ::size_t;
          ~~^
    ../../../../../../../tool/android-ndk-r16b/sources/cxx-stl/llvm-libc++/include/cstring:70:9: error: no member named 'memcpy' in the global namespace; did you mean 'memchr'?
    using ::memcpy;
          ~~^
    ../../../../../../../tool/android-ndk-r16b/sources/cxx-stl/llvm-libc++/include/string.h:99:13: note: 'memchr' declared here
          void* memchr(      void* __s, int __c, size_t __n) {return __libcpp_memchr(__s, __c, __n);}
                ^
    In file included from ../../base/allocator/allocator_extension.cc:7:
    In file included from ../../base/logging.h:11:
    ../../../../../../../tool/android-ndk-r16b/sources/cxx-stl/llvm-libc++/include/cstring:71:9: error: no member named 'memmove' in the global namespace
    using ::memmove;
          ~~^
    ../../../../../../../tool/android-ndk-r16b/sources/cxx-stl/llvm-libc++/include/cstring:72:9: error: no member named 'strcpy' in the global namespace; did you mean 'strchr'?
    using ::strcpy;
          ~~^
    ../../../../../../../tool/android-ndk-r16b/sources/cxx-stl/llvm-libc++/include/string.h:76:13: note: 'strchr' declared here
    const char* strchr(const char* __s, int __c) {return __libcpp_strchr(__s, __c);}
                ^
    In file included from ../../base/allocator/allocator_extension.cc:7:
    In file included from ../../base/logging.h:11:
    ../../../../../../../tool/android-ndk-r16b/sources/cxx-stl/llvm-libc++/include/cstring:73:9: error: no member named 'strncpy' in the global namespace
    using ::strncpy;
          ~~^
    ../../../../../../../tool/android-ndk-r16b/sources/cxx-stl/llvm-libc++/include/cstring:74:9: error: no member named 'strcat' in the global namespace; did you mean 'strchr'?
    using ::strcat;
          ~~^
    ../../../../../../../tool/android-ndk-r16b/sources/cxx-stl/llvm-libc++/include/string.h:76:13: note: 'strchr' declared here
    const char* strchr(const char* __s, int __c) {return __libcpp_strchr(__s, __c);}
                ^
    In file included from ../../base/allocator/allocator_extension.cc:7:
    In file included from ../../base/logging.h:11:
    ../../../../../../../tool/android-ndk-r16b/sources/cxx-stl/llvm-libc++/include/cstring:75:9: error: no member named 'strncat' in the global namespace
    using ::strncat;
          ~~^
    ../../../../../../../tool/android-ndk-r16b/sources/cxx-stl/llvm-libc++/include/cstring:76:9: error: no member named 'memcmp' in the global namespace; did you mean 'memchr'?
    using ::memcmp;
          ~~^
    ../../../../../../../tool/android-ndk-r16b/sources/cxx-stl/llvm-libc++/include/string.h:99:13: note: 'memchr' declared here
          void* memchr(      void* __s, int __c, size_t __n) {return __libcpp_memchr(__s, __c, __n);}
                ^
    fatal error: too many errors emitted, stopping now [-ferror-limit=]
    20 errors generated.
    

    看到这些错误一脸懵逼,size_t 不是基础类型吗,怎么会找不到。
    google 一番没有任何结果,可以明确知到不是代码逻辑问题,是依赖的环境变量问题,具体的是哪个环境引起的错误,一头雾水。

    经过一番测试后找到了问题原因:
    xcode 版本升级为11.0 后, gcc 依赖的编译环境发生变化,导致编译错误。
    解决方案:
    安装一个xcode 10.2版本,重新编译后,问题消失
    tip:中间替换了ndk,sdk等版本来确定是否因为这些问题导致

    mac 中同时安装不同版本的xcode,可以使用如下命令切换主xcode

    $ sudo xcode-select -switch /Applications/Xcode.app(xcode保存的位置)
    Password:// 输入密码后就可以修改成功
    $ xcodebuild -version 
    Xcode 10.2.1
    Build version 10E1001
    $ xcode-select -p  
    /Users/Documents/tool/Xcode.app/Contents/Developer
    

    相关文章

      网友评论

          本文标题:Android So编译错误

          本文链接:https://www.haomeiwen.com/subject/tvzcpctx.html