Makefile Project 中 MSBuild MSB3073 error 不能正确检测字符串 “error:

本文主要是介绍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="(?&lt;FILENAME&gt;[^:]*):(?&lt;LINE&gt;\d*):(?&lt;COLUMN&gt;\d*):\s*(?&lt;CATEGORY&gt;fatal error|error):(?&lt;TEXT&gt;.*)"
CustomWarningRegularExpression="(?&lt;FILENAME&gt;[^:]*):(?&lt;LINE&gt;\d*):(?&lt;COLUMN&gt;\d*):\s*(?&lt;CATEGORY&gt;warning):(?&lt;TEXT&gt;.*)"
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="(?&lt;FILENAME&gt;[^:]*):(?&lt;LINE&gt;\d*):(?&lt;COLUMN&gt;\d*):\s*(?&lt;CATEGORY&gt;fatal error|error):(?&lt;TEXT&gt;.*)"
CustomWarningRegularExpression="(?&lt;FILENAME&gt;[^:]*):(?&lt;LINE&gt;\d*):(?&lt;COLUMN&gt;\d*):\s*(?&lt;CATEGORY&gt;warning):(?&lt;TEXT&gt;.*)"
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="(?&lt;FILENAME&gt;[^:]*):(?&lt;LINE&gt;\d*):(?&lt;COLUMN&gt;\d*):\s*(?&lt;CATEGORY&gt;fatal error|error):(?&lt;TEXT&gt;.*)"
CustomWarningRegularExpression="(?&lt;FILENAME&gt;[^:]*):(?&lt;LINE&gt;\d*):(?&lt;COLUMN&gt;\d*):\s*(?&lt;CATEGORY&gt;warning):(?&lt;TEXT&gt;.*)"
IgnoreStandardErrorWarningFormat="true"
Condition="'$(NMakeReBuildCommandLine)'!=''"/><Exec Command="$(NMakeCleanCommandLine)" 
CustomErrorRegularExpression="(?&lt;FILENAME&gt;[^:]*):(?&lt;LINE&gt;\d*):(?&lt;COLUMN&gt;\d*):\s*(?&lt;CATEGORY&gt;fatal error|error):(?&lt;TEXT&gt;.*)"
CustomWarningRegularExpression="(?&lt;FILENAME&gt;[^:]*):(?&lt;LINE&gt;\d*):(?&lt;COLUMN&gt;\d*):\s*(?&lt;CATEGORY&gt;warning):(?&lt;TEXT&gt;.*)"
IgnoreStandardErrorWarningFormat="true"
Condition="'$(NMakeReBuildCommandLine)'=='' and '$(NMakeCleanCommandLine)'!='' and '$(NMakeBuildCommandLine)'!=''" /><Exec Command="$(NMakeBuildCommandLine)" 
CustomErrorRegularExpression="(?&lt;FILENAME&gt;[^:]*):(?&lt;LINE&gt;\d*):(?&lt;COLUMN&gt;\d*):\s*(?&lt;CATEGORY&gt;fatal error|error):(?&lt;TEXT&gt;.*)"
CustomWarningRegularExpression="(?&lt;FILENAME&gt;[^:]*):(?&lt;LINE&gt;\d*):(?&lt;COLUMN&gt;\d*):\s*(?&lt;CATEGORY&gt;warning):(?&lt;TEXT&gt;.*)"
IgnoreStandardErrorWarningFormat="true"
Condition="'$(NMakeReBuildCommandLine)'=='' and '$(NMakeCleanCommandLine)'!='' and '$(NMakeBuildCommandLine)'!=''" /></Target>

对单独项目修改

什么意思呢?你修改的是 VS 的配置文件,就是说修改之后对所有该类型项目生效,如果你只希望这个项目可以跑起来,不再做配置文件的改变的话也是可以的

  1. 右击你的ndk-build 项目里,添加一个新的property sheet:你
    这里写图片描述
  2. 在这个property sheet 你需要定义 Build, Rebuild, And CoreClean targets,这会自动覆盖默认的 targets. 因为旧的targets 正则表达式不能正确检测字符串 ”error:”, 所以我们需要用新的正则表达式去替代它。最下面你会看到完整的代码,你只需要将里面的代码复制到你项目中的 PropertySheet.props 就可以了。
  3. .添加代码:
 <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="(?&lt;FILENAME&gt;[^:]*):(?&lt;LINE&gt;\d*):(?&lt;COLUMN&gt;\d*):\s*(?&lt;CATEGORY&gt;fatal error|error):(?&lt;TEXT&gt;.*)"
CustomWarningRegularExpression="(?&lt;FILENAME&gt;[^:]*):(?&lt;LINE&gt;\d*):(?&lt;COLUMN&gt;\d*):\s*(?&lt;CATEGORY&gt;warning):(?&lt;TEXT&gt;.*)"
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="(?&lt;FILENAME&gt;[^:]*):(?&lt;LINE&gt;\d*):(?&lt;COLUMN&gt;\d*):\s*(?&lt;CATEGORY&gt;fatal error|error):(?&lt;TEXT&gt;.*)"
CustomWarningRegularExpression="(?&lt;FILENAME&gt;[^:]*):(?&lt;LINE&gt;\d*):(?&lt;COLUMN&gt;\d*):\s*(?&lt;CATEGORY&gt;warning):(?&lt;TEXT&gt;.*)"
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="(?&lt;FILENAME&gt;[^:]*):(?&lt;LINE&gt;\d*):(?&lt;COLUMN&gt;\d*):\s*(?&lt;CATEGORY&gt;fatal error|error):(?&lt;TEXT&gt;.*)"
CustomWarningRegularExpression="(?&lt;FILENAME&gt;[^:]*):(?&lt;LINE&gt;\d*):(?&lt;COLUMN&gt;\d*):\s*(?&lt;CATEGORY&gt;warning):(?&lt;TEXT&gt;.*)"
IgnoreStandardErrorWarningFormat="true"
Condition="'$(NMakeReBuildCommandLine)'!=''"/><Exec Command="$(NMakeCleanCommandLine)"
CustomErrorRegularExpression="(?&lt;FILENAME&gt;[^:]*):(?&lt;LINE&gt;\d*):(?&lt;COLUMN&gt;\d*):\s*(?&lt;CATEGORY&gt;fatal error|error):(?&lt;TEXT&gt;.*)"
CustomWarningRegularExpression="(?&lt;FILENAME&gt;[^:]*):(?&lt;LINE&gt;\d*):(?&lt;COLUMN&gt;\d*):\s*(?&lt;CATEGORY&gt;warning):(?&lt;TEXT&gt;.*)"
IgnoreStandardErrorWarningFormat="true"
Condition="'$(NMakeReBuildCommandLine)'=='' and '$(NMakeCleanCommandLine)'!='' and '$(NMakeBuildCommandLine)'!=''" /><Exec Command="$(NMakeBuildCommandLine)"
CustomErrorRegularExpression="(?&lt;FILENAME&gt;[^:]*):(?&lt;LINE&gt;\d*):(?&lt;COLUMN&gt;\d*):\s*(?&lt;CATEGORY&gt;fatal error|error):(?&lt;TEXT&gt;.*)"
CustomWarningRegularExpression="(?&lt;FILENAME&gt;[^:]*):(?&lt;LINE&gt;\d*):(?&lt;COLUMN&gt;\d*):\s*(?&lt;CATEGORY&gt;warning):(?&lt;TEXT&gt;.*)"
IgnoreStandardErrorWarningFormat="true"
Condition="'$(NMakeReBuildCommandLine)'=='' and '$(NMakeCleanCommandLine)'!='' and '$(NMakeBuildCommandLine)'!=''" /></Target></Project>

这篇关于Makefile Project 中 MSBuild MSB3073 error 不能正确检测字符串 “error:的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1010527

相关文章

Python实现字典转字符串的五种方法

《Python实现字典转字符串的五种方法》本文介绍了在Python中如何将字典数据结构转换为字符串格式的多种方法,首先可以通过内置的str()函数进行简单转换;其次利用ison.dumps()函数能够... 目录1、使用json模块的dumps方法:2、使用str方法:3、使用循环和字符串拼接:4、使用字符

Python 常用数据类型详解之字符串、列表、字典操作方法

《Python常用数据类型详解之字符串、列表、字典操作方法》在Python中,字符串、列表和字典是最常用的数据类型,它们在数据处理、程序设计和算法实现中扮演着重要角色,接下来通过本文给大家介绍这三种... 目录一、字符串(String)(一)创建字符串(二)字符串操作1. 字符串连接2. 字符串重复3. 字

C#自动化实现检测并删除PDF文件中的空白页面

《C#自动化实现检测并删除PDF文件中的空白页面》PDF文档在日常工作和生活中扮演着重要的角色,本文将深入探讨如何使用C#编程语言,结合强大的PDF处理库,自动化地检测并删除PDF文件中的空白页面,感... 目录理解PDF空白页的定义与挑战引入Spire.PDF for .NET库核心实现:检测并删除空白页

Java 中的 equals 和 hashCode 方法关系与正确重写实践案例

《Java中的equals和hashCode方法关系与正确重写实践案例》在Java中,equals和hashCode方法是Object类的核心方法,广泛用于对象比较和哈希集合(如HashMa... 目录一、背景与需求分析1.1 equals 和 hashCode 的背景1.2 需求分析1.3 技术挑战1.4

Java 字符串操作之contains 和 substring 方法最佳实践与常见问题

《Java字符串操作之contains和substring方法最佳实践与常见问题》本文给大家详细介绍Java字符串操作之contains和substring方法最佳实践与常见问题,本文结合实例... 目录一、contains 方法详解1. 方法定义与语法2. 底层实现原理3. 使用示例4. 注意事项二、su

如何正确识别一台POE交换机的好坏? 选购可靠的POE交换机注意事项

《如何正确识别一台POE交换机的好坏?选购可靠的POE交换机注意事项》POE技术已经历多年发展,广泛应用于安防监控和无线覆盖等领域,需求量大,但质量参差不齐,市场上POE交换机的品牌繁多,如何正确识... 目录生产标识1. 必须包含的信息2. 劣质设备的常见问题供电标准1. 正规的 POE 标准2. 劣质设

Java实现将HTML文件与字符串转换为图片

《Java实现将HTML文件与字符串转换为图片》在Java开发中,我们经常会遇到将HTML内容转换为图片的需求,本文小编就来和大家详细讲讲如何使用FreeSpire.DocforJava库来实现这一功... 目录前言核心实现:html 转图片完整代码场景 1:转换本地 HTML 文件为图片场景 2:转换 H

Java中如何正确的停掉线程

《Java中如何正确的停掉线程》Java通过interrupt()通知线程停止而非强制,确保线程自主处理中断,避免数据损坏,线程池的shutdown()等待任务完成,shutdownNow()强制中断... 目录为什么不强制停止为什么 Java 不提供强制停止线程的能力呢?如何用interrupt停止线程s

解决Nginx启动报错Job for nginx.service failed because the control process exited with error code问题

《解决Nginx启动报错Jobfornginx.servicefailedbecausethecontrolprocessexitedwitherrorcode问题》Nginx启... 目录一、报错如下二、解决原因三、解决方式总结一、报错如下Job for nginx.service failed bec

Java使用正则提取字符串中的内容的详细步骤

《Java使用正则提取字符串中的内容的详细步骤》:本文主要介绍Java中使用正则表达式提取字符串内容的方法,通过Pattern和Matcher类实现,涵盖编译正则、查找匹配、分组捕获、数字与邮箱提... 目录1. 基础流程2. 关键方法说明3. 常见场景示例场景1:提取所有数字场景2:提取邮箱地址4. 高级