Skip to content

Commit

Permalink
Added notes on closing a library. (JuliaLang#23489)
Browse files Browse the repository at this point in the history
* Added notes on closing a library.

Fixes 23459

* shorten line lengths

* "can"/"could" consistency.
  • Loading branch information
tuckermcclure authored and KristofferC committed Aug 29, 2017
1 parent 9089b13 commit 15fb3db
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions doc/src/manual/calling-c-and-fortran-code.md
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,25 @@ mylibvar = Libdl.dlopen("mylib")
ccall(@dlsym("myfunc", mylibvar), Void, ())
```

## Closing a Library

It is sometimes useful to close (unload) a library so that it can be reloaded.
For instance, when developing C code for use with Julia, one may need to compile,
call the C code from Julia, then close the library, make an edit, recompile,
and load in the new changes. One can either restart Julia or use the
`Libdl` functions to manage the library explicitly, such as:

```julia
lib = Libdl.dlopen("./my_lib.so") # Open the library explicitly.
sym = Libdl.dlsym(lib, :my_fcn) # Get a symbol for the function to call.
ccall(sym, ...) # Use the symbol instead of the (symbol, library) tuple (remaining arguments are the same).
Libdl.dlclose(lib) # Close the library explicitly.
```

Note that when using `ccall` with the tuple input
(e.g., `ccall((:my_fcn, "./my_lib.so"), ...)`), the library is opened implicitly
and it may not be explicitly closed.

## Calling Convention

The second argument to [`ccall`](@ref) can optionally be a calling convention specifier (immediately
Expand Down

0 comments on commit 15fb3db

Please sign in to comment.