SWI-Prolog / packages-cpp

The SWI-Prolog C++ interface
30 stars 14 forks source link

Can't find entry point...? #88

Closed HayatoTenryuu closed 2 months ago

HayatoTenryuu commented 2 months ago

I am new to this, I just looked at the code for likes.cpp and likes.pl, then I compiled them successfully (I think?)

image

But then when I tried to run the program, I got this error:

355516587-5245fb94-4a9f-4070-a1b0-691cedee467a

Am I stupid or is something actually configured wrong?

kamahen commented 2 months ago

The message seems to say that you don't have a proper executable -- possibly there's a missing DLL in your dynamic load path?

This is what I did on Linux (I don't know the equivalent on Windows) ... the only difference I see is that I called my executable likes.exe, which isn't necessary on Linux but which might be necessary on Windows and the "loaded" messages are slightly different:

$ swipl-ld -o likes.exe likes.cpp likes.pl
% Disabled autoloading (loaded 34 files)
% Disabled autoloading (loaded 5 files)
% Disabled autoloading (loaded 0 files)
% halt

$ ./likes.exe mary
Welcome to SWI-Prolog (threaded, 64 bits, version 9.3.8-27-g80f956be2-DIRTY)
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software.
Please run ?- license. for legal details.

For online help and background, visit https://www.swi-prolog.org
For built-in help, use ?- help(Topic). or ?- apropos(Word).

mary likes:
    john
    potplants
    jane
    paul
    Heartbreak High
    sunbathing

$ ldd ./likes.exe
    linux-vdso.so.1 (0x00007ffe9deed000)
    libswipl.so.9 => /home/peter/.local/lib/swipl/lib/x86_64-linux/libswipl.so.9 (0x00007f012cd27000)
    libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f012ca00000)
    libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f012ccf1000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f012c81f000)
    libtinfo.so.6 => /lib/x86_64-linux-gnu/libtinfo.so.6 (0x00007f012ccbe000)
    libgmp.so.10 => /lib/x86_64-linux-gnu/libgmp.so.10 (0x00007f012cc3b000)
    libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f012cc1c000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f012c740000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f012ced0000)
HayatoTenryuu commented 2 months ago

So, apparently this error only shows up when I try to double-click the exe file. The "disabled autoloading" messages are the same regardless of whether I type ".exe" or not.

When I run it from the terminal as ".\likes mary" or "./likes.exe mary" or any combination of slashes and inclusion/exclusion of ".exe", it just does nothing.

JanWielemaker commented 2 months ago

You need the folder holding libswipl.dll, etc, in %PATH%. I'm not sure that is enough on modern Windows. You may need to copy likes.exe to this folder or copy the required dlls to the folder holding likes.exe.

kamahen commented 2 months ago

You may want to put your call to likes.exe into a likes.bat file that adds the folder with liswipl.dll to the PATH (or %PATH% or whatever Windows does). You can also pass additional parameters to the C++ compiler and linker as described in the swipl-ld manual page (e.g., there might be a Windows equivalent of -ld-options,-Bstatic, although this doesn't seem to make any difference on Linux). Specifying -v to swipl-ld might give you additional insights.

HayatoTenryuu commented 2 months ago

image

I don't know enough computer-fu to see anything wrong, except one possible thing which is that I am using 64-bit. My Prolog should also be 64 bit though. Is the master branch of this repo incompatible with x64? I do see an x64 branch...?

Moving libswipl.dll didn't help any, either.

kamahen commented 2 months ago

I don't know enough about Windows to help further, but there are people who routinely use Windows at who could possibly help at https://swi-prolog.discourse.group/

HayatoTenryuu commented 2 months ago

I've thrown a question on there, and I'd like to leave this open until we can find a resolution. I want to leave the solution here for posterity.

JanWielemaker commented 2 months ago

This issue has been mentioned on SWI-Prolog. There might be relevant details there:

https://swi-prolog.discourse.group/t/swi-prolog-interface-to-c-c/7671/3

HayatoTenryuu commented 2 months ago

Problem solved, apparently I was using an earlier version of Prolog (pre-9.2.6) and therefore it was not working. It should've been obvious, but moving forward if anyone is having issues with the interface, first check the SWI-Prolog version we are using.

kamahen commented 2 months ago

I think that SWI-Prolog 9.2.6 has all the latest changes that are also in the development version (9.3.8). The C++ interface should be stable from now on (except for bug fixes), but there are a few missing things that I'll work on if I have time: https://github.com/SWI-Prolog/packages-cpp/issues Note that PlTermScoped is still experimental; there are some subtle interactions between its design and how C++ does "move" semantics that I'm not 100% sure of (in other words, I don't fully understand C++ "move semantics); also it requires at least C++-17 (C++-20 on Windows).