原来在引用附加库到工程中时,都是在项目属性中,添加附加的头文件和库文件,每次自己重装电脑了,或者工程变了都要重新添加一遍,
非常复杂。于是学会了写配置文件,添加库只要把额外的配置文件加入项目即可,详细过程如下:
1 前提摘要
环境:本人环境为VS2012,可能别的环境不太适合
环境变量:如果路径太长了,直接写环境变量比较省事
2 如何编写配置文件
先上一份配置文件,这是我电脑上的opencv2.4.8的配置文件:
<?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>$(OPENCV)\include;$(IncludePath)</IncludePath>
<LibraryPath Condition="'$(Platform)'=='Win32'">$(OPENCV)\x86\vc11\lib;$(LibraryPath)</LibraryPath>
<LibraryPath Condition="'$(Platform)'=='X64'">$(OPENCV)\x64\vc11\lib;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup>
<Link Condition="'$(Configuration)'=='Debug'">
<AdditionalDependencies>opencv_calib3d248d.lib;opencv_contrib248d.lib;opencv_core248d.lib;opencv_features2d248d.lib;opencv_flann248d.lib;opencv_gpu248d.lib;opencv_highgui248d.lib;opencv_imgproc248d.lib;opencv_legacy248d.lib;opencv_ml248d.lib;opencv_nonfree248d.lib;opencv_objdetect248d.lib;opencv_ocl248d.lib;opencv_photo248d.lib;opencv_stitching248d.lib;opencv_superres248d.lib;opencv_ts248d.lib;opencv_video248d.lib;opencv_videostab248d.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
<Link Condition="'$(Configuration)'=='Release'">
<AdditionalDependencies>opencv_calib3d248.lib;opencv_contrib248.lib;opencv_core248.lib;opencv_features2d248.lib;opencv_flann248.lib;opencv_gpu248.lib;opencv_highgui248.lib;opencv_imgproc248.lib;opencv_legacy248.lib;opencv_ml248.lib;opencv_nonfree248.lib;opencv_objdetect248.lib;opencv_ocl248.lib;opencv_photo248.lib;opencv_stitching248.lib;opencv_superres248.lib;opencv_ts248.lib;opencv_video248.lib;opencv_videostab248.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup />
</Project>
如何编写:(1) 估计看了上面这一份配置,大家都会写配置文件了 配置中$(OPENCV) 是自定义的环境变量 就是OPENCV的目录
(2) 只要在IncludePath ,LibraryPath ,AdditionalDependencies 这三个标签中填入正确的值即可,分别是:头文件路径,库路径,和库名称,这里面库路径分别要填写Win32 和X64两个版本,同样链接库也要写Debug和Release两个版本的
(3)写完了保存的时候,记得后缀名是props
3 如何导入工程
将需要的附加库导入工程非常简单!
打开工程的属性管理器 -选中工程 右键 -添加现有属性表--然后选择配置文件--打开 -- 导入完毕
附加库可以使用了......