在 VS 中创建 Visual C++ –> Cross Platform –> Android | Linux –> Makefile Project 后,只是在项目中有这样一段代码:
LOGD("data length error: %d", datalen);
便宜的时候就会报错,
1>------ Build started: Project: Project14, Configuration: Debug Win32 ------
1>====
1>make: Entering directory `C:/workspace/ndkTest/ndk-build/TestCC/jni'
1>[arm64-v8a] Compile : testtime <= timetest.c
1>C:/workspace/ndkTest/ndk-build/TestCC/jni/./timetest.c(16,2): warning G5552ABC2: incompatible integer to pointer conversion passing 'int' to parameter of type 'const char *' [-Wint-conversion]
1>EXEC : LOGD("data length error : %d", datalen);
1> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1>C:/workspace/ndkTest/ndk-build/TestCC/jni/./timetest.c:10:26: note: expanded from macro 'LOGD'
1>#define LOGD(...) printf(ANDROID_LOG_DEBUG,LOG_TAG ,__VA_ARGS__);
1> ^~~~~~~~~~~~~~~~~
1>C:/workspace/ndkTest/ndk-build/TestCC/jni/./timetest.c:7:27: note: expanded from macro 'ANDROID_LOG_DEBUG'
1>#define ANDROID_LOG_DEBUG 3
1> ^
1>C:/Users/v-shenya/AppData/Local/Android/Sdk/ndk-bundle/build//../sysroot/usr/include\stdio.h:129:24: note: passing argument to parameter '__fmt' here
1>int printf(const char* __fmt, ...) __printflike(1, 2);
1> ^
1>1 warning generated.
1>[arm64-v8a] Executable : testtime
1>[arm64-v8a] Install : testtime => libs/arm64-v8a/testtime
1>make: Leaving directory `C:/workspace/ndkTest/ndk-build/TestCC/jni'
1>error=0
1>Press any key to continue . . .
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\VC\VCTargets\Microsoft.MakeFile.Targets(44,5): error MSB3073: The command "C:\workspace\ndkTest\ndk-build\TestCC\jni\build.bat" exited with code -1.
1>Done building project "Project14.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
但是只要不把 “string” 和 “:” 放在一起,编译就没有问题:
1>------ Build started: Project: Project2, Configuration: Debug x86 ------
1>====
1>make: Entering directory `C:/Users/mdTestAU/Desktop/23922-testcc/TestCC/jni'
1>C:/Users/mdTestAU/Desktop/23922-testcc/TestCC/jni/./timetest.c(24,1): warning G5552ABC2: incompatible integer to pointer conversion passing 'int' to parameter of type 'const char *' [-Wint-conversion]
1>LOGD("data length errdor: %d", datalen);
1>^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1>C:/Users/mdTestAU/Desktop/23922-testcc/TestCC/jni/./timetest.c:14:26: note: expanded from macro 'LOGD'
1>#define LOGD(...) printf(ANDROID_LOG_DEBUG,LOG_TAG ,__VA_ARGS__);
1> ^~~~~~~~~~~~~~~~~
1>C:/Users/mdTestAU/Desktop/23922-testcc/TestCC/jni/./timetest.c:8:27: note: expanded from macro 'ANDROID_LOG_DEBUG'
1>#define ANDROID_LOG_DEBUG 3
1> ^
1>C:/ProgramData/Microsoft/AndroidNDK64/android-ndk-r15c/build//../sysroot/usr/include\stdio.h:144:45: note: passing argument to parameter here
1>int printf(const char * __restrict _Nonnull, ...) __printflike(1, 2);
1> ^
1>1 warning generated.
1>[arm64-v8a] Compile : testtime <= timetest.c
1>[arm64-v8a] Executable : testtime
1>[arm64-v8a] Install : testtime => libs/arm64-v8a/testtime
1>make: Leaving directory `C:/Users/mdTestAU/Desktop/23922-testcc/TestCC/jni'
1>error=0
1>Done building project "Project2.vcxproj".
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
就目前来讲,在 VS 中创建的 Android Makefile project 和 Linux Makefile project 在 build 过程中,MSBuild 会把 ”string:” 自动检测会 error 并 放到 errro list 中。
修改出错项目的 MSBuild 的 build 命令,让 MSBuild 编译器能够识别字符串 “string:”
//Android Makefile project 的文件是这个
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\VC\VCTargets\Application Type\Android\3.0\Android.Makefile.targets
"CoreClean" DependsOnTargets="PrepareForNMakeBuild">
"MSB8005" Type="Warning" Arguments="NMakeCleanCommandLine" Condition="'$(NMakeCleanCommandLine)'==''"/>
"$(NMakeCleanCommandLine)"
CustomErrorRegularExpression="(?<FILENAME>[^:]*):(?<LINE>\d*):(?<COLUMN>\d*):\s*(?<CATEGORY>fatal error|error):(?<TEXT>.*)"
CustomWarningRegularExpression="(?<FILENAME>[^:]*):(?<LINE>\d*):(?<COLUMN>\d*):\s*(?<CATEGORY>warning):(?<TEXT>.*)"
IgnoreStandardErrorWarningFormat="true"
Condition="'$(NMakeCleanCommandLine)'!=''"/>
"Build" DependsOnTargets="PrepareForNMakeBuild;ResolveReferences;GetTargetPath;$(PreNMakeBuildTarget)" Returns="$(NMakeManagedOutput)">
"MSB8005" Type="Warning" Arguments="NMakeBuildCommandLine" Condition="'$(NMakeBuildCommandLine)'==''"/>
"$(NMakeBuildCommandLine)"
CustomErrorRegularExpression="(?<FILENAME>[^:]*):(?<LINE>\d*):(?<COLUMN>\d*):\s*(?<CATEGORY>fatal error|error):(?<TEXT>.*)"
CustomWarningRegularExpression="(?<FILENAME>[^:]*):(?<LINE>\d*):(?<COLUMN>\d*):\s*(?<CATEGORY>warning):(?<TEXT>.*)"
IgnoreStandardErrorWarningFormat="true"
Condition="'$(NMakeBuildCommandLine)'!=''"/>
"Rebuild" DependsOnTargets="PrepareForNMakeBuild;_SetRebuildReferences;ResolveReferences;GetTargetPath;$(PreNMakeBuildTarget)" Returns="$(NMakeManagedOutput)">
"MSB8005" Type="Warning" Arguments="NMakeReBuildCommandLine" Condition="'$(NMakeReBuildCommandLine)'=='' and ('$(NMakeCleanCommandLine)'=='' or '$(NMakeBuildCommandLine)'=='')"/>
"$(NMakeReBuildCommandLine)"
CustomErrorRegularExpression="(?<FILENAME>[^:]*):(?<LINE>\d*):(?<COLUMN>\d*):\s*(?<CATEGORY>fatal error|error):(?<TEXT>.*)"
CustomWarningRegularExpression="(?<FILENAME>[^:]*):(?<LINE>\d*):(?<COLUMN>\d*):\s*(?<CATEGORY>warning):(?<TEXT>.*)"
IgnoreStandardErrorWarningFormat="true"
Condition="'$(NMakeReBuildCommandLine)'!=''"/>
"$(NMakeCleanCommandLine)"
CustomErrorRegularExpression="(?<FILENAME>[^:]*):(?<LINE>\d*):(?<COLUMN>\d*):\s*(?<CATEGORY>fatal error|error):(?<TEXT>.*)"
CustomWarningRegularExpression="(?<FILENAME>[^:]*):(?<LINE>\d*):(?<COLUMN>\d*):\s*(?<CATEGORY>warning):(?<TEXT>.*)"
IgnoreStandardErrorWarningFormat="true"
Condition="'$(NMakeReBuildCommandLine)'=='' and '$(NMakeCleanCommandLine)'!='' and '$(NMakeBuildCommandLine)'!=''" />
"$(NMakeBuildCommandLine)"
CustomErrorRegularExpression="(?<FILENAME>[^:]*):(?<LINE>\d*):(?<COLUMN>\d*):\s*(?<CATEGORY>fatal error|error):(?<TEXT>.*)"
CustomWarningRegularExpression="(?<FILENAME>[^:]*):(?<LINE>\d*):(?<COLUMN>\d*):\s*(?<CATEGORY>warning):(?<TEXT>.*)"
IgnoreStandardErrorWarningFormat="true"
Condition="'$(NMakeReBuildCommandLine)'=='' and '$(NMakeCleanCommandLine)'!='' and '$(NMakeBuildCommandLine)'!=''" />
什么意思呢?你修改的是 VS 的配置文件,就是说修改之后对所有该类型项目生效,如果你只希望这个项目可以跑起来,不再做配置文件的改变的话也是可以的
<Import Project="PropertySheet.props" />
"http://schemas.microsoft.com/developer/msbuild/2003">
"CoreClean" DependsOnTargets="PrepareForNMakeBuild">
"MSB8005" Type="Warning" Arguments="NMakeCleanCommandLine" Condition="'$(NMakeCleanCommandLine)'==''"/>
"$(NMakeCleanCommandLine)"
CustomErrorRegularExpression="(?<FILENAME>[^:]*):(?<LINE>\d*):(?<COLUMN>\d*):\s*(?<CATEGORY>fatal error|error):(?<TEXT>.*)"
CustomWarningRegularExpression="(?<FILENAME>[^:]*):(?<LINE>\d*):(?<COLUMN>\d*):\s*(?<CATEGORY>warning):(?<TEXT>.*)"
IgnoreStandardErrorWarningFormat="true"
Condition="'$(NMakeCleanCommandLine)'!=''"/>
"Build" DependsOnTargets="PrepareForNMakeBuild;ResolveReferences;GetTargetPath;$(PreNMakeBuildTarget)" Returns="$(NMakeManagedOutput)">
"MSB8005" Type="Warning" Arguments="NMakeBuildCommandLine" Condition="'$(NMakeBuildCommandLine)'==''"/>
"$(NMakeBuildCommandLine)"
CustomErrorRegularExpression="(?<FILENAME>[^:]*):(?<LINE>\d*):(?<COLUMN>\d*):\s*(?<CATEGORY>fatal error|error):(?<TEXT>.*)"
CustomWarningRegularExpression="(?<FILENAME>[^:]*):(?<LINE>\d*):(?<COLUMN>\d*):\s*(?<CATEGORY>warning):(?<TEXT>.*)"
IgnoreStandardErrorWarningFormat="true"
Condition="'$(NMakeBuildCommandLine)'!=''"/>
"Rebuild" DependsOnTargets="PrepareForNMakeBuild;_SetRebuildReferences;ResolveReferences;GetTargetPath;$(PreNMakeBuildTarget)" Returns="$(NMakeManagedOutput)">
"MSB8005" Type="Warning" Arguments="NMakeReBuildCommandLine" Condition="'$(NMakeReBuildCommandLine)'=='' and ('$(NMakeCleanCommandLine)'=='' or '$(NMakeBuildCommandLine)'=='')"/>
"$(NMakeReBuildCommandLine)"
CustomErrorRegularExpression="(?<FILENAME>[^:]*):(?<LINE>\d*):(?<COLUMN>\d*):\s*(?<CATEGORY>fatal error|error):(?<TEXT>.*)"
CustomWarningRegularExpression="(?<FILENAME>[^:]*):(?<LINE>\d*):(?<COLUMN>\d*):\s*(?<CATEGORY>warning):(?<TEXT>.*)"
IgnoreStandardErrorWarningFormat="true"
Condition="'$(NMakeReBuildCommandLine)'!=''"/>
"$(NMakeCleanCommandLine)"
CustomErrorRegularExpression="(?<FILENAME>[^:]*):(?<LINE>\d*):(?<COLUMN>\d*):\s*(?<CATEGORY>fatal error|error):(?<TEXT>.*)"
CustomWarningRegularExpression="(?<FILENAME>[^:]*):(?<LINE>\d*):(?<COLUMN>\d*):\s*(?<CATEGORY>warning):(?<TEXT>.*)"
IgnoreStandardErrorWarningFormat="true"
Condition="'$(NMakeReBuildCommandLine)'=='' and '$(NMakeCleanCommandLine)'!='' and '$(NMakeBuildCommandLine)'!=''" />
"$(NMakeBuildCommandLine)"
CustomErrorRegularExpression="(?<FILENAME>[^:]*):(?<LINE>\d*):(?<COLUMN>\d*):\s*(?<CATEGORY>fatal error|error):(?<TEXT>.*)"
CustomWarningRegularExpression="(?<FILENAME>[^:]*):(?<LINE>\d*):(?<COLUMN>\d*):\s*(?<CATEGORY>warning):(?<TEXT>.*)"
IgnoreStandardErrorWarningFormat="true"
Condition="'$(NMakeReBuildCommandLine)'=='' and '$(NMakeCleanCommandLine)'!='' and '$(NMakeBuildCommandLine)'!=''" />