I'd like to be able to compile a C/C++ library so that it runs within a managed runtime in the CLR. There are several tools for doing this with the JVM (NestedVM, LLJVM, etc) but I can't seem to find any for the CLR. Has anyone tried doing this?
+2
A:
If you have the source code and it compiles under Visual C++ compiler, then from 2005 onwards you can switch the /clr flag and it should compile it to IL rather than a native binary.
Colin Desmond
2010-05-03 18:20:19
Will the code compiled this way be marked as "unsafe"? That is, could it be run within Silverlight?
paleozogt
2010-05-03 18:26:52
From memory I think you get the option of whether you want Safe code or not. Safe is stricter and may require you to do make more changes to your code than Unsafe IL. This link should help http://msdn.microsoft.com/en-us/library/k8d11d4s.aspx
Colin Desmond
2010-05-03 18:29:57
+2
A:
Microsoft already provides such a tool with Visual Studio. The C++ compiler cl.exe
accepts the /clr
option to tell it to generate managed code instead of native code. See the MSDN document How To: Migrate to /clr for information on changing your native project to support managed code.
Rob Kennedy
2010-05-03 18:21:27
Will the code compiled this way be marked as "unsafe"? That is, could it be run within Silverlight?
paleozogt
2010-05-03 18:30:09
Yes, I think it will be marked as unsafe. You may need either `/clr:pure` or `/clr:safe`. I don't really know what the difference is, but you're welcome to post a new question about that here if it hasn't already been asked before. The specific topic of running C++ on Silverlight has been asked here before, but with mixed verdicts; a search will provide links.
Rob Kennedy
2010-05-03 19:00:00
ok, I guess my question was too vague. I'm reasking it here: http://stackoverflow.com/questions/2760549/c-to-bytecode-compiler-for-silverlight-clr
paleozogt
2010-05-03 19:13:39