Skip to content

Library generated with juliac errors when called from julia itself, but works when called by other program #59237

@asprionj

Description

@asprionj

For full background / history see this discourse post/thread.

OS is Windows 11, julia nightly as of writing was at:

Version 1.13.0-DEV.970 (2025-08-07)
Commit d268106b94 (0 days old master)

libmwe.jl contains:

Base.@ccallable function answer()::Cint
    return 42
end

Compile it using nightly build:

julia +nightly <path\to\>juliac.jl --output-lib libmwe --experimental --trim --compile-ccallable libmwe.jl

Trying to call it fails, however. Executing

julia +nightly -e '@ccall "libmwe.dll".answer()::Cint'

results in:

[2924] signal 22: SIGABRT
in expression starting at none:1
crt_sig_handler at C:/workdir/src\signals-win.c:99
raise at C:\WINDOWS\System32\msvcrt.dll (unknown line)
abort at C:\WINDOWS\System32\msvcrt.dll (unknown line)
jl_init_threadtls at C:/workdir/src\threading.c:334
ijl_adopt_thread at C:/workdir/src\threading.c:447
.text at <path\to>\libmwe.dll (unknown line)
[...]

The remainder of the trace is different when called from the REPL, or when wrapping libmwe.dll in another DLL using another language (such as C, Go) and calling this one from julia again. So, these first lines seem to pinpoint the problem.

Note 1: Using Libdl.dlopen and then Libdl.dlsym to get the function pointer works fine. The error occurs when actually calling the answer function.

Note 2: When calling the library from a different language, everything works fine. Exemplary Go file to reproduce it, wrapmwe.go:

package main

import "fmt"

/*
#cgo LDFLAGS: -L. -llibmwe
int answer();
*/
import "C"

func main() {
	answer := C.answer()
	fmt.Println("This is Go. Value returned by answer: ", answer)
}

Put file next to libmwe.dll and just call go run ./wrapmwe.go .

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions