首页 > 解决方案 > 如何使用 dotnet core 从 linux 共享库中导入公共 ref 类

问题描述

我看过其他一些关于这个的帖子,要么它们太简单,要么太旧。我宁愿不使用 Visual Studio,因为我对它不是很熟悉,也没有安装它。我在 ubuntu 中使用 dotnet core cli。我有一个共享库vendor.so我正在尝试使用内部公共引用类中的方法vendor.so这是代码

vendor.h

namespace Vendor_namespace{
    public ref class Vendor
    {
    public:
        int myMethod(...)

MyCSharp.cs

using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

namespace Program {
       class Program {
        [DllImport("Vendor.so")]
        static extern class Vendor;
public static void main(string[] args) {
  Vendor foo = new Vendor();
  foo.myMethod(...)
}

这是我在运行代码时遇到的错误

Program.cs(76,13): error CS0246: The type or namespace name 'Vendor' could not be found (are you missing a using directive or an assembly reference?) [/../../MyCSharp/MyCSharp.csproj]
Program.cs(76,36): error CS0246: The type or namespace name 'Vendor' could not be found (are you missing a using directive or an assembly reference?) [/../../MyCSharp/MyCSharp.csproj]

标签: c#c++shared-libraries

解决方案


推荐阅读