Adding additional library and include paths when compiling from command line

≡放荡痞女 提交于 2019-11-28 23:38:52

For VS2013, just define environment variables before running msbuild:

set "INCLUDE=%additional_include_path%;%INCLUDE%"
set "LIB=%additional_lib_path%;%LIB%"
REM use environment variables for INCLUDE and LIB values
set UseEnv=true

Reference: MSBuild/Microsoft.Cpp/v4.0/V120/Microsoft.Cpp.targets

<Target Name="SetBuildDefaultEnvironmentVariables"
        Condition="'$(UseEnv)' != 'true'">
...
    <SetEnv Name   ="INCLUDE"
        Value  ="$(IncludePath)"
        Prefix ="false" >
       <Output TaskParameter="OutputEnvironmentVariable"             PropertyName="INCLUDE"/>
    </SetEnv>

But looks like the INCLUDE and LIB appended behind additional include/lib directories specified in project properties.

In C++Builder 10 Seattle (current version as of 2016), I was able to solve this problem (i.e. add custom library paths in automated build) by putting additional library paths into environment variable ILink_LibraryPath before running msbuild. This has to be done by set ILink_LibraryPath=..., not by passing property as /p:... to msbuild.

This achieves additional paths in automated build environment, without replacing existing paths already set in .cbproj files, and doesn't require any hacks in Embarcadero-supplied files.

The only problem with this approach is that the sequence in which individual paths are checked is not guaranteed - i.e. custom paths supplied via environment variable are appended to .cbproj paths or possibly put in the middle, depending on project setup, and are not necessarily put in front, so you need to be careful to not have conflicting libraries in other directories mentioned in project files.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!