# PackageCompiler.jl does not support ARGS (arguments)?

**URL:** https://discourse.julialang.org/t/packagecompiler-jl-does-not-support-args-arguments/103513
**Category:** General Usage
**Tags:** compilation, argument, package-compiler
**Created:** [September 4, 2023, 3:37pm UTC](https://discourse.julialang.org/t/packagecompiler-jl-does-not-support-args-arguments/103513 "2023-09-04T15:37:06Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Miroslav-Stimac](https://avatars.discourse-cdn.com/v4/letter/m/c89c15/32.png) [@Miroslav-Stimac](https://discourse.julialang.org/u/Miroslav-Stimac)
#### Post date: [September 4, 2023, 3:37pm UTC](https://discourse.julialang.org/t/packagecompiler-jl-does-not-support-args-arguments/103513/1 "2023-09-04T15:37:06Z")

</div>

Hello,

It seems that PackageCompiler does not work with ARGS.  
I tried several ways and none worked:

**CASE 1:**

In precompile\_app.jl:

```julia
MyProgram.julia_main(["CHECK_DATA_1", "DEV"])

```

In MyProgram.jl:

```julia
module MyProgram

	argument_list = ARGS

	println("Length of arguments array: " * string(length(ARGS)))
	println("Content of arguments array: ")

	program_main()
		# My Source Code
	end

    Base.@ccallable function julia_main(ARGS::Vector{String})::Cint
		program_main()
		return 0
	end
end

```

When compiling with PackageCompiler, then I get this error message:  
Failed to precompile MyProgram [8055130b-358c-4aa5-b077-72da6b1478e9] to C:\Users\sbbstm.julia\compiled\v1.8\MyProgram\jl\_5E4F.tmp.  
ERROR: LoadError: MethodError: no method matching julia\_main()  
Closest candidates are:  
julia\_main(::Vector{String}) at C:\JuliaWS\MyProgram\MyProgram\src\MyProgram.jl:890

**CASE 2:**

In precompile\_app.jl:

```julia
MyProgram.julia_main()

```

In MyProgram.jl:

```julia
module MyProgram

	argument_list = ARGS

	println("Length of arguments array: " * string(length(ARGS)))
	println("Content of arguments array: ")

 	program_main()
		# My Source Code
	end

	Base.@ccallable function julia_main(ARGS::Vector{String})::Cint
		program_main()
		return 0
	end
end

```

When compiling with PackageCompiler, then I get this error message:  
Failed to precompile MyProgram [8055130b-358c-4aa5-b077-72da6b1478e9] to C:\Users\sbbstm.julia\compiled\v1.8\MyProgram\jl\_517D.tmp.  
ERROR: LoadError: MethodError: no method matching julia\_main()  
Closest candidates are:  
julia\_main(::Vector{String}) at C:\JuliaWS\MyProgram\MyProgram\src\MyProgram.jl:890

**CASE 3:**

In precompile\_app.jl:

```julia
MyProgram.julia_main()

```

```julia
module MyProgram

	argument_list = ARGS

	println("Length of arguments array: " * string(length(ARGS)))
	println("Content of arguments array: ")

 	program_main()
		# My Source Code
	end

	julia_main()::Cint
		program_main()
		return 0
	end
end

```

It compiles an creates a MyProgram.exe in the folder bin, but when starting the compiled MyProgram.exe, it does nothing related to ARGS!  
It even does not write the result of these 2 lines, neither when I give arguments nor when i give no arguments when starting MyProgram.exe:

```julia
println("Length of arguments array: " * string(length(ARGS)))
println("Content of arguments array: ")

```

**WITHOUT PackageCompiler.jl:**

When starting the same source code as in CASE 3 without PackageCompiler and giving no args, then I get this here (that is what I expected and what is OK):  
_Length of arguments array: 0  
Content of arguments array:_

When starting the program (source code via Julia.exe) with arguments, such as “Julia.exe MyProgram.jl bla 123” then it works correctly. The output is:  
_Length of arguments array: 2  
Content of arguments array:  
bla  
123_

**It seems that ARGS does not work with PackageCompiler.  
Is there any workaround or bugfix?**

My system:

- Winows 10 64 Bits
- Julia 1.8.5
- PackageCompiler v2.1.7

Thanks for your advices in advance!

Kind regards,  
Miroslav Stimac

---

<div class="post-metadata">

### Author: ![sschmidhuber](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sschmidhuber/32/13349_2.png) [@sschmidhuber](https://discourse.julialang.org/u/sschmidhuber)
#### Post date: [September 4, 2023, 10:27pm UTC](https://discourse.julialang.org/t/packagecompiler-jl-does-not-support-args-arguments/103513/2 "2023-09-04T22:27:40Z")

</div>

Hello Miroslav,

PackageCompiler works with ARGS. You need to use the `julia_main()` function signature as you did in CASE 3. But keep in mind the entry point, for a compiled julia application, is `julia_main()`, so your `println()` functions were never called.  
In the interpreted version you got another output, because the file is just executed top down, including global scope (where your println() calls live).

`ARGS` is a global constant in Julia, you don’t need to put anywhere as function parameter, you can just use it.

Try this, if you want to compile it:

```julia
module compiled_example

function julia_main()::Cint
    println("Length of arguments array: $(length(ARGS))")
	println("Content of arguments array: ", ARGS)

    # program main, add your code here

    exit(0)    
end

end

```

and if you want to run it as script:

```julia
#! /usr/bin/env julia

module compiled_example

function julia_main()::Cint
    println("Length of arguments array: $(length(ARGS))")
	println("Content of arguments array: ", ARGS)

    # program main, add your code here

    exit(0)    
end

julia_main()

end

```

---

<div class="post-metadata">

### Author: ![xgdgsc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xgdgsc/32/608_2.png) [@xgdgsc](https://discourse.julialang.org/u/xgdgsc)
#### Post date: [September 5, 2023, 1:35am UTC](https://discourse.julialang.org/t/packagecompiler-jl-does-not-support-args-arguments/103513/3 "2023-09-05T01:35:07Z")

</div>

Easy way is using [Home · Comonicon.jl](https://comonicon.org/stable/)

---

<div class="post-metadata">

### Author: ![Miroslav-Stimac](https://avatars.discourse-cdn.com/v4/letter/m/c89c15/32.png) [@Miroslav-Stimac](https://discourse.julialang.org/u/Miroslav-Stimac)
#### Post date: [September 5, 2023, 6:14am UTC](https://discourse.julialang.org/t/packagecompiler-jl-does-not-support-args-arguments/103513/4 "2023-09-05T06:14:21Z")

</div>

Thank you very much!  
You are right!  
If I put the code in the function, then it works correctly and I can use ARGS.

Kind regards,  
Miroslav Stimac
