# Ccall of entry point name vs tuple of entry point and library

**URL:** https://discourse.julialang.org/t/ccall-of-entry-point-name-vs-tuple-of-entry-point-and-library/133209
**Category:** Internals & Design
**Tags:** question
**Created:** [October 16, 2025, 3:46pm UTC](https://discourse.julialang.org/t/ccall-of-entry-point-name-vs-tuple-of-entry-point-and-library/133209 "2025-10-16T15:46:28Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![dmbates](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dmbates/32/44_2.png) [@dmbates](https://discourse.julialang.org/u/dmbates)
#### Post date: [October 16, 2025, 3:46pm UTC](https://discourse.julialang.org/t/ccall-of-entry-point-name-vs-tuple-of-entry-point-and-library/133209/1 "2025-10-16T15:46:29Z")

</div>

As background, I have been working on modifying some of the `RCall.jl` code to isolate the boxing/unboxing code for R’s internal representations of objects. The idea is to write Julia code that can be compiled to a shared library and called from R.

I spent an inordinate amount of time fussing about how to determine the exact version of the libR shared library (e.g. `libR.so`) in use by the R process that loads the Julia code. Then I re-read the documentation for Julia’s ccall (Pro Tip: When you are wondering how something works, try reading the documentation) and realized that I could call, e.g. the C function `Rf_xlength`, which returns the length of an R object, as `len = ccall(:Rf_xlength, my_R_object)` instead of `len = ccall((:Rf_xlength, libR), my_R_object)`.

And it works! (One of the delightful things about programming in Julia is how often “it just works”.) So my question is, am I giving up performance by specifying only the entry point. I haven’t tracked down the code that implements this yet but I imagine that there is some kind of lookup through the entry point names in the currently loaded shared libraries. Are the results cached so that further calls to `Rf_xlength` don’t require the lookup?

---

<div class="post-metadata">

### Author: ![xal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xal/32/215106_2.png) [@xal](https://discourse.julialang.org/u/xal)
#### Post date: [October 16, 2025, 5:02pm UTC](https://discourse.julialang.org/t/ccall-of-entry-point-name-vs-tuple-of-entry-point-and-library/133209/2 "2025-10-16T17:02:36Z")

</div>

You aren’t giving up any performance, but you may sacrifice easy compatibility with Windows, which doesn’t have a “default” handle for us to search for symbols in.

---

<div class="post-metadata">

### Author: ![dmbates](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dmbates/32/44_2.png) [@dmbates](https://discourse.julialang.org/u/dmbates)
#### Post date: [October 16, 2025, 8:39pm UTC](https://discourse.julialang.org/t/ccall-of-entry-point-name-vs-tuple-of-entry-point-and-library/133209/3 "2025-10-16T20:39:48Z")

</div>

Any suggestions of how to handle the situation in Windows? In R I can evaluate `R.home()` and get the directory whose subdirectory `lib` contains the `libR` of interest, but I feel that somehow getting that information to the Julia shared library would involve a lot of contortions.

---

<div class="post-metadata">

### Author: ![sgaure](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sgaure/32/14779_2.png) [@sgaure](https://discourse.julialang.org/u/sgaure)
#### Post date: [October 17, 2025, 7:30pm UTC](https://discourse.julialang.org/t/ccall-of-entry-point-name-vs-tuple-of-entry-point-and-library/133209/4 "2025-10-17T19:30:43Z")

</div>

Perhaps you can loop through the `Libc.Libdl.dllist()` and find the R library there? Then pick up the pointer with `dlsym` (e.g. in ` __init__ `), and use that in the `ccall`?
