Hi Stefan, I'm not sure. I guess it might be failing the first time it
tries to map an executable page. You might find some clues on the llvm
mailing list. But the bigger issue is that the msvc debugger won't be very
useful because msvc doesn't know anything about the jit'd object format
(still ELF I think). If you want to use a debugger you should download the
mingw64 tools in readme.windows and use gdb.
On Oct 2, 2014 3:59 AM, "Stefan Babinec" <[email protected]> wrote:

> Thanks Isaiah.
>
> It works.
>
> I also tried to pass Julia's system image to jl_init and with the little
> help
>
> of SetDllDirectory method it works properly when i try to run it in
> console.
>
> *******
> using System.Runtime.InteropServices;
>
> namespace ConsoleApplication1
> {
>     class Program
>     {
>         [DllImport("kernel32.dll", SetLastError = true)]
>         static extern bool SetDllDirectory(string lpPathName);
>
>         [DllImport("libjulia.dll")]
>         static extern void jl_init(string message);
>
>         [DllImport("libjulia.dll")]
>         static extern void jl_eval_string(string message);
>
>         static void Main(string[] args)
>         {
>             SetDllDirectory(@"c:\Users\SB\AppData\Local\Julia-0.3.0\bin\");
>
>             jl_init(@"c:\Users\SB\AppData\Local\Julia-0.3.0\bin\");
>
>             jl_eval_string("print(sqrt(2.0))");
>         }
>     }
> }
> *******
>
> But when I try to run it directly in VS 2103 in (Debug/Release) I get
>
> following error from jl_init:
>
> "System.AccesViolationException.
> Attempted to read or write protected memory. This is often an indication
> that
>
> other memory is corrupt."
>
> Small piece from :
>
> http://social.msdn.microsoft.com/Forums/en-US/8789ea67-fbc5-4a7b-a4eb-d4a8a050d5c1/attempt-to-read-or-write-protected-memory-this-is-often-an-indicating-that-other-memory-is-corrupt
>
> "This issue shouldn't happen in managed code. The problem is typically
> caused by some component (typically unmanaged, but can also be a bad
> P/Invoke signature) that corrupts the program's memory."
>
> I tried also to suppress this exception by disabling
> "Tools menu ->Options -> Debugging -> General -> Suppress JIT optimization
> on module load"
> but with no success ?
>
> Any ideas ?
>
> Best regards.
>
> Stefan.
>
> On Wednesday, October 1, 2014 12:16:15 AM UTC+2, Isaiah wrote:
>>
>> The ">" indicates the cmd prompt working directory:
>> ```
>> C:\cmn\Julia-0.3.0>bin\ConsoleApplication2.exe
>> 1.4142135623730951
>> ```
>> Otherwise, try passing the bin path as a char* to jl_init as suggested.
>>
>>
>> On Tue, Sep 30, 2014 at 11:24 AM, Stefan Babinec <[email protected]>
>> wrote:
>>
>>> I've copied exe file directly to julia's bin directory Isaiah.
>>>
>>> And I get the above mentioned error when I try to run it in the bin
>>> directory.
>>>
>>>
>>> On Tuesday, September 30, 2014 4:57:41 PM UTC+2, Isaiah wrote:
>>>>
>>>> Try running it from the Julia directory as `bin\CommandLine2.exe`. This
>>>> is very much a minimal example; for general use, the bin directory should
>>>> be passed as an argument to `jl_init`:
>>>>
>>>> https://github.com/JuliaLang/julia/blob/1ee440bee5035ccb33f82b8a45febd
>>>> dd2f973baa/src/jlapi.c#L70-L73
>>>>
>>>> To go much further than this will really require to dig in to both
>>>> jlapi.c and the general Julia source code. Be aware that dealing with type
>>>> translation and garbage collection are both non-trivial. See also
>>>> `examples/embedding.c` in the julia tree, and several previous discussion
>>>> on the mailing list.
>>>>
>>>> On Tue, Sep 30, 2014 at 9:08 AM, Stefan Babinec <[email protected]>
>>>> wrote:
>>>>
>>>>> Hi Isaiah.
>>>>>
>>>>> I tried and got this error:
>>>>> "System image file " ?l\../lib/julia/sys.ji" not found"
>>>>>
>>>>> System Image sys.ji looks to be on his place and I have no problem
>>>>> running Julia.
>>>>>
>>>>> Thanks.
>>>>>
>>>>>
>>>>> On Tuesday, September 30, 2014 2:03:42 PM UTC+2, Isaiah wrote:
>>>>>>
>>>>>> I should mention that it is necessary to change the project target
>>>>>> CPU from the default Any to x64 or x86 to match the libjulia 
>>>>>> architecture.
>>>>>> On Sep 29, 2014 11:58 PM, "Isaiah Norton" <[email protected]>
>>>>>> wrote:
>>>>>>
>>>>>>> I tried this some time ago during 0.2, so to make sure it still
>>>>>>> works I made a minimal translation of the embedding example to C#:
>>>>>>>
>>>>>>> ```
>>>>>>> using System;
>>>>>>> using System.Runtime.InteropServices;
>>>>>>>
>>>>>>> namespace ConsoleApplication2
>>>>>>> {
>>>>>>>     class Program
>>>>>>>     {
>>>>>>>         [DllImport("libjulia.dll")]
>>>>>>>         static extern void jl_init();
>>>>>>>         [DllImport("libjulia.dll")]
>>>>>>>         static extern void jl_eval_string(string message);
>>>>>>>
>>>>>>>         static void Main(string[] args)
>>>>>>>         {
>>>>>>>             jl_init();
>>>>>>>             jl_eval_string("print(sqrt(2.0))");
>>>>>>>         }
>>>>>>>     }
>>>>>>> }
>>>>>>> ```
>>>>>>>
>>>>>>> I compiled this, copied the binary into `Julia-0.3.0\bin`, and it
>>>>>>> works:
>>>>>>>
>>>>>>> ```
>>>>>>> C:\cmn\Julia-0.3.0>bin\ConsoleApplication2.exe
>>>>>>> 1.4142135623730951
>>>>>>> ```
>>>>>>>
>>>>>>>
>>>>>>> On Mon, Sep 29, 2014 at 4:11 PM, Tobias Knopp <
>>>>>>> [email protected]> wrote:
>>>>>>>
>>>>>>>> yep, I have done this (mostly for fun) before and it works. One
>>>>>>>> needs some experience with P/Invoke of course but this is no magic but
>>>>>>>> similar to our ccall.
>>>>>>>>
>>>>>>>> Cheers,
>>>>>>>>
>>>>>>>> Tobi
>>>>>>>>
>>>>>>>> Am Montag, 29. September 2014 20:52:10 UTC+2 schrieb Stefan
>>>>>>>> Karpinski:
>>>>>>>>>
>>>>>>>>> I assume that you can call C libraries from .NET, right? The C
>>>>>>>>> library for Julia is libjulia – how to call it from C is explained in 
>>>>>>>>> the
>>>>>>>>> embedding docs, calling it from .NET should be similar.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> > On Sep 29, 2014, at 12:37 PM, Guido De Bouver <
>>>>>>>>> [email protected]> wrote:
>>>>>>>>> >
>>>>>>>>> > I have not found the C# examples, but I have not looked for
>>>>>>>>> them. Sorry for that.
>>>>>>>>> >
>>>>>>>>> > So, any help on this, how could we call Julia from .NET ????
>>>>>>>>> >
>>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>
>>

Reply via email to