NDK编译cpp文件出现的-Werror=format-security

文章详细介绍了如何解决Android NDK版本9及以上出现的打印日志错误,通过在Android.mk文件中添加LOCAL_DISABLE_FORMAT_STRING_CHECKS:=true来修复问题,感谢国外大神提供的解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

原文出处

最近编译的时候出现了打印日志时:
char * s = "cainiaobuhuifei";
LOGI(s);

报:error: format not a string literal and no format arguments [-Werror=format-security] 

从上面那个网站找到了解决方法为:

as of Android NDK revision 9, the following should be added to Android.mk as a work-around for the quoted error.

"LOCAL_DISABLE_FORMAT_STRING_CHECKS := true"

然后就好了,感谢国外大神。
Execution failed for task ':app:externalNativeBuildDebug'. > Build command failed. Error while executing process D:\NDK\android-sdk-windows\cmake\3.22.1\bin\ninja.exe with arguments {-C E:\desktop\MyApplication\app\.cxx\cmake\debug\armeabi-v7a myapplication} ninja: Entering directory `E:\desktop\MyApplication\app\.cxx\cmake\debug\armeabi-v7a' [1/2] Building CXX object CMakeFiles/myapplication.dir/native-lib.cpp.o FAILED: CMakeFiles/myapplication.dir/native-lib.cpp.o D:\NDK\android-sdk-windows\ndk\21.4.7075529\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=armv7-none-linux-androideabi24 --gcc-toolchain=D:/NDK/android-sdk-windows/ndk/21.4.7075529/toolchains/llvm/prebuilt/windows-x86_64 --sysroot=D:/NDK/android-sdk-windows/ndk/21.4.7075529/toolchains/llvm/prebuilt/windows-x86_64/sysroot -Dmyapplication_EXPORTS -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -march=armv7-a -mthumb -Wformat -Werror=format-security -O0 -fno-limit-debug-info -fPIC -MD -MT CMakeFiles/myapplication.dir/native-lib.cpp.o -MF CMakeFiles\myapplication.dir\native-lib.cpp.o.d -o CMakeFiles/myapplication.dir/native-lib.cpp.o -c E:/desktop/MyApplication/app/src/main/cpp/native-lib.cpp E:/desktop/MyApplication/app/src/main/cpp/native-lib.cpp:3:10: fatal error: 'opencv2/core.hpp' file not found #include <opencv2/core.hpp> ^~~~~~~~~~~~~~~~~~ 1 error generated. ninja: build stopped: subcommand failed. * Try: > Run with --stacktrace option to get the stack trace. > Run with --info or --debug option to get more log output. > Run with --scan to get full insights.
05-26
Detecting C compiler ABI info failed to compile with the following output: Change Dir: D:/java/javacode/nmmp/nmm-protect/build/.cxx/cmake/Release/armeabi-v7a/CMakeFiles/CMakeTmp Run Build Command(s):D:\Android\Cmake\cmake-3.22.2-windows-x86_64\bin\ninja cmTC_cec21 && [1/2] Building C object CMakeFiles/cmTC_cec21.dir/CMakeCCompilerABI.c.o FAILED: CMakeFiles/cmTC_cec21.dir/CMakeCCompilerABI.c.o D:\Android\AndroidNDK\android-ndk-r21e-windows-x86_64\android-ndk-r21e\toolchains\llvm\prebuilt\windows-x86_64\bin\clang.exe --target=armv7-none-linux-androideabi21 --gcc-toolchain=D:/Android/AndroidNDK/android-ndk-r21e-windows-x86_64/android-ndk-r21e/toolchains/llvm/prebuilt/windows-x86_64 --sysroot=D:/Android/AndroidNDK/android-ndk-r21e-windows-x86_64/android-ndk-r21e/toolchains/llvm/prebuilt/windows-x86_64/sysroot -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -march=armv7-a -mthumb -Wformat -fPIE -v -MD -MT CMakeFiles/cmTC_cec21.dir/CMakeCCompilerABI.c.o -MF CMakeFiles\cmTC_cec21.dir\CMakeCCompilerABI.c.o.d -o CMakeFiles/cmTC_cec21.dir/CMakeCCompilerABI.c.o -c D:/Android/Cmake/cmake-3.22.2-windows-x86_64/share/cmake-3.22/Modules/CMakeCCompilerABI.c ninja: build stopped: subcommand failed. Determining if the C compiler works failed with the following output: Change Dir: D:/java/javacode/nmmp/nmm-protect/build/.cxx/cmake/Release/armeabi-v7a/CMakeFiles/CMakeTmp Run Build Command(s):D:\Android\Cmake\cmake-3.22.2-windows-x86_64\bin\ninja cmTC_9ef40 && [1/2] Building C object CMakeFiles/cmTC_9ef40.dir/testCCompiler.c.o FAILED: CMakeFiles/cmTC_9ef40.dir/testCCompiler.c.o D:\Android\AndroidNDK\android-ndk-r21e-windows-x86_64\android-ndk-r21e\toolchains\llvm\prebuilt\windows-x86_64\bin\clang.exe --target=armv7-none-linux-androideabi21 --gcc-toolchain=D:/Android/AndroidNDK/android-ndk-r21e-windows-x86_64/android-ndk-r21e/toolchains/llvm/prebuilt/windows-x86_64 --sysroot=D:/Android/AndroidNDK/android-ndk-r21e-windows-x86_64/android-ndk-r21e/toolchains/llvm/prebuilt/windows-x86_64/sysroot -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -march=armv7-a -mthumb -Wformat -Werror=format-security -fPIE -MD -MT CMakeFiles/cmTC_9ef40.dir/testCCompiler.c.o -MF CMakeFiles\cmTC_9ef40.dir\testCCompiler.c.o.d -o CMakeFiles/cmTC_9ef40.dir/testCCompiler.c.o -c D:/java/javacode/nmmp/nmm-protect/build/.cxx/cmake/Release/armeabi-v7a/CMakeFiles/CMakeTmp/testCCompiler.c ninja: build stopped: subcommand failed.这个错误是怎么回事
最新发布
08-05
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值