Creating a Julia Executable

I did this yesterday, but only started the blog today...

It is possible to create an executable file from a Julia script, with a little bit of effort. Basically, we need to create a Julia package project, and then use the PackageCompiler library to turn this into an executable: 

Process to create a Julia package

  1. Launch an interactive julia session
  2. Press the "]" key, the Julia prompt will be replaced with a pkg prompt:
  3. (@1.4) pkg>
  4. Type "generate <packagename>" This will create a new package with the given name. In doing so, it will create a directory with the same name, which will include a "src" subdirectory, and a Project.toml file which describes the project to Julia
  5. Activate the project by typing "activate <packagename>"
  6. Add any and all dependencies used by the project. This is done via the "add <package>" command, which can accept more than one package name at a time. This will update the "[dep]" section of Package.toml, and create/modify the Manifest.toml file.

Process to compile the script
  1. From a regular Julia prompt, type
    using PackageCompile
    create_app("<PackageName>", "<PackageName>Compiled", force=true)
  2. This will create a new directory, which will contain a "bin" subdirectory. The executable will be in this subdirectory
Some notes
  1. Julia becomes quite anal about loading symbols from C libraries when compiled this way. Basically, trying to store the open library and/or symbols globally doesn't work. The workaround I have found is to pass the open library around between Julia functions, and have each function extract whatever symbols they need.
  2. This is actually a standard problem when we load non-local modules, it turns out. For a general library wrapper, where we don't want to pass the library betweene functions, it appears that making the call to Libdl.dlopen at the top of each function does not introduce any appreciable overhead.

Comments

Popular posts from this blog

Creating a Node-Node Connectivity Array

Creating an Element-Element Connectivity Array