     pop-literal nip over set-alien-invoke-return
     ! Quotation which coerces parameters to required types
     dup make-prep-quot recursive-state get infer-quot
-    ! If symbol doesn't resolve, no stack effect, no compile
-    dup alien-invoke-dlsym 2drop
     ! Add node to IR
     dup node,
     ! Magic #: consume exactly the number of inputs
     0 alien-invoke-stack
 ] "infer" set-word-prop
+
+: stdcall-mangle ( symbol node -- symbol )
+    "@"
+    swap alien-node-parameters parameter-sizes drop
+    number>string 3append ;
+
+: (alien-invoke-dlsym) ( node -- symbol dll )
+    dup alien-invoke-function
+    swap alien-invoke-library load-library ;
+
+: alien-invoke-dlsym ( node -- symbol dll )
+    dup (alien-invoke-dlsym)
+    >r over stdcall-mangle r> 2dup dlsym [
+        rot drop
+    ] [
+        2drop (alien-invoke-dlsym)
+    ] if ;
 
 M: alien-invoke generate-node
     dup alien-invoke-frame [

M: alien-callback alien-node-abi alien-callback-abi ;

M: alien-callback-error summary
    drop "Words calling ``alien-callback'' cannot run in the interpreter. Compile the caller word and try again." ;

: callback-bottom ( node -- )
    alien-callback-xt [ word-xt <alien> ] curry

    alien-invoke-library library
    [ library-abi ] [ "cdecl" ] if* ;

M: alien-invoke-error summary
    drop
    "Words calling ``alien-invoke'' must be compiled with the optimizing compiler." ;

: pop-parameters pop-literal nip [ expand-constants ] map ;

