Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Julia: check whether c library exists

Tags:

julia

Is there a way to check whether a c library can be found by the system?

I tried to use a try catch block on a library call to test whether it exists, but that actually kills the program.

try
    ccall( (:func, "libfoo"), Bool, () )
catch
    println("This line is never called. Ever")
end

The associated error is:

ERROR: error compiling anonymous: could not load module libfoo: libfoo: cannot open shared object file: No such file or directory
like image 256
Mageek Avatar asked Jul 29 '14 17:07

Mageek


1 Answers

You could look before you leap using find_library:

julia> find_library(["libc"])
"libc"

julia> find_library(["libfoo"])
""

where you'll get the empty string if not found.

julia> help(find_library)
INFO: Loading help data...
Base.find_library(names, locations)

   Searches for the first library in "names" in the paths in the
   "locations" list, "DL_LOAD_PATH", or system library paths (in
   that order) which can successfully be dlopen'd. On success, the
   return value will be one of the names (potentially prefixed by one
   of the paths in locations). This string can be assigned to a
   "global const" and used as the library name in future
   "ccall"'s. On failure, it returns the empty string.
like image 190
DSM Avatar answered Oct 19 '22 18:10

DSM