wangzhaode / mnn-llm

llm deploy project based mnn.
Apache License 2.0
1.46k stars 159 forks source link

fix compilation error on Android #148

Closed windmaple closed 9 months ago

windmaple commented 9 months ago

without static cast, compiler throws this error when cross-compiling for Android on both Mac and Linux:

Build command failed. Error while executing process /Users/windmaple/Library/Android/sdk/cmake/3.10.2.4988404/bin/ninja with arguments {-C /Users/windmaple/Desktop/project-src/mnn-llm/android/app/.cxx/cmake/debug/arm64-v8a llm_mnn} ninja: Entering directory `/Users/windmaple/Desktop/project-src/mnn-llm/android/app/.cxx/cmake/debug/arm64-v8a' [1/3] Building CXX object CMakeFiles/llm_mnn.dir/llm_mnn_jni.cpp.o [2/3] Building CXX object CMakeFiles/llm_mnn.dir/Users/windmaple/Desktop/project-src/mnn-llm/src/llm.cpp.o FAILED: CMakeFiles/llm_mnn.dir/Users/windmaple/Desktop/project-src/mnn-llm/src/llm.cpp.o /Users/windmaple/Library/Android/sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ --target=aarch64-none-linux-android21 --gcc-toolchain=/Users/windmaple/Library/Android/sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/darwin-x86_64 --sysroot=/Users/windmaple/Library/Android/sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/darwin-x86_64/sysroot -DUSING_DISK_EMBED -Dllm_mnn_EXPORTS -I/Users/windmaple/Desktop/project-src/mnn-llm/android/app/src/main/jni/../../../../../include -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -O0 -fno-limit-debug-info -fPIC -MD -MT CMakeFiles/llm_mnn.dir/Users/windmaple/Desktop/project-src/mnn-llm/src/llm.cpp.o -MF CMakeFiles/llm_mnn.dir/Users/windmaple/Desktop/project-src/mnn-llm/src/llm.cpp.o.d -o CMakeFiles/llm_mnn.dir/Users/windmaple/Desktop/project-src/mnn-llm/src/llm.cpp.o -c /Users/windmaple/Desktop/project-src/mnn-llm/src/llm.cpp /Users/windmaple/Desktop/project-src/mnn-llm/src/llm.cpp:812:46: error: non-constant-expression cannot be narrowed from type 'std::ndk1::basic_string<char, std::__ndk1::char_traits, std::ndk1::allocator >::size_type' (aka 'unsigned long') to 'int' in initializer list [-Wc++11-narrowing] auto text_var = _Const(text.data(), {text.size()}, NHWC, halide_type_of()); ^~~ /Users/windmaple/Desktop/project-src/mnn-llm/src/llm.cpp:812:46: note: insert an explicit cast to silence this issue auto text_var = _Const(text.data(), {text.size()}, NHWC, halide_type_of()); ^~~ static_cast( ) 1 error generated. ninja: build stopped: subcommand failed.