On Wednesday, July 8, 2015 at 3:03:39 PM UTC+3, Milan Bouchet-Valat wrote:
>
> Le mercredi 08 juillet 2015 à 04:56 -0700, Panagiotis Mamatsis a écrit
> :
> > On Wednesday, July 8, 2015 at 2:45:17 PM UTC+3, Milan Bouchet-Valat
> > wrote:
> > > Le mercredi 08 juillet 2015 à 03:28 -0700, Panagiotis Mamatsis a
> > > écrit
> > > :
> > > > Hello to everyone,
> > > > i am a n00b in Julia language and i am trying to understand
> > > the
> > > > way to call code written in C via shared libraries. I have
> > > started
> > > > with a 'small scale' case into which i am trying to call a
> > > function
> > > > which returns void but accepts a pointer to an Integer. When i
> > > > perform the call from a Julia script the number returned back is
> > > "0"
> > > > and not the one i am expecting...when i am calling the C function
> > > the
> > > > argument i am supplying is Ptr{Cint}. Can somebody please explain
> > >
> > > > what i am missing ?
> > > Showing the code you tried would be helpful.
> > >
> > > Anyway, this precise case is documented. Let us know whether that's
> > >
> > > enough to fix your problem. For 0.3:
> > > http://docs.julialang.org/en/release-0.3/manual/calling-c-and
> > > -fortran
> > > -code/#passing-pointers-for-modifying-inputs
> > >
> > > For 0.4 (a bit different):
> > > http://docs.julialang.org/en/latest/manual/calling-c-and-fortran
> > > -code/#passing-pointers-for-modifying-inputs
> > >
> > >
> > > Regards
> > Hi Milan and thank you so much for your quick response. I didn't
> > keyed in my source code because i don't want to burden people by
> > reading source code. :)
> > Anyway...here is my little Julia script:
> >
> > mynumber=convert(Cint, 0)
> > ccall((:funct1, "./libtest.so"), Void, (Ptr{Cint},), &mynumber)
> > println(mynumber)
> >
> > My C code:
> > void funct1(int *i){
> > *i=5;
> > }
> >
> > The environment i am using is Linux (Ubuntu flavor) and the version
> > of Julia is 0.3.10.
> >
> > I have read the documentation of Julia for callign external functions
> > of C and Fortran but it seems that i am missing something !
> You probably missed the interesting part in the middle of the long
> docs. In the link I gave you, you'll see that something like this
> should work:
>
> mynumber = Cint[0]
> ccall((:funct1, "./libtest.so"), Void, (Ptr{Cint},), &mynumber)
>
> The reason is that an immutable (like an Int) has no 'individual'
> existence nor storage: 5 is always equal to 5, and it doesn't make
> sense to change it to be equal to 3. So you need to create a one
> -element array and modify this location.
>
>
> Regards
>
Hi Milan,
following up on your reply, i have tried this but i am getting a
conversion error as following:
`convert` has not method matching convert(::Type{Int32}, ::Array{Int32,1})
Any suggestions ?
Best regards and
thanks in advance,
Panos.