Re: Calling Lisp from C (SBCL as a shared object) on Windows
Stas Boukarev <[email protected]> Fri, 4 Apr 2025 16:49:38 +0300
| Newsgroups | gmane.lisp.steel-bank.general |
|---|---|
| Message-ID | <CAF63=10q4z3sFJMF=xhZkv9W+svDPjxOwfvKk3SUF8Zb04mdYw@mail.gmail.com> |
UCRT is now fully working. And it actually doesn't have these warnings. On Fri, Apr 4, 2025 at 8:02 AM Uģis Lācis <[email protected]> wrote: > > Hi again, > > After the enlightening detour regarding UCRT and MSVCRT differences via bug > https://bugs.launchpad.net/sbcl/+bug/2105485 > the usage of SBCL as shared object finally works for me for a basic example from https://sourceforge.net/p/sbcl/mailman/message/59119977/. > > I am now using MINGW64 environment for my test. To generate the executable, I use slightly modified version to make it work on windows (linker expects .dll extension it seems), see attached zip file. > > The only thing that seems a bit suspicious now is that the final executable warns about missing few required external symbols: > AD+ugis.lacis@EQ-LT-49 MINGW64 ~/test_c_gcc_directExample > $ ./example.exe > Missing required foreign symbol 'truncf' > Missing required foreign symbol 'trunc' > Missing required foreign symbol 'log1p' > Missing required foreign symbol 'log2' > The sum of 2 and 387 is 389. > > Is this something to be worried about? > > Best wishes, > Ugis > > > -----Original Message----- > From: Uģis Lācis <[email protected]> > Sent: Friday, 28 March 2025 12:58 > To: Stas Boukarev <[email protected]> > Cc: [email protected] > Subject: Re: [Sbcl-help] Calling Lisp from C (SBCL as a shared object) on Windows > > Thanks! Tried it, still seems to fail the same as the second patch ... > > //entering make-target-2.sh > //doing warm init - compilation phase > This is SBCL 2.5.2.161-1abc2d5f6-WIP, an implementation of ANSI Common Lisp. > More information about SBCL is available at <http://www.sbcl.org/>. > > SBCL is free software, provided as is, with absolutely no warranty. > It is mostly in the public domain; some portions are provided under BSD-style licenses. See the CREDITS and COPYING files in the distribution for more information. > Initial page table: > | Immobile Objects | > Gen layout symbol code Boxed Cons Raw Code SmMix Mixed LgRaw LgCode LgMix Waste% Alloc Trig Dirty GCs Mem-age > 6 549 25872 20740 0 127 0 0 0 485 0 0 0 0.2 20021376 2000000 0 0 0.0000 > Tot 549 25872 20740 0 127 0 0 0 485 0 0 0 0.2 20021376 [1.9% of 1073741824 max] > [long list of Chinese symbols] > Exception Code: 00000000C0000374. > Faulting IP: 00007FFB5B4AB035. > fatal error encountered in SBCL pid 2929228304: > Exception too early in cold init, cannot continue. > > Welcome to LDB, a low-level debugger for the Lisp runtime environment. > ldb> exit > Argh! lossage_handler() returned, total confusion.. > > real 4m34.068s > user 0m0.030s > sys 0m0.077s > > -----Original Message----- > From: Stas Boukarev <[email protected]> > Sent: Friday, 28 March 2025 12:28 > To: Uģis Lācis <[email protected]> > Cc: [email protected] > Subject: Re: [Sbcl-help] Calling Lisp from C (SBCL as a shared object) on Windows > > Try the final patch then: > https://github.com/stassats/sbcl/commit/53654beb03cb7f7ec032d816868dcd4bd4e4bf89 > > On Fri, Mar 28, 2025 at 1:43 PM Uģis Lācis <[email protected]> wrote: > > > > Hi Stas, > > > > Thanks a lot for a quick reply. I tried both of your patches, but unfortunately SBCL did not want to build anymore (it seems it fails at some cross-compilation stage, if I am not mistaken). For the first patch, this is where my build process dies: > > ---------------------------------------------------------------------- > > ---------------------------------------------------------------------- > > - ; wrote > > C:/msys64/home/ugis.lacis/sbcl_patched/obj/from-host/src/compiler/gene > > ric/genesis.fasl-tmp > > ; compilation finished in 0:00:00.966 > > While evaluating the form starting at line 11, column 0 > > of #P"C:/msys64/home/ugis.lacis/sbcl_patched/make-genesis-2.lisp": > > > > debugger invoked on a HOST-SB-EXT:FILE-DOES-NOT-EXIST in thread > > #<THREAD tid=16816 "main thread" RUNNING {1100BA8133}>: > > The file #P"C:/msys64/home/ugis.lacis/sbcl_patched/output/tls-init.lisp-expr" > > does not exist: > > The system cannot find the file specified. > > > > Type HELP for debugger help, or (SB-EXT:EXIT) to exit from SBCL. > > > > restarts (invokable by number or by possibly-abbreviated name): > > 0: [CREATE ] Reopen with :if-does-not-exist :create > > 1: [CONTINUE ] Retry opening. > > 2: [USE-VALUE ] Try opening a different file. > > 3: [RETRY ] Retry EVAL of current toplevel form. > > 4: Ignore error and continue loading file "C:\\msys64\\home\\ugis.lacis\\sbcl_patched\\make-genesis-2.lisp". > > 5: [ABORT ] Abort loading file "C:\\msys64\\home\\ugis.lacis\\sbcl_patched\\make-genesis-2.lisp". > > 6: [ABORT-BUILD] Abort building SBCL. > > 7: Exit debugger, returning to top level. > > > > (HOST-SB-IMPL::%OPEN-ERROR > > #P"C:/msys64/home/ugis.lacis/sbcl_patched/output/tls-init.lisp-expr" 2 > > :IGNORE-THIS-ARG :ERROR) 0] //testing for consistency of first and > > second GENESIS passes > > diff: output/genesis-2: No such file or directory > > error: header files do not match between first and second GENESIS > > ---------------------------------------------------------------------- > > ---------------------------------------------------------------------- > > - > > > > For the second patch, I get a different error: > > ---------------------------------------------------------------------- > > ---------------------------------------------------------------------- > > - > > //entering make-target-2.sh > > //doing warm init - compilation phase > > This is SBCL 2.5.2.161-1abc2d5f6-WIP, an implementation of ANSI Common Lisp. > > More information about SBCL is available at <http://www.sbcl.org/>. > > > > SBCL is free software, provided as is, with absolutely no warranty. > > It is mostly in the public domain; some portions are provided under > > BSD-style licenses. See the CREDITS and COPYING files in the > > distribution for more information. > > Initial page table: > > | Immobile Objects | > > Gen layout symbol code Boxed Cons Raw Code SmMix Mixed LgRaw LgCode LgMix Waste% Alloc Trig Dirty GCs Mem-age > > 6 549 25872 20740 0 127 0 0 0 485 0 0 0 0.2 20021088 2000000 0 0 0.0000 > > Tot 549 25872 20740 0 127 0 0 0 485 0 0 0 0.2 20021088 [1.9% of 1073741824 max] > > [lot-of-chineese-symbols] > > Exception Code: 00000000C0000374. > > Faulting IP: 00007FFB5B4AB035. > > fatal error encountered in SBCL pid 1648420608: > > Exception too early in cold init, cannot continue. > > > > Welcome to LDB, a low-level debugger for the Lisp runtime environment. > > ldb> > > ---------------------------------------------------------------------- > > ---------------------------------------------------------------------- > > - > > > > > > -----Original Message----- > > From: Stas Boukarev <[email protected]> > > Sent: Thursday, 27 March 2025 19:37 > > To: Uģis Lācis <[email protected]> > > Cc: [email protected] > > Subject: Re: [Sbcl-help] Calling Lisp from C (SBCL as a shared object) > > on Windows > > > > Or rather try this > > > > On Thu, Mar 27, 2025 at 9:15 PM Stas Boukarev <[email protected]> wrote: > > > > > > Try this > > > > > > On Thu, Mar 27, 2025 at 6:07 PM Stas Boukarev <[email protected]> wrote: > > > > > > > > os_dlsym_default is probably to blame. > > > > > > > > On Thu, Mar 27, 2025 at 4:14 PM Uģis Lācis <[email protected]> wrote: > > > > > > > > > > Dear SBCL community, > > > > > > > > > > > > > > > > > > > > I am trying to use SBCL to define a LISP function I should be able to call from C. My working platform is Windows 11. I have gone through the information I could find on the topic, but can not make a basic example work. I have found discussions around this topic (with similar error traces as I am getting), but without a solution that would work for me. So what I am trying to do now: > > > > > > > > > > > > > > > > > > > > I have found an example (Re: [Sbcl-help] Calling Lisp from C (SBCL as a shared object) | Steel Bank Common Lisp) that should be working for exporting a callable LISP function. > > > > > I have saved the LISP code as-is in a “test1.lsp” file. > > > > > To check that I can produce a valid core, I do: > > > > > > > > > > sbcl.exe --script "test1.lsp" --noinform sbcl.exe --core > > > > > libsum.core > > > > > > > > > > > > > > > > > > > > After these steps I get the error, which is attached at the end of this message (I have also seen it in the thread I referenced above). I have tried these steps both in pre-built Windows installation downloaded from SBCL home page (SBCL 2.5.1) and also in compiled version from the git source (SBCL 2.5.2.155-1d476f1e0). I get the same output if I load the core as written above or via linking to compiled libsbcl.so shared library. > > > > > > > > > > > > > > > > > > > > Has anyone gotten this functionality to work on Windows? Any suggestions about how to get this working would be highly appreciated. > > > > > > > > > > > > > > > > > > > > Best wishes, > > > > > Ugis > > > > > > > > > > > > > > > > > > > > ------------------------------------- > > > > > > > > > > ------------------------ ERROR > > > > > ------------------------------------- > > > > > Unhandled SB-KERNEL::UNDEFINED-ALIEN-VARIABLE-ERROR in thread > > > > > #<SB-THREAD:THREAD tid=47068 "main thread" RUNNING > > > > > > > > > > {1100BA8003}>: > > > > > > > > > > Attempt to access an undefined alien variable. > > > > > > > > > > > > > > > > > > > > Backtrace for: #<SB-THREAD:THREAD tid=47068 "main thread" > > > > > RUNNING {1100BA8003}> > > > > > > > > > > 0: (SB-DEBUG::DEBUGGER-DISABLED-HOOK > > > > > #<SB-KERNEL::UNDEFINED-ALIEN-VARIABLE-ERROR {1100B9E613}> > > > > > #<unused > > > > > argument> :QUIT T) > > > > > > > > > > 1: (SB-DEBUG::RUN-HOOK *INVOKE-DEBUGGER-HOOK* > > > > > #<SB-KERNEL::UNDEFINED-ALIEN-VARIABLE-ERROR {1100B9E613}>) > > > > > > > > > > 2: (INVOKE-DEBUGGER #<SB-KERNEL::UNDEFINED-ALIEN-VARIABLE-ERROR > > > > > {1100B9E613}>) > > > > > > > > > > 3: (ERROR SB-KERNEL::UNDEFINED-ALIEN-VARIABLE-ERROR) > > > > > > > > > > 4: (SB-KERNEL::UNDEFINED-ALIEN-VARIABLE-ERROR) > > > > > > > > > > 5: ("foreign function: #x140046D35") > > > > > > > > > > 6: ("foreign function: #x140046E00") > > > > > > > > > > 7: ((SETF SB-SYS:SAP-REF-SAP) > > > > > :INVALID-VALUE-FOR-UNESCAPED-REGISTER-STORAGE > > > > > :INVALID-VALUE-FOR-UNESCAPED-REGISTER-STORAGE > > > > > :INVALID-VALUE-FOR-UNESCAPED-REGISTER-STORAGE) > > > > > > > > > > 8: (SB-EVAL::EVAL-PROGN ((SETF (SB-SYS:SAP-REF-SAP SB-ALIEN::SAP > > > > > (/ SB-ALIEN::OFFSET SB-VM:N-BYTE-BITS)) SB-ALIEN::VALUE) > > > > > (SB-ALIEN-INTERNALS:NATURALIZE SB-ALIEN::VALUE (QUOTE > > > > > #<ALIEN-TYPE > > > > > (* T)>))) #<SB-EVAL::ENV {1100B9E1F3}>) > > > > > > > > > > 9: ((SETF SB-ALIEN-INTERNALS:%ALIEN-VALUE) > > > > > #<SB-ALIEN-INTERNALS:ALIEN-VALUE :SAP #X20010CC0 :TYPE (* T)> > > > > > #.(SB-SYS:INT-SAP #X001D0000) 0 #<ALIEN-TYPE (* T)>) > > > > > > > > > > 10: (SB-IMPL::%START-LISP) > > > > > > > > > > 11: ("foreign function: #x140046D35") > > > > > > > > > > 12: ("foreign function: #x14000A160") > > > > > > > > > > _______________________________________________ > > > > > Sbcl-help mailing list > > > > > [email protected] > > > > > https://lists.sourceforge.net/lists/listinfo/sbcl-help > > _______________________________________________ > Sbcl-help mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/sbcl-help _______________________________________________ Sbcl-help mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/sbcl-help