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

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

问题描述

我正在尝试添加其他路径,以供我的项目组在编译期间使用.由于 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:\FooBar\Libs /t:build foo.groupproj

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

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 似乎正在使用 IncludePath ILINK_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)\include\dinkumware;$(BDS)\include\vcl;Common Components;..\Config\Config32;$(IncludePath)</IncludePath>

更新2:

CodeGear.Cpp.Targets 中,我将自己的称为 AdditionalIncludePaths 属性添加到了 PropertyGroup 中,包含路径.

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:\Foo\Include foo.groupproj

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

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天全站免登陆