【发布时间】:2011-05-05 17:22:11
【问题描述】:
是否可以在 Ubuntu 中从 mono 调用 g++ 可执行文件的函数?请注意,在 Ubuntu 操作系统中编译的 C++ 和 C# 代码。
C++应用源码:
#include <stdlib.h>
static int32_t Sum(int32_t a, int32_t b){
return a + b;
}
/*
*
*/
int main(int argc, char** argv) {
return (EXIT_SUCCESS);
}
C#单声道应用源码:
using System;
using System.Runtime.InteropServices;
namespace MonoCsTest
{
class MainClass
{
[DllImport("/home/.../MonoCsTest/bin/Debug/testcpp")]
public static extern Int32 Sum(Int32 a, Int32 b);
public static void Main (string[] args)
{
Console.WriteLine (" 5 + 6 = " + Sum(5,6));
}
}
}
这会抛出DllNotFoundException
【问题讨论】:
-
我有一个共享库 (.so) here 的示例。这有帮助吗?
-
感谢那个 dtb,但我的问题是
DllNotFoundException!!!我确定文件路径是正确的!我想这一定是一个愚蠢的问题! :)
标签: c# c++ ubuntu mono pinvoke