C# 嵌入C++;Linux上的应用
问题的背景/描述 我试图运行C++脚本作为我的C++应用程序的一部分,我在DEBIAN-9 Linux中编译。但是,我的应用程序由于来自mono运行时的错误而崩溃 我已经从Debian存储库安装了mono,甚至用源代码编译的mono版本做了同样的实验。c代码,我使用C# 嵌入C++;Linux上的应用,c#,c++,mono,mono-embedding,C#,C++,Mono,Mono Embedding,问题的背景/描述 我试图运行C++脚本作为我的C++应用程序的一部分,我在DEBIAN-9 Linux中编译。但是,我的应用程序由于来自mono运行时的错误而崩溃 我已经从Debian存储库安装了mono,甚至用源代码编译的mono版本做了同样的实验。c代码,我使用mcs-t:library*.cs编译成了一个dll。尝试运行我的应用程序时,它会崩溃,并出现以下错误: * Assertion at object.c:116, condition `is_ok (error)' not met,
mcs-t:library*.cs
编译成了一个dll。尝试运行我的应用程序时,它会崩溃,并出现以下错误:
* Assertion at object.c:116, condition `is_ok (error)' not met,
function:mono_runtime_object_init, (null) assembly:/usr/lib/mono/4.5/mscorlib.dll type:TypeInitializationException member:(null)
=================================================================
Native Crash Reporting
=================================================================
Got a SIGABRT while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.
=================================================================
=================================================================
Native stacktrace:
=================================================================
0x7f80f3fb9ccb - /usr/lib/libmonosgen-2.0.so.1 :
0x7f80f3fba069 - /usr/lib/libmonosgen-2.0.so.1 :
0x7f80f3f4479f - /usr/lib/libmonosgen-2.0.so.1 :
0x7f80f3fb9273 - /usr/lib/libmonosgen-2.0.so.1 :
0x7f80f3e5b510 - /lib/x86_64-linux-gnu/libpthread.so.0 :
0x7f80f3994081 - /lib/x86_64-linux-gnu/libc.so.6 : gsignal
0x7f80f397f535 - /lib/x86_64-linux-gnu/libc.so.6 : abort
0x7f80f3ea6f94 - /usr/lib/libmonosgen-2.0.so.1 :
0x7f80f41935f6 - /usr/lib/libmonosgen-2.0.so.1 :
0x7f80f41ae2db - /usr/lib/libmonosgen-2.0.so.1 :
0x7f80f41ae89d - /usr/lib/libmonosgen-2.0.so.1 : monoeg_assertion_message
0x7f80f40bf357 - /usr/lib/libmonosgen-2.0.so.1 : mono_runtime_object_init
0x561bf41542e0 - ./mono_test :
0x7f80f3980bbb - /lib/x86_64-linux-gnu/libc.so.6 : __libc_start_main
0x561bf415412a - ./mono_test :
.... more details follow ....
最小示例
C++代码(main .CPP):
CMakeLists:
cmake_minimum_required(VERSION 3.9)
project(mono_test)
set (CMAKE_CXX_FLAGS "-std=c++17")
file(GLOB SOURCES *.cpp)
add_executable(mono_test ${SOURCES})
INCLUDE(FindPkgConfig)
PKG_SEARCH_MODULE(MONO REQUIRED mono-2)
target_include_directories(mono_test SYSTEM PRIVATE ${MONO_INCLUDE_DIRS})
target_link_libraries(mono_test ${MONO_LIBRARIES})
我一整天都在阅读不同的教程,尝试不同的事情(包括从源代码重新编译mono),但都没有成功。我没有嵌入mono的经验,也不知道如何解释或调试崩溃报告。
任何帮助都将不胜感激
using System;
namespace Test {
class Hello {
Hello() {
Console.WriteLine("Hello constructor.");
}
void Update() {
Console.WriteLine("Yay update is called.");
}
}
}
cmake_minimum_required(VERSION 3.9)
project(mono_test)
set (CMAKE_CXX_FLAGS "-std=c++17")
file(GLOB SOURCES *.cpp)
add_executable(mono_test ${SOURCES})
INCLUDE(FindPkgConfig)
PKG_SEARCH_MODULE(MONO REQUIRED mono-2)
target_include_directories(mono_test SYSTEM PRIVATE ${MONO_INCLUDE_DIRS})
target_link_libraries(mono_test ${MONO_LIBRARIES})