# Import a dll function in Mathematica?

**URL:** <https://community.wolfram.com/t/import-a-dll-function-in-mathematica/10509>\
**Category:** Questions\
**Tags:** compilation, external-interfaces, import-and-export\
**Created:** [May 10, 2017, 12:18pm UTC](https://community.wolfram.com/t/import-a-dll-function-in-mathematica/10509 "2017-05-10T12:18:31Z")\
**Posts on this page:** 5\
**Page:** 2

<div class="post-metadata">

**Author:** ![alessio211734](https://avatars.discourse-cdn.com/v4/letter/a/91b2a8/32.png) [@alessio211734](https://community.wolfram.com/u/alessio211734)\
**Post date:** [May 15, 2017, 6:38pm UTC](https://community.wolfram.com/t/import-a-dll-function-in-mathematica/10509/21 "2017-05-15T18:38:11Z")

</div>

Sorry for my English. I did a library with LibraryLink. It’s possible avoid every time I startup Mathematica to execute the notebook that compile the dll files and load it to use the imported function?

---

<div class="post-metadata">

**Author:** ![szhorvat](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/szhorvat/32/3531_2.png) [@szhorvat](https://community.wolfram.com/u/szhorvat)\
**Post date:** [May 15, 2017, 8:03pm UTC](https://community.wolfram.com/t/import-a-dll-function-in-mathematica/10509/22 "2017-05-15T20:03:44Z")

</div>

You can compile it once, then create a plain text `.m` file (a package file) that contains all the `LibraryFunctionLoad` commands for it. Then you can simply load that file using `Get`.

---

<div class="post-metadata">

**Author:** ![anon\_91240867](https://avatars.discourse-cdn.com/v4/letter/a/8baadc/32.png) [@anon\_91240867](https://community.wolfram.com/u/anon_91240867)\
**Post date:** [May 16, 2017, 12:50pm UTC](https://community.wolfram.com/t/import-a-dll-function-in-mathematica/10509/23 "2017-05-16T12:50:10Z")

</div>

Do you mean ?

> **[Setting Up External Functions to Be Called from the Wolfram Language—Wolfram...](https://reference.wolfram.com/language/tutorial/SettingUpExternalFunctionsToBeCalledFromTheWolframLanguage.html)**
>
> If you have a function defined in an external program, then what you need to do in order to make it possible to call the function from within the Wolfram Language is to add appropriate Wolfram Symbolic Transfer Protocol (WSTP) code that passes...

that allows a two way exchange over a unix (file/stream) socket called a LiinkObject (which also is used for remote kernels, remote kernels speak the same link language on the socket, per say)

HOWEVER you said memory and that depends. you can copy the data over the link (i’m unsure if your avoiding that so will continue …)

You could return a unix shared memory location to a mathematica program that can directly read user space memory. if it’s CL video card data then that memory is shared.

BETTER: is copy only a filename over the link containing data which is on a memory drive made in shared memory. now your (other side, a notebook) can poke (bytes) of data from the file after opening file without ever the whole file being copied over the link

On a modern system files are cached very well and if used temporarily never are committed to (slow memory or drive), so you really don’t need the trouble of insuring file is located on a shared memory drive I think.

In the Unix world there is an old saying: “everything is a file”.

---

<div class="post-metadata">

**Author:** ![alessio211734](https://avatars.discourse-cdn.com/v4/letter/a/91b2a8/32.png) [@alessio211734](https://community.wolfram.com/u/alessio211734)\
**Post date:** [May 18, 2017, 1:33pm UTC](https://community.wolfram.com/t/import-a-dll-function-in-mathematica/10509/24 "2017-05-18T13:33:04Z")

</div>

Hello,  
I tried to build a package that load a dll but when I call the package function I get the following error (screenshot with error)

 ![error.png](https://global.discourse-cdn.com/wolfram/original/3X/c/2/c2088a4c816c5a32af759e1e664ae69a4c820a95.png)

If I tried to copy the body of package function on notebook and it work.

This is my package file “meshAlgorithms.m”

```
BeginPackage["meshAlgorithms`"]

AdjVertex::usage = "adjVert=adjVertex[v, f] returns a list adj vertex";
Begin["`Private`"]

partitionRagged[v_List,l_?VectorQ]:=MapThread[Take[v,{#1,#2}]&,Module[{a=Accumulate[l]},{a-l+1,a}]]
unpack[packed_]:=With[{len=Round@First[packed]},partitionRagged[packed[[len+2;;All]],Round[packed[[2;;len+1]]]]]

AdjVertex[v_,f_]:=Module[{l={},lib,vertexAdj},
lib=FindLibrary["vertexAdj"];
vertexAdj=LibraryFunctionLoad[lib,"vertexAdj",{{Real,2},{Integer,2}},{Integer,1}];
(unpack[vertexAdj[vdata,idata]])];

End[]
EndPackage[]

```

---

<div class="post-metadata">

**Author:** ![alessio211734](https://avatars.discourse-cdn.com/v4/letter/a/91b2a8/32.png) [@alessio211734](https://community.wolfram.com/u/alessio211734)\
**Post date:** [May 18, 2017, 6:29pm UTC](https://community.wolfram.com/t/import-a-dll-function-in-mathematica/10509/25 "2017-05-18T18:29:49Z")

</div>

Sorry I wrong to call function vertexAdj[vdata,idata] instead of vertexAdj[v,f]…

[Previous page](https://community.wolfram.com/t/import-a-dll-function-in-mathematica/10509.md?page=1)
