PackageCompiler error. @ccallable was already defined

I get this error when trying to compile a fairly long code. I succeeded previously with Julia 1.5, having to manually edit out of some deps.jl file some hardcoded library paths. It wasn’t easy but it worked. Now, with most libraries using the artifacts system, that is much alleviated, but I get the following error and I can’t find the cause:

ERROR: @ccallable was already defined for this method name
Stacktrace:
 [1] _ccallable(rt::Type, sigt::Type)
   @ Base .\c.jl:498
 [2] top-level scope
   @ c.jl:529
ERROR: LoadError: failed process: Process(`'C:\Users\usr\AppData\Local\Programs\Julia-1.6.1\bin\julia.exe' --color=yes --startup-file=no '--cpu-target=generic;sandybridge,-xsaveopt,clone_all;haswell,-rdrnd,base(1)' '--sysimage=C:\Users\usr\AppData\Local\Temp\jl_oUKlQj\tmp_sys.so' '--project=C:\Users\usr\Desktop\DKT\CodeR - v1.5 - dev\compilable_code' '--output-o=C:\Users\usr\AppData\Local\Temp\jl_V3iHdZTDNY.o' -e 'Base.reinit_stdio()
@eval Sys BINDIR = ccall(:jl_get_julia_bindir, Any, ())::String
@eval Sys STDLIB = "C:\\Users\\usr\\AppData\\Local\\Programs\\Julia-1.6.1\\share\\julia\\stdlib\\v1.6"
Base.init_load_path()
if isdefined(Base, :init_active_project)
    Base.init_active_project()
end
Base.init_depot_path()
import compilable_code
# This @eval prevents symbols from being put into Main
@eval Module() begin
    PrecompileStagingArea = Module()
    for (_pkgid, _mod) in Base.loaded_modules
        if !(_pkgid.name in ("Main", "Core", "Base"))
            eval(PrecompileStagingArea, :(const $(Symbol(_mod)) = $_mod))
        end
    end
    precompile_files = String[
        "C:\\Users\\usr\\AppData\\Local\\Temp\\jl_6krAUC3B01"
    ]
    for file in precompile_files, statement in eachline(file)
        # println(statement)
        # The compiler has problem caching signatures with \`Vararg{?, N}\`. Replacing
        # N with a large number seems to work around it.
        statement = replace(statement, r"Vararg{(.*?), N} where N" => s"Vararg{\1, 100}")
        try
            Base.include_string(PrecompileStagingArea, statement)
        catch
            # See julia issue #28808
            @debug "failed to execute $statement"
        end
    end
end # module
Base.@ccallable function julia_main()::Cint
    try
        compilable_code.julia_main()
    catch
        Core.print("julia_main() threw an unhandled exception")
        return 1
    end
end
empty!(LOAD_PATH)
empty!(DEPOT_PATH)
'`, ProcessExited(1)) [1]

Stacktrace:
 [1] pipeline_error
   @ .\process.jl:525 [inlined]
 [2] run(::Cmd; wait::Bool)
   @ Base .\process.jl:440
 [3] run
   @ .\process.jl:438 [inlined]
 [4] create_sysimg_object_file(object_file::String, packages::Vector{String}; project::String, base_sysimage::String, precompile_execution_file::Vector{String}, precompile_statements_file::Vector{String}, cpu_target::String, script::Nothing, isapp::Bool)
   @ PackageCompiler C:\Users\usr\.julia\packages\PackageCompiler\3BsME\src\PackageCompiler.jl:306
 [5] create_sysimage(packages::Symbol; sysimage_path::String, project::String, precompile_execution_file::Vector{String}, precompile_statements_file::Vector{String}, incremental::Bool, filter_stdlibs::Bool, replace_default::Bool, cpu_target::String, script::Nothing, base_sysimage::String, isapp::Bool)
   @ PackageCompiler C:\Users\usr\.julia\packages\PackageCompiler\3BsME\src\PackageCompiler.jl:442
 [6] (::PackageCompiler.var"#9#10"{Vector{String}, Vector{String}, Bool, Bool, String, String, String, String, String})()
   @ PackageCompiler C:\Users\usr\.julia\packages\PackageCompiler\3BsME\src\PackageCompiler.jl:672
 [7] cd(f::PackageCompiler.var"#9#10"{Vector{String}, Vector{String}, Bool, Bool, String, String, String, String, String}, dir::String)
   @ Base.Filesystem .\file.jl:95
 [8] create_app(package_dir::String, app_dir::String; app_name::Nothing, precompile_execution_file::Vector{String}, precompile_statements_file::Vector{String}, incremental::Bool, filter_stdlibs::Bool, audit::Bool, force::Bool, c_driver_program::String, cpu_target::String)
   @ PackageCompiler C:\Users\usr\.julia\packages\PackageCompiler\3BsME\src\PackageCompiler.jl:661
 [9] top-level scope
   @ C:\Users\usr\Desktop\DKT\CodeR - v1.5 - dev\make.jl:5
in expression starting at C:\Users\usr\Desktop\DKT\CodeR - v1.5 - dev\make.jl:5module compilable_code
  include(joinpath(pwd(),"..\\..\\LabReactor\\LabReactor.jl"))
  include(joinpath(pwd(),"..\\..\\Reactor\\Reactor_Release.jl"))
  using .LabReactor
  using .Reactor
  using NLopt
  using LSODA
  using DelimitedFiles
  #using Random
  #Random.__init__()
  
  #run_estimation(3)
  #model_transient()
  #estimate_transient(2)
  #estimate_fresh_profile(2)
  #println("\n\nPRECOMPILATION SUCCESFUL\n\n")

  Base.@ccallable function julia_main(ARGS::Vector{String})::Cint
      println("compilable_code Reactor Model\n\n")
		run_estimation(200)
		#=
      TaskFile = joinpath(pwd(),"IO\\Task.dat")
      task = readdlm(TaskFile)
      if task[1] == "Kinetics"
        run_estimation(200)
	  elseif task[1] == "Reactor" && task[2] == "Modelling"
        model_transient()
      elseif task[1] == "Reactor" && task[4] == "Deactivation"
        estimate_transient(50)
      elseif task[1] == "Reactor" && task[4] == "Heat"
        estimate_fresh_profile(200)
      end
	  =#

      return 0
  end

end

My guess is that you already have a Base.@ccallable function julia_main in your code.

Found the issue :slight_smile:
The main function was defined in my code as:

Base.@ccallable function julia_main()::Cint
  #some statements
end

instead, it compiled when taking out the Base.@ccallable out and leaving it like:

function julia_main()::Cint
  #some statements
end

It’s strange, since it used to work with the previous form and it appears like that in PackageCompiler documentations.

https://julialang.github.io/PackageCompiler.jl/dev/apps/#Creating-an-app-1

where it says:

It should define a function with the signature

function julia_main()::Cint
 # do something based on ARGS?
 return 0 # if things finished successfully
end

(no @ccallable).

1 Like

I got it from this part of the documentation:

https://julialang.github.io/PackageCompiler.jl/dev/devdocs/relocatable_part_3/

module MyApp
using Crayons

Base.@ccallable function julia_main()::Cint
    try
        real_main()
    catch
        Base.invokelatest(Base.display_error, Base.catch_stack())
        return 1
    end
    return 0
end

function real_main()
    Crayons.FORCE_COLOR[] = true
    color = :red
    for arg in ARGS
        if !(arg in ["red", "green", "blue"])
            error("invalid color $arg")
        end
        color = Symbol(arg)
    end
    c = Crayon(foreground=color)
    r = Crayon(reset=true)
    while !eof(stdin)
        txt = String(readavailable(stdin))
        print(r, c, txt, r)
    end
    return 0
end
if abspath(PROGRAM_FILE) == @__FILE__
    real_main()
end
end # module

Did you see the top:

This section is for people who want to understand PackageCompiler.jl under the hood. It is not required reading to use the pacakge.

2 Likes

apparently not :sweat_smile: