【问题标题】:Adding additional library and include paths when compiling from command line从命令行编译时添加额外的库和包含路径
【发布时间】:2013-03-17 05:56:58
【问题描述】:

我正在尝试添加其他路径以供我的项目组在编译期间使用。由于 C++ Builder 2010 使用 msbuild 我已经尝试查看文档,根据我可以找到的内容 AdditionalLibPaths 应该可以作为属性传递.即

msbuild /p:AdditionalLibPaths=C:\FooBar\Libs /t:build foo.groupproj

但它似乎没有使用我添加的路径。我之前注意到,当传递给 msbuild 时,VC++C++ Builder 之间的某些属性名称不同,并且想知道是否 C++ Builder 可能会使用其他属性名称来添加额外的库和包含文件夹?

我不想替换项目中定义的现有路径,而是附加其他路径。这样做的理由是,当项目在我们的构建服务器上构建时,一些库驻留在一个标准化的位置,可能与它在开发机器上的安装位置不同。

msbuild 实际调用了一个 msbuild 脚本文件,而该文件又使用 调用其他脚本,包括 .groupproj 脚本> 标签。我知道使用 标记时会创建一个新的 msbuild 实例,因此我知道在脚本中运行该任务时必须添加该属性。

<MSBuild Targets="Build" Projects="..\Foo.groupproj" Properties="Config=Debug (property to add additional paths here!)" />

更新:

C++ Builder 似乎正在使用 IncludePathILINK_LibraryPath 但设置这些会覆盖项目文件中已定义的路径。由于此文件由 IDE 创建和维护,因此任何使其附加而不是覆盖的更改都将被 IDE 覆盖。这有点奇怪,因为它看起来确实应该附加值

<IncludePath>..\FooBar\;$(BDS)\include;$(BDS)\include\dinkumware;$(BDS)\include\vcl;Common Components;..\Config\Config32;$(IncludePath)</IncludePath>

更新 2:

CodeGear.Cpp.Targets 中,我将自己的 property 称为 AdditionalIncludePaths 添加到 PropertyGroup包括路径。

251号线附近

<PropertyGroup>
        <BCC_NoLink>true</BCC_NoLink>
        <ILINK_OSVersion Condition="'$(ILINK_OSVersion)'=='' And '$(NoVCL)'!='true'">5.0</ILINK_OSVersion>
        <DCC_GenerateCppFiles>true</DCC_GenerateCppFiles>
        <ShowStdOut Condition="'$(ShowStdOut)'==''">$(ShowGeneralMessages)</ShowStdOut>

        <!-- _TCHAR mapping for Uni^H^H^H character selection -->
        <StartupObj Condition="'$(_TCHARMapping)'=='wchar_t'">$(StartupObj)w</StartupObj>
        <ILINK_StartupObjs Condition="'$(ILINK_StartupObjs)'==''">$(StartupObj)</ILINK_StartupObjs>
        <BCC_GenerateUnicode Condition="'$(_TCHARMapping)'=='wchar_t'">true</BCC_GenerateUnicode>
        <!-- Include Paths -->
        <Win32LibraryPath Condition="'$(Win32LibraryPath)'==''">$(BDS)\lib</Win32LibraryPath>
        <IncludePath Condition="'$(CBuilderIncludePath)'!=''">$(IncludePath);$(CBuilderIncludePath)</IncludePath>
                <IncludePath Condition="'$(AdditionalIncludePath)'!=''">$(IncludePath);$(AdditionalIncludePath)</IncludePath>
        <BCC_IncludePath Condition="'$(BCC_IncludePath)'!=''">$(BCC_IncludePath);$(IncludePath)</BCC_IncludePath>
        <BCC_IncludePath Condition="'$(BCC_IncludePath)'==''">$(IncludePath)</BCC_IncludePath>
        <BRCC_IncludePath Condition="'$(BRCC_IncludePath)'!=''">$(BRCC_IncludePath);$(IncludePath)</BRCC_IncludePath>
        <BRCC_IncludePath Condition="'$(BRCC_IncludePath)'==''">$(IncludePath)</BRCC_IncludePath>
        <DCC_IncludePath Condition="'$(DCC_IncludePath)'!=''">$(DCC_IncludePath);$(IncludePath)</DCC_IncludePath>
        <DCC_IncludePath Condition="'$(DCC_IncludePath)'==''">$(IncludePath)</DCC_IncludePath>
        <DCC_UnitSearchPath>$(DCC_IncludePath);$(Win32LibraryPath)</DCC_UnitSearchPath>
        <DCC_ResourcePath>$(DCC_IncludePath)</DCC_ResourcePath>
        <DCC_ObjPath>$(DCC_IncludePath)</DCC_ObjPath>
        <TASM_IncludePath Condition="'$(TASM_IncludePath)'!=''">$(TASM_IncludePath);$(IncludePath)</TASM_IncludePath>
        <TASM_IncludePath Condition="'$(TASM_IncludePath)'==''">$(IncludePath)</TASM_IncludePath>

那我可以打电话了

msbuild /t:build /p:AdditionalIncludePaths=C:\Foo\Include foo.groupproj

这很好用,可以满足我的要求。我只需要对库路径做同样的事情。但我不想破解这样的 Embarcaderos 提供的文件之一。这太荒谬了:P...没有任何官方属性可以设置来添加包含路径和库路径吗?

【问题讨论】:

    标签: msbuild c++builder


    【解决方案1】:

    对于 VS2019,我测试了msbuild,它不会应用INCLUDELIB 的这些环境变量,即使你已经设置了它们。根本原因可能是msbuild在加载和编译*.sln*.vcxproj时覆盖了INCLUDELIB。但是,这只是我的假设,因为有关 windows/msbuild 的在线文档很难找到底层原因。

    解决方案 A:
    在我的解决方案中,我使用CLLINK 环境变量在msbuild 构建项目之前将include 目录和lib 目录设置为:

    set $env:CL="/I\C:\users\user\local\include"
    set $env:LINK="/LIBPATH:C:\users\user\local\lib"
    ...
    msbuild *.vcxproj
    

    更多关于CLMSVC compiler environment variables
    更多关于LINKMSVC Linker environment variables

    解决方案 B:
    对于您已经指出的另一种可能的解决方案,您可以将选项传递给msbuild,例如:

    msbuild *.vcxproj /nologo /p:AdditionalIncludePaths="C:\users\user\local"
    msbuild *.vcxproj /nologo /p:IncludePath="C:\users\user\local"
    

    【讨论】:

      【解决方案2】:

      对于 VS2019 上的其他 include,请使用开关 /p:IncludePath=C:\Foo

      要包含多个路径,请在开关上使用双引号和分号:

      /p:IncludePath="C:\Foo;C:\Bar;C:\Another;$(IncludePath)"
      

      【讨论】:

      • 多路径怎么样。
      • @X.Arthur 你可以这样做(注意双引号和分号):/p:IncludePath="C:\Foo;C:\Bar;C:\Another;$(IncludePath)"
      【解决方案3】:

      在 C++Builder 10 Seattle(截至 2016 年的当前版本)中,我能够通过在运行 @987654322 之前将其他库路径放入环境变量 ILink_LibraryPath 来解决这个问题(即在自动构建中添加自定义库路径) @。这必须由set ILink_LibraryPath=... 完成,而不是通过将属性作为/p:... 传递给msbuild

      这在自动构建环境中实现了额外的路径,而无需替换 .cbproj 文件中已设置的现有路径,并且不需要对 Embarcadero 提供的文件进行任何修改。

      这种方法的唯一问题是不能保证检查单个路径的顺序 - 即通过环境变量提供的自定义路径附加到 .cbproj 路径或可能放在中间,具体取决于项目设置,并且是不一定放在前面,所以需要注意项目文件中提到的其他目录中不要有冲突的库。

      【讨论】:

      • 非常有用的答案,谢谢!关于这个环境变量,如果我们需要提供多个值路径,那么语法会是什么样子?
      • @nk-fford 用分号分隔多个路径
      【解决方案4】:

      对于 VS2013,只需要在运行 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
      

      参考: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>
      

      但看起来像是附加在项目属性中指定的附加 include/lib 目录后面的 INCLUDE 和 LIB。

      【讨论】:

        猜你喜欢
        • 2013-04-06
        • 1970-01-01
        • 2012-06-06
        • 2011-05-06
        • 1970-01-01
        • 1970-01-01
        • 2014-01-02
        • 2012-09-07
        • 1970-01-01
        相关资源
        最近更新 更多