Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
Mono organizations on
GitHub to continue tracking issues. Bugzilla will remain
available for reference in read-only mode. We will continue to work
on open Bugzilla bugs, copy them to the new locations
as needed for follow-up, and add the new items under Related
Our sincere thanks to everyone who has contributed on this bug
tracker over the years. Thanks also for your understanding as we
make these adjustments and improvements for the future.
Please create a new report on
GitHub or Developer Community with
your current version information, steps to reproduce, and relevant error
messages or log files if you are hitting an issue that looks similar to
this resolved bug and you do not yet see a matching new report.
Created attachment 14250 [details]
C code for embedding CS
This is not a bug report but a cry for help.
I am trying to use a C program to call a CS function which uses a vb dll (created on Windows). The CS code with the dll works fine when compiled with mcs.
I think I have followed the steps to embed the code into C. When I compile the C code I get a few innocuous warnings
test1dtl.c:14:21: warning: initialization makes pointer from integer without a cast [enabled by default]
test1dtl.c:22:2: warning: passing argument 3 of ‘mono_runtime_invoke’ from incompatible pointer type [enabled by default]
/usr/lib/pkgconfig/../../include/mono-2.0/mono/metadata/object.h:222:1: note: expected ‘void **’ but argument is of type ‘struct MonoArray *’
test1dtl.c:24:17: warning: initialization makes pointer from integer without a cast [enabled by default]
When I run the executable created I get segmentation fault
Debug info from gdb:
Could not attach to process. If your uid matches the uid of the target
process, check the setting of /proc/sys/kernel/yama/ptrace_scope, or try
again as the root user. For more details, see /etc/sysctl.d/10-ptrace.conf
ptrace: Operation not permitted.
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.
Aborted (core dumped)
My C code is attached. The make command I am using is gcc -o a.x test1dtl.c `pkg-config --cflags --libs mono-2` -lm
Please let me know what I am doing wrong.
Instead of embedding the Mono C runtime which is error prone you might like to take a look at CppSharp (https://github.com/mono/CppSharp), which might provide a slightly easier way to interop between your native and managed code.
If you'd still like to try embedding Mono, then we need a slightly better stack trace to figure out what's going wrong. You'll need to compile the Mono runtime with debug info, which you can do with:
CFLAGS="-O0 -g" ./autogen.sh --prefix=`pwd`/build
Then link your program with the compiled Mono library and try running it under GDB again.