You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu(Mono环境)下C#程序如何引用MATLAB Runtime库?

How to Use MATLAB Runtime with C# & Mono on Ubuntu

Hey there, let's tackle your problem head-on—this is totally feasible, but the key issue here is that you're trying to use the Windows-specific MWArray.dll on Linux, which won't work. Linux uses shared object files (.so) under the hood, and MATLAB Runtime provides a Linux-compatible .NET binding for this. Here's how to fix it step by step:

1. Confirm Version Compatibility First

Before anything else, make sure the MATLAB version you used to build your C# program matches exactly with the MATLAB Runtime installed on your Ubuntu machine. Even minor version mismatches (like R2023a vs R2023b) can cause library not found errors.

You can check your MATLAB Runtime version by navigating to its default install path:

ls /usr/local/MATLAB/MATLAB_Runtime/

This will show you folders named like R20XXx (e.g., R2023a)—that's your Runtime version.

2. Replace the Windows MWArray.dll with Linux's Compatible Version

Windows' MWArray.dll isn't built for Linux. Instead, grab the Linux-compatible MWArray.dll directly from your installed MATLAB Runtime. It's located in the extern/dotnet directory of your Runtime installation. For example:

/usr/local/MATLAB/MATLAB_Runtime/R20XXx/extern/dotnet/netstandard2.0/MWArray.dll

Copy this file to your C# project's reference folder, replacing the Windows version you were using before.

3. Configure Library Paths for Mono

Mono needs to find MATLAB Runtime's underlying shared libraries (.so files) to run your program. Set the LD_LIBRARY_PATH environment variable to include the necessary Runtime directories:

Temporary Setup (for current terminal session)

Run this command before launching your program:

export LD_LIBRARY_PATH=/usr/local/MATLAB/MATLAB_Runtime/R20XXx/runtime/glnxa64:/usr/local/MATLAB/MATLAB_Runtime/R20XXx/bin/glnxa64:/usr/local/MATLAB/MATLAB_Runtime/R20XXx/sys/os/glnxa64:$LD_LIBRARY_PATH

Permanent Setup (for all terminal sessions)

Add the above line to your ~/.bashrc or ~/.profile file, then run:

source ~/.bashrc

This ensures the path is set every time you open a terminal.

4. Compile & Run Your C# Program with Mono

Compile

Use Mono's C# compiler (mcs) and reference the Linux version of MWArray.dll:

mcs YourProgram.cs -r:/path/to/your/copied/MWArray.dll

Replace YourProgram.cs with your actual C# file name, and update the path to the copied MWArray.dll.

Run

Launch the compiled executable with Mono:

mono YourProgram.exe

5. Troubleshooting Common Issues

  • Still getting "library not found" errors? Double-check that LD_LIBRARY_PATH includes all three directories mentioned earlier, and that your Runtime version matches your program's MATLAB version.
  • Mono compatibility issues? Ensure your Mono version supports the .NET Framework version your C# program was built with. For example, if you used .NET Framework 4.8, you'll need Mono 6.12 or newer.
  • Permission issues? Make sure you have read access to the MATLAB Runtime directories and the copied MWArray.dll.

内容的提问来源于stack exchange,提问作者Roshan Vincent

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 11:49:51