从命令行编译时添加额外的库和包含路径 [英] Adding additional library and include paths when compiling from command line

查看:9
本文介绍了从命令行编译时添加额外的库和包含路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to add additional paths to be used by my project group during compilation. Since C++ Builder 2010 uses msbuild I have tried looking at the documentation for that and according to what I can find AdditionalLibPaths should be passable as a property. i.e

msbuild /p:AdditionalLibPaths=C:FooBarLibs /t:build foo.groupproj

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

But it doesn't seem to use the paths I added. I have previously noticed that some property names differ between VC++ and C++ Builder when passed to msbuild and wonder if C++ Builder might use some other property name to add additional lib and include folders?

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

I don't want to replace the existing paths defined in the project but append additional ones. The rationale for this is that when the project is build on our build server some libraries reside in a standardized place that might differ from where it's installed on the development machine.

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

msbuild acutally calls a msbuild script file that in turn calls additional scripts including the .groupproj ones using the tag. I know that a new instance of msbuild is created when using the tag so I know that I have to add the property when running that task in my script.

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

更新:

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

C++ Builder seems to be using IncludePath and ILINK_LibraryPath but setting these overwrite the paths already defined in the project file. Since this file is created and maintained by the IDE so any changes to make it append instead of overwrite would be overwritten by the IDE. Which is kind of strange since it looks like it should indeed append the values

<IncludePath>..FooBar;$(BDS)include;$(BDS)includedinkumware;$(BDS)includevcl;Common Components;..ConfigConfig32;$(IncludePath)</IncludePath>

更新 2:

CodeGear.Cpp.Targets 我添加了我自己的 property 称为 AdditionalIncludePathsPropertyGroup 摆弄包括路径.

In CodeGear.Cpp.Targets I added my own property called AdditionalIncludePaths to the PropertyGroup fiddling with the include paths.

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:FooInclude foo.groupproj

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

This works fine and does what I want. I'll just have to do the same with the library paths. But I don't want to have to hack one of Embarcaderos supplied files like this. That's just ridiculous :P... Isn't there any official property to set for adding include paths and lib paths?

推荐答案

对于VS2013,只需要在运行msbuild之前定义环境变量即可:

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

参考:MSBuild/Microsoft.Cpp/v4.0/V120/Microsoft.Cpp.targets

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>

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

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

这篇关于从命令行编译时添加额外的库和包含路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆