I want to make an app for my Julia package named “MyApp”. Below is the simplified usage of MyApp in Julia:
using MyApp, DataFrames, CSV, Distributions
a = CSV.read("data.csv", Dataframe)
b = "y=x"
c = 1
d = Normal(c,c)
e = function1(a)
f = function2(b)
Following the documentation of PackgeCompiler.jl, I cloned MyApp from Github, and ran create_app("MyApp", "MyAppCompiled"). Now I have a folder “MyAppComplied” with sub-folder “bin”,“lib” and “share”, and there are two exe files in the “bin” folder named MyApp and julia.
Sorry I have no experience with this, and my question is how to use MyApp to do my previous analysis as shown in above code?
You’ll need to have a “main” function in your package; according to the usage example you gave, it could look like the following:
function julia_main()::Cint
# Get arguments from the command-line
# (you'll probably want to handle errors, e.g. in case users don't
# provide enough arguments)
filename = ARGS[1] # data file provided as argument, instead of hardcoding "data.csv"
param = parse(Int, ARGS[2]) # numeric parameter instead of hardcoding c=1
# Use your package to do what you need to do
a = CSV.read(filename, Dataframe)
b = "y=x"
c = param
d = Normal(c,c)
e = function1(a)
f = function2(b)
# Display results in the end
@show f
# Return a success/error code
# 0 indicates that everything went well
# any other value indicates an error
return 0
end
After having created the app using PackageCompiler, the executable is found in MyAppCompiled/bin/MyApp. The way you run it will depend a bit on the OS you’re using, but the command-line would look like this: