static-julia icon indicating copy to clipboard operation
static-julia copied to clipboard

Passing command line arguments

Open TransGirlCodes opened this issue 7 years ago • 1 comments

Hi,

I've just tried to make a binary which accepts command line arguments and I get segfaults which has led me to notice:

In hello.jl:

Base.@ccallable function julia_main(ARGS::Vector{String})::Cint
    println("hello, world")
    @show f()
    println(lineplot(1:10, (1:10).^2))
    return 0
end

So I should expect to accept ARGS and pass it through to use with say ArgParse.jl. However, when I look at program.c:

int main(int argc, char *argv[])
{
    intptr_t v;

    // Initialize Julia
    uv_setup_args(argc, argv); // no-op on Windows
    libsupport_init();
    jl_options.image_file = "libhello";
    julia_init(JL_IMAGE_CWD);

    // Do some work
    julia_main();

    // Cleanup and graceful exit
    jl_atexit_hook(0);
    return 0;
}

Nothing is passed to julia_main when it is invoked - perhaps why I'm getting segfault!? So does the call of julia_main() need to be altered to accept some arguments? If so, how?

TransGirlCodes avatar Nov 08 '17 16:11 TransGirlCodes

I've just had a look in procram2.c and have seen that it converts UTF16 to UTF8 and builds an array of strings, for passing into julia_main, is this ok to simply copy into program.c (including the conditional windows dependent bit)?

(I know program2 is supposed to do somethings differently to program one regarding including a binary rather than loading a dl (although I can't see where). So I'm hesitant to just blindly copy anything in program2.c.)

TransGirlCodes avatar Nov 08 '17 16:11 TransGirlCodes