Trouble running CppSharp through Mono (CppSharp.Parser.CLI.dll)

643 views
Skip to first unread message

kiro...@gmail.com

unread,
Jan 21, 2016, 12:17:12 PM1/21/16
to CppSharp
I've gotten an implementation up and running of the entire process.
- I use the pre-compiled CppSharp binaries provided on GitHub
- Making a native C++ dll and headers for my code
- Created a C# application using the CppSharp.ILibrary interface to create the binding files

This process works perfectly when on Windows and running the C# application natively through .NET. But if I attempt to execute the process through Mono I get this error.

'<Module>:_getFiberPtrId ()' in assembly 'CppSharp.Parser.CLI.dll' contains native code that cannot be executed by Mono in modules loaded from byte arrays. The assembly was probably created using C++/CLI.

I get the same error when trying to run the process on Linux which requires Mono to execute the above code.

I assume this is something with my setup, or that I will be required to compile the CppSharp binaries manually for each operating system. Any advice would be appreciated, thank you for your help.

- Chase

João Matos

unread,
Jan 21, 2016, 12:52:28 PM1/21/16
to kiro...@gmail.com, CppSharp

On Thu, Jan 21, 2016 at 5:17 PM, <kiro...@gmail.com> wrote:
This process works perfectly when on Windows and running the C# application natively through .NET.  But if I attempt to execute the process through Mono I get this error.


You are correct, that assembly was compiled using C++/CLI. 

We also support a non-default (on Windows) configuration that uses C# instead of C++/CLI for the parser bindings, you can try to link against 'CppSharp.Parser.CSharp.dll' instead, though I've not personally tested CppSharp with Mono on Windows. Let me know how that works out.

About running on Linux, you are correct again. You need a Linux-specific binary, though sadly we do not package them automatically even though we run already do builds against every commit. You can see the specifics of how we build CppSharp for OSX and Linux here: https://github.com/mono/CppSharp/blob/master/.travis.yml

--
João Matos

kiro...@gmail.com

unread,
Jan 21, 2016, 1:52:40 PM1/21/16
to CppSharp, kiro...@gmail.com
Thank you for your help. I've been doing more digging into this and I think I'm beginning to understand. If you don't mind could you confirm if I'm correct in these assumptions?

The pre-build Windows binaries are built against the C++/CLI Parser. This dll is a mixed-mode assembly, which is why only the native .NET is able to run them.

As C++/CLI is only able to be compiled through MSVS, the Linux and Mac versions use the CSharp parser.

CppSharp uses LLVM and Clang, which are native C++ libraries. This is why the project needs compiled for each platform, even though most of CppSharp is written in C#.

I think I will go ahead and see if I'm able to compile and run the CppSharp project using the CSharp parser, I will let you guys know if I have success.

Out of curiosity, as test builds are already being compiled for each platform, is it possible that they may provide the binaries in the future? Or if not, would anyone appreciate if someone like myself build and posted them somewhere?

Again thank you for your help.

kiro...@gmail.com

unread,
Jan 21, 2016, 2:11:20 PM1/21/16
to CppSharp, kiro...@gmail.com
Just as a confirmation, I was able to compile CppSharp using CppSharp.Parser.CSharp and was able to run in on Windows just fine. This also allowed me to run CppSharp through Mono without issue.

To do the above I needed to recompile the CppSharp dlls, making sure to change any references in the VS solution from CppSharp.Parser.CLI to CppSharp.Parser.CSharp.

João Matos

unread,
Jan 21, 2016, 3:36:24 PM1/21/16
to Kiro Neem, CppSharp
On Thu, Jan 21, 2016 at 6:52 PM, <kiro...@gmail.com> wrote:

The pre-build Windows binaries are built against the C++/CLI Parser.  This dll is a mixed-mode assembly, which is why only the native .NET is able to run them.

As C++/CLI is only able to be compiled through MSVS, the Linux and Mac versions use the CSharp parser.

That's right.
 
CppSharp uses LLVM and Clang, which are native C++ libraries.  This is why the project needs compiled for each platform, even though most of CppSharp is written in C#.

I think I will go ahead and see if I'm able to compile and run the CppSharp project using the CSharp parser, I will let you guys know if I have success.

Out of curiosity, as test builds are already being compiled for each platform, is it possible that they may provide the binaries in the future?  Or if not, would anyone appreciate if someone like myself build and posted them somewhere?

Yes, it's possible. Basically we need to archive the needed libraries after the build in the Travis bot and upload them to Github automatically, like we already do for AppVeyor CI. If you'd like to help with that, it'd be much appreciated.


On Thu, Jan 21, 2016 at 7:11 PM, <kiro...@gmail.com> wrote:
Just as a confirmation, I was able to compile CppSharp using CppSharp.Parser.CSharp and was able to run in on Windows just fine.  This also allowed me to run CppSharp through Mono without issue.

To do the above I needed to recompile the CppSharp dlls, making sure to change any references in the VS solution from CppSharp.Parser.CLI to CppSharp.Parser.CSharp.

 Great to hear you've found out a way to do it.

Another way is to go to "build/Parser.lua" and change the 'SetupParser' function to always call 'SetupCSharpParser'.


--
João Matos
Reply all
Reply to author
Forward
0 new messages