c# - 在 C# 中嵌入 Julia

标签 c# julia embedding

我从 here 中提取了代码与此相关 post在 Github 上,但它对我不起作用。

我运行的是 Windows 10、Visual Studio 2012,我的 julia 目录是 c:\julia-0.4.3\bin。我对代码做了一点小改动以反射(reflect)我的路径:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;

namespace ConsoleApplication1
{
    class Program
    {
        [DllImport("libjulia.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern void jl_init(string julia_home_dir);

        [DllImport("libjulia.dll", CallingConvention = CallingConvention.Cdecl)]
        public static extern void jl_eval_string(string str);

        static void Main(string[] args)
        {
            // Pass

            jl_init(@"C:\Julia-0.4.3\bin");

            // Crash
            jl_eval_string("print(sqrt(2.0))");

        }
    }
}

当我在 Visual Studio 中运行该程序时,我得到: 试图加载格式不正确的程序。 (HRESULT 异常:0x8007000B)

如果我将 ConsoleApplication1.exe 文件复制到 c:\julia-0.4.3\bin 并从 cmd 行运行它,我得到: 未处理的异常:System.BadImageFormatException:尝试加载格式不正确的程序。 (HRESULT 异常:0x8007000B) 在 ConsoleApplication1.Program.jl_init(字符串 julia_home_dir) 在 ConsoleApplication1.Program.Main(String[] args)

是我做错了什么,还是 Windows 10 是罪魁祸首?我对 C# 有点陌生,所以这里可能有一些对于更熟练的程序员来说显而易见的东西。

谢谢!

最佳答案

因为你正在将 32 位库加载到 64 位 exe 中,反之亦然

尝试转到项目属性并关闭“首选 32 位”

关于c# - 在 C# 中嵌入 Julia,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35992240/

相关文章:

c# - Thread.Sleep 还是 Thread.Timer 挂系统?

c# - 如何将类作为可选参数传递给方法?

c# - 正则表达式匹配以单词、数字或罗马数字形式书写的数字

html - 在 HTML 页面中嵌入本地 PDF

c# - LINQ C#的编写方法

types - 类型定义中的嵌套类型参数

julia - 在包代码上使用 Infiltrator.jl 而无需将 Infitrator 添加到 Project.toml

julia - 使用 Julia 通过 n 维中的 n 个点求解非奇异方程组、超空间

css - 自定义字体嵌入在跨浏览器中不起作用

python - pygtk 如何在我的 pygtk GUI 中嵌入外部应用程序