VS:使用一个pros文件在Debug和Release下配置opencv

目录

1.背景

2.目的

3.方法

4.配置

4.1. OpenCV 4.4.0:

4.2. OpenCV3.4.6

4.3. Opencv2.4.13

4.4 添加该.pros文件


 

1.背景

某个偶然的机会,看到有些VS工程只配置一个pros文件即可满足opencv在Debug和Release模式下的运行。

2.目的

实现一个pros统领opencv在Debug和Release下的运行,但不限于配置opencv。

3.方法

在标签头中加入Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'" 或者Condition="'$(Configuration)|$(Platform)' == 'Release|x64'" 即可实现在同一配置文件(.pros)中实现不同平台的配置。

4.配置

pros文件如下:给出OpenCV4、OpenCV3、OpenCV2某一版本的模板。一下结果均配置为x64

创建后缀为.pros文件,或者在如下图vs里Add New Project Property Sheet,然后根据按照opencv版本选择4.1-4.3以本文编辑方式填写.pros文件。

4.1. OpenCV 4.4.0:

<PropertyGroup>中在对应<IncludePath>和<LibraryPath>输入头文件目录和库文件目录

PS:若Debug和Release下文件路径不同,则,例:<PropertyGroup> 改写为<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> 等。

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ImportGroup Label="PropertySheets" />
  <PropertyGroup Label="UserMacros" />
  
  <PropertyGroup>
    <IncludePath>F:\opencv4\build\include;F:\opencv4\build\include\opencv2</IncludePath>
    <LibraryPath>F:\opencv4\build\x64\vc14\lib;$(LibraryPath)</LibraryPath>
  </PropertyGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
    <Link>
      <AdditionalDependencies>opencv_world440d.lib;%(AdditionalDependencies)</AdditionalDependencies>
    </Link>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <Link>
      <AdditionalDependencies>opencv_world440.lib;%(AdditionalDependencies)</AdditionalDependencies>
    </Link>
  </ItemDefinitionGroup>
  <ItemGroup />
</Project>

4.2. OpenCV3.4.6

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ImportGroup Label="PropertySheets" />
  <PropertyGroup Label="UserMacros" />
  
  <PropertyGroup>
    <IncludePath>F:\opencv3\build\include;F:\opencv3\build\include\opencv2</IncludePath>
    <LibraryPath>F:\opencv3\build\x64\vc14\lib;$(LibraryPath)</LibraryPath>
  </PropertyGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
    <Link>
      <AdditionalDependencies>opencv_world346d.lib;%(AdditionalDependencies)</AdditionalDependencies>
    </Link>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <Link>
      <AdditionalDependencies>opencv_world346.lib;%(AdditionalDependencies)</AdditionalDependencies>
    </Link>
  </ItemDefinitionGroup>
  <ItemGroup />
</Project>

4.3. Opencv2.4.13

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ImportGroup Label="PropertySheets" />
  <PropertyGroup Label="UserMacros" />
  
  <PropertyGroup>
    <IncludePath>F:\opencv2\build\include;F:\opencv2\build\include\opencv2</IncludePath>
    <LibraryPath>F:\opencv2\build\x64\vc14\lib;$(LibraryPath)</LibraryPath>
  </PropertyGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
    <Link>
      <AdditionalDependencies>opencv_ml2413d.lib;opencv_calib3d2413d.lib;opencv_contrib2413d.lib;opencv_core2413d.lib;opencv_features2d2413d.lib;opencv_flann2413d.lib;opencv_gpu2413d.lib;opencv_highgui2413d.lib;opencv_imgproc2413d.lib;opencv_legacy2413d.lib;opencv_objdetect2413d.lib;opencv_ts2413d.lib;opencv_video2413d.lib;opencv_nonfree2413d.lib;opencv_ocl2413d.lib;opencv_photo2413d.lib;opencv_stitching2413d.lib;opencv_superres2413d.lib;opencv_videostab2413d.lib;%(AdditionalDependencies)</AdditionalDependencies>
    </Link>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <Link>
      <AdditionalDependencies>opencv_ml2413.lib;opencv_calib3d2413.lib;opencv_contrib2413.lib;opencv_core2413.lib;opencv_features2d2413.lib;opencv_flann2413.lib;opencv_gpu2413.lib;opencv_highgui2413.lib;opencv_imgproc2413.lib;opencv_legacy2413.lib;opencv_objdetect2413.lib;opencv_ts2413.lib;opencv_video2413.lib;opencv_nonfree2413.lib;opencv_ocl2413.lib;opencv_photo2413d.lib;opencv_stitching2413.lib;opencv_superres2413.lib;opencv_videostab2413.lib;%(AdditionalDependencies)</AdditionalDependencies>
    </Link>
  </ItemDefinitionGroup>
</Project>

4.4 添加该.pros文件

Debug和Release下都添加该.pros文件,结果如下:

Debug:

Release:

最终一个pros即可实现opencv在Debug和Release下的配置,无需配置两个.pros两件。(该方法不限于配置opencv)。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值