本文主要是介绍Makefile Project 中 MSBuild MSB3073 error 不能正确检测字符串 “error:,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
背景
在 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 31> ^1>C:/ProgramData/Microsoft/AndroidNDK64/android-ndk-r15c/build//../sysroot/usr/include\stdio.h:144:45: note: passing argument to parameter here1>int printf(const char * __restrict _Nonnull, ...) __printflike(1, 2);1> ^1>1 warning generated.1>[arm64-v8a] Compile : testtime <= timetest.c1>[arm64-v8a] Executable : testtime1>[arm64-v8a] Install : testtime => libs/arm64-v8a/testtime1>make: Leaving directory `C:/Users/mdTestAU/Desktop/23922-testcc/TestCC/jni'1>error=01>Done building project "Project2.vcxproj".========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
具体情况
- https://devdiv.visualstudio.com/DefaultCollection/DevDiv/_workitems/edit/601596
- https://stackoverflow.com/questions/49857869/when-i-use-msbuild-to-build-android-makefile-project-and-print-log-i-cant-put
- https://developercommunity.visualstudio.com/content/problem/205761/i-wrote-the-script-to-build-android-ndk-applicatio.html
原因
就目前来讲,在 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
之后你 copy 这个文件做个备份
修改Android.Makefile.targets 里面的 Build、CoreClean、ReBuild 三个 Target
<!-- Override the default build / rebuild / clean makefile targets to pass in our custom error / warning handling --><Target Name="CoreClean" DependsOnTargets="PrepareForNMakeBuild"><VCMessage Code="MSB8005" Type="Warning" Arguments="NMakeCleanCommandLine" Condition="'$(NMakeCleanCommandLine)'==''"/><Exec Command="$(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)'!=''"/></Target><Target Name="Build" DependsOnTargets="PrepareForNMakeBuild;ResolveReferences;GetTargetPath;$(PreNMakeBuildTarget)" Returns="$(NMakeManagedOutput)"><VCMessage Code="MSB8005" Type="Warning" Arguments="NMakeBuildCommandLine" Condition="'$(NMakeBuildCommandLine)'==''"/><Exec Command="$(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)'!=''"/></Target><Target Name="Rebuild" DependsOnTargets="PrepareForNMakeBuild;_SetRebuildReferences;ResolveReferences;GetTargetPath;$(PreNMakeBuildTarget)" Returns="$(NMakeManagedOutput)"><VCMessage Code="MSB8005" Type="Warning" Arguments="NMakeReBuildCommandLine" Condition="'$(NMakeReBuildCommandLine)'=='' and ('$(NMakeCleanCommandLine)'=='' or '$(NMakeBuildCommandLine)'=='')"/><Exec Command="$(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)'!=''"/><Exec Command="$(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)'!=''" /><Exec Command="$(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)'!=''" /></Target>
对单独项目修改
什么意思呢?你修改的是 VS 的配置文件,就是说修改之后对所有该类型项目生效,如果你只希望这个项目可以跑起来,不再做配置文件的改变的话也是可以的
- 右击你的ndk-build 项目里,添加一个新的property sheet:你
- 在这个property sheet 你需要定义 Build, Rebuild, And CoreClean targets,这会自动覆盖默认的 targets. 因为旧的targets 正则表达式不能正确检测字符串 ”error:”, 所以我们需要用新的正则表达式去替代它。最下面你会看到完整的代码,你只需要将里面的代码复制到你项目中的 PropertySheet.props 就可以了。
- .添加代码:
<Import Project="PropertySheet.props" />
Reload the project and build again.
Android Makefile prject –> PropertySheet.props
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"><Target Name="CoreClean" DependsOnTargets="PrepareForNMakeBuild"><VCMessage Code="MSB8005" Type="Warning" Arguments="NMakeCleanCommandLine" Condition="'$(NMakeCleanCommandLine)'==''"/><Exec Command="$(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)'!=''"/></Target><Target Name="Build" DependsOnTargets="PrepareForNMakeBuild;ResolveReferences;GetTargetPath;$(PreNMakeBuildTarget)" Returns="$(NMakeManagedOutput)"><VCMessage Code="MSB8005" Type="Warning" Arguments="NMakeBuildCommandLine" Condition="'$(NMakeBuildCommandLine)'==''"/><Exec Command="$(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)'!=''"/></Target><Target Name="Rebuild" DependsOnTargets="PrepareForNMakeBuild;_SetRebuildReferences;ResolveReferences;GetTargetPath;$(PreNMakeBuildTarget)" Returns="$(NMakeManagedOutput)"><VCMessage Code="MSB8005" Type="Warning" Arguments="NMakeReBuildCommandLine" Condition="'$(NMakeReBuildCommandLine)'=='' and ('$(NMakeCleanCommandLine)'=='' or '$(NMakeBuildCommandLine)'=='')"/><Exec Command="$(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)'!=''"/><Exec Command="$(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)'!=''" /><Exec Command="$(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)'!=''" /></Target></Project>
这篇关于Makefile Project 中 MSBuild MSB3073 error 不能正确检测字符串 “error:的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!