Creating a Julia Executable
I did this yesterday, but only started the blog today...
Process to create a Julia package
Process to compile the script
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:
- Launch an interactive julia session
- Press the "]" key, the Julia prompt will be replaced with a pkg prompt:
- (@1.4) pkg>
- 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
- Activate the project by typing "activate <packagename>"
- 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.
- From a regular Julia prompt, type
using PackageCompile
create_app("<PackageName>", "<PackageName>Compiled", force=true) - This will create a new directory, which will contain a "bin" subdirectory. The executable will be in this subdirectory
- 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.
- 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
Post a Comment