编译为独立标志在客户端代码中提供编译错误 [英] Compile with standalone flag gives compilation errors in client code

查看:96
本文介绍了编译为独立标志在客户端代码中提供编译错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用 - 独立编译 Zero29 ,编译器标志。项目本身编译好,但我有一个单元测试项目,在Zero29项目中执行一些代码,即使它是一个可执行程序(.exe)。



一切正常

- standalone 编译标志到Zero29项目,Zero29项目编译正常,但在单元测试项目中,编译器抱怨这个歧视联盟在Zero29项目中定义

 命名空间Ploeh.ZeroToNine 

打开系统
打开Ploeh.ZeroToNine.Versioning

类型Arg =
|分配版本
| AssignRank的排名* int
| Rank的增量
| ListVersions
| ShowHelp
|未知的字符串列表

单元测试项目直接引用Zero29项目:


Zero29.UnitTests --references - > Zero29(其中 - 添加了standalone)


当我尝试编译整个解决方案时,Zero29项目用 - standalone 标志编译,但是Zero29.UnitTests的编译失败。有几个错误,但它们都是一样的,所以这里有一个例子:


错误FS0039:值或构造函数'未定义


这指向此代码

  let ParseAssignVersionReturnsCorrectResult(version:string)= 
let actual = [| -一个;版本|] |> Args.Parse
verify< @ [Assign(Version version)] =(actual |> Seq.toList)@>

奇怪的是,虽然编译器抱怨 $ c>在此代码段的第三行,它不会抱怨使用 Args.Parse ,即使它在与 Arg 歧视联盟



为什么会这样做,如何解决此问题?



(我试图在这里提取问题,但是我提供的链接指向GitHub上的实际代码文件,如果需要更多信息)。

解决方案

使用 - standalone 开关编译的库不能公开任何F#数据类型。这是,一个,在皮克林(2007年),第。在你的情况下,歧视的联合是这些被禁止的类型之一。文件是可执行文件的事实在这里没有任何变化:它试图使用它作为一个时刻成为一个库。



还有多个报告(例如,此处此处),即使使用编译的库 - 独立 behave,引用其中一个来源,funky。可以安全地说,使用这个开关应该只限于独立的可执行文件(他们不能假装是一个库,甚至






Pickering R.(2007)。 F#的基础。 Apress。


I'm attempting to compile Zero29 with the --standalone compiler flag. The project itself compiles fine, but I have a unit test project that exercises some code in the Zero29 project, even though it's an executable program (.exe).

Everything works fine without the --standalone compilation flag.

However, when I add the --standalone compilation flag to the Zero29 project, the Zero29 project compiles fine, but in the unit test project, the compiler complains about this Discriminated Union defined in the Zero29 project:

namespace Ploeh.ZeroToNine

open System
open Ploeh.ZeroToNine.Versioning

type Arg =
    | Assign of Version
    | AssignRank of Rank * int
    | Increment of Rank
    | ListVersions
    | ShowHelp
    | Unknown of string list

The unit test project directly references the Zero29 project:

Zero29.UnitTests --references--> Zero29 (where --standalone is added)

When I attempt to compile the entire solution, the Zero29 project compiles with the --standalone flag, but then compilation of Zero29.UnitTests fails. There are several errors, but they are all the same, so here's a single example:

error FS0039: The value or constructor 'Assign' is not defined

Which points to the third line of this code:

let ParseAssignVersionReturnsCorrectResult(version : string) =
    let actual = [| "-a"; version |] |> Args.Parse
    verify <@ [Assign(Version version)] = (actual |> Seq.toList) @>

The strange thing is that while the compiler complains about Assign in the third line of this code snippet, it doesn't complain about the use of Args.Parse, even though it's defined in the same code file as the Arg Discriminated Union.

Why does it do that, and how can I resolve this issue?

(I've attempted to distil the problem here, but the links I've provided point to the actual code files on GitHub, if more information is required.)

解决方案

Libraries compiled with the --standalone switch cannot expose any F# datatypes. This is, for one, expressly stated in Pickering (2007), p. 210. In your case, a discriminated union is one of these prohibited types. The fact that the file is an executable changes nothing here: it becomes a library the moment you attempt to use it as one.

There have been also multiple reports (for example, here and here) that even libraries compiled with --standalone behave, quoting one of these sources, "funky." It would be safe to say that the use of this switch should perhaps be limited to stand-alone executables only (and they cannot pretend to be a library even when under unit tests).


Pickering R. (2007). Foundations of F#. Apress.

这篇关于编译为独立标志在客户端代码中提供编译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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