Le dimanche 27 décembre 2015 à 10:24 -0800, axsk a écrit :
> I want to ccall a file which is relative to the packages dir, but
>
> const path = joinpath(@__FILE__,"..","bin","lib.so")
> ccall((:fn, path),...)
>
> fails with the same error as above
> first argument not a pointer or valid constant expression
>
> How can I fix this?
I'm not sure whether the compiler should be able to consider 'path' as
a compile-time constant, but you can use dynamic linking for that:
julia> path = "/usr/lib64/libc.so.6"
julia> lib = Libdl.dlopen(path)
Ptr{Void} @0x00007fe64cb46000
julia> ccall(Libdl.dlsym(lib, :clock), Int32, ())
3179878
You can also use BinDeps.jl to manage the library, and it will define
automatically the required constant. See for example how _jl_libcairo
is used in deps/build.jl and src/Cairo.jl at
https://github.com/JuliaLang/Cairo.jl/
(The trick is that a deps/deps.jl file is generated on install, and it
contains the path as a string constant.)
Regards
> On Monday, November 30, 2015 at 7:08:09 PM UTC+1, Felix wrote:
> > Hi,
> >
> > I can't seem to get a hang of how to call a C function that
> > essentially needs a string containing the path to a file as input,
> > but it is declared as a structure containing a const char. The
> > setup is the following (SPICE library):
> >
> > I want to call the function:
> >
> > void furnsh_c ( ConstSpiceChar * file ) { ... }
> >
> > with the structure ConstSpiceChar being defined as:
> >
> > typedef const char ConstSpiceChar;
> >
> > I don't know how to call that from Julia. What I have tried and
> > modified in many ways is the following:
> >
> > immutable ConstSpiceChar
> > x::Ptr{UInt8}
> > end
> >
> > kernel =
> > ConstSpiceChar(pointer("../../../../cspice/kernels/sat317.bsp"))
> >
> > ccall((:furnsh_c , spicelib), Void, (Ptr{ConstSpiceChar},) ,
> > pointer(kernel))
> >
> > Which ends up in an error:
> >
> > LoadError: TypeError: anonymous: in ccall: first argument not a
> > pointer or valid constant expression, expected Ptr{T}, got
> > Tuple{Symbol,ASCIIString}
> >
> > I hope there is an easy solution to this. I am not very skilled in
> > C.
> >
> > Thanks, Felix.
> >
> >
> >