无法使System.Numerics在OS X上与命令行Mono(mcs)一起使用 [英] Can't get System.Numerics to work with command-line Mono (mcs) on OS X

查看:151
本文介绍了无法使System.Numerics在OS X上与命令行Mono(mcs)一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在尝试在OS X的命令行上运行一个简单的Mono脚本.大多数脚本对我们来说都可以正常工作,但是当我们尝试使用System.Numerics时,我们会收到错误CS0234:类型或名称空间名称数字"在名称空间系统中不存在."

We're trying to run a simple Mono script on the command line on OS X. Most scripts work fine for us, but as soon as we try to use System.Numerics, we get "error CS0234: The type or namespace name `Numerics' does not exist in the namespace System."

这并不奇怪,应该使用mcs的适当命令行选项进行修复,再加上正确设置PKG_CONFIG_PATH ...,但这就是我们的绊脚石.首先,这是脚本,因此您可以在家中进行以下操作:

This isn't too surprising, and should be fixable with an appropriate command-line option to mcs, plus properly set up PKG_CONFIG_PATH... but this is where we get stumped. First, here's the script so you can follow along at home:

using System;
using System.Numerics;

public static class MainProgram {
    public static void Main(string[] args) {
        Console.WriteLine("Hello world!");
    }
}

因此,接下来我们尝试了"mcs -r:System.Numerics Test.cs".这样会产生错误CS0006:找不到元数据文件'System.Numerics'".

So next we tried "mcs -r:System.Numerics Test.cs". This produces "error CS0006: Metadata file `System.Numerics' could not be found".

"man mcs"建议我们可以通过在命令行中添加"-pkg:dotnet"来获取其他系统软件包.但这会产生:

"man mcs" suggests that we can get the other system packages by adding "-pkg:dotnet" to the command line. But that produces:

在pkg-config搜索路径中找不到软件包dotnet.可能 您应该将包含`dotnet.pc'的目录添加到 PKG_CONFIG_PATH环境变量找不到软件包"dotnet"错误 CS8027:运行pkg-config时出错.检查上面的输出.

Package dotnet was not found in the pkg-config search path. Perhaps you should add the directory containing `dotnet.pc' to the PKG_CONFIG_PATH environment variable No package 'dotnet' found error CS8027: Error running pkg-config. Check the above output.

那么,我们没有PKG_CONFIG_PATH,因此我们尝试定义一个:

OK then, we had no PKG_CONFIG_PATH, so we tried defining one:

export PKG_CONFIG_PATH=/Library/Frameworks/Mono.framework/Versions/Current/lib/pkgconfig/

这修复了CS8027;但是我们仍然得到开始使用的CS0234.如果我结合了-pkg和-r,例如"mcs -pkg:dotnet -r:System.Numerics Test.cs",我收到错误CS0006:找不到元数据文件'System.Numerics'".

This fixes the CS8027; but we still get the CS0234 we started with. And if I combine the -pkg and the -r, e.g. "mcs -pkg:dotnet -r:System.Numerics Test.cs", I get "error CS0006: Metadata file `System.Numerics' could not be found".

在这一点上,我感到难过……不知道我想让System.Numerics与mcs一起使用是什么咒语吗?

I'm stumped at this point... any idea what incantation I'm missing to make System.Numerics work with mcs?

推荐答案

如果使用的是Mono 2.10.x,则必须使用dmcs而不是mcs进行编译才能启用4.0概要文件(System.Numerics仅是C#4.0或更高版本的功能).

If you're using Mono 2.10.x, you will have to compile with dmcs rather than mcs to enable the 4.0 profile (System.Numerics is a C# 4.0+ feature only).

如果您使用的是Mono 2.11.x或3.0.x,则默认情况下mcs应该选择4.5配置文件. mcs -help应该显示244.5作为-sdk选项的可能值.如果没有安装,则说明框架安装不正确;否则,请重新安装框架.我曾经有一次,我以为/Library/Frameworks/Mono.framework/Versions/Current指向错误的目录.再次安装可以解决该问题.

If you're using Mono 2.11.x or 3.0.x, then mcs by default should select the 4.5 profile. mcs -help should show 2, 4, and 4.5 as possible values for the -sdk option. If it doesn't, then the framework isn't properly installed; I had that once, where I think that /Library/Frameworks/Mono.framework/Versions/Current pointed to the wrong directory; installing a second time fixed that.

不需要pkg-config.

这篇关于无法使System.Numerics在OS X上与命令行Mono(mcs)一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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