I’m using: SWI-Prolog version 9.3.8
I want to create a stand alone exe that can be executed in multiples machine without prolog installed, the exe run a web server with a local websocket.
My code looks like this:
:- use_module(library(http/thread_httpd)).
:- use_module(library(http/http_dispatch)).
:- use_module(library(http/http_parameters)).
:- use_module(library(http/websocket)).
:- use_module(library(http/http_error)).
:- use_module(library(http/http_json)).
:- use_module(library(http/json_convert)).
:- use_module(library(http/json)).
main:-
server,
thread_get_message(_).
% Star the server at port 9000
server :-
http_server(http_dispatch, [port(9000)]).
:- http_handler(root(time),
http_upgrade_to_websocket(time_handler, []),
[spawn([])]).
time_handler(WebSocket) :-
ws_receive(WebSocket, Message, [format(json)]),
(
Message.opcode == close
->
true
;
time_response(ResponseDict),
ws_send(WebSocket, json(ResponseDict)),
time_handler(WebSocket)
).
time_response(ResponseDict) :-
get_time(Time),
format_time(string(Message), '%c', Time),
dict_create(Data, _, [message-Message]),
dict_create(ResponseDict, _, [data-Data,format-json,opcode-text]).
And the exe it’s generated with
qsave_program('websocket.exe', [stand_alone(true), foreign(copy), goal(main)]).
This generates an exe with all the necessary dlls.
The problem arise when running the exe on another machine as it does not run the websocket because it does not find certain modules, such as http_stream.pl, websocket.pl, etc.
this is one of the errors
ERROR: c:/program files/swipl/library/ext/clib/socket.pl:215: Initialization goal raised exception:
ERROR: The specified module can not be found
ERROR: In:
ERROR: [18] throw(error(shared_object(open,'The specified module can not be found.rn'),context(...,_3168)))
ERROR: [16] <meta call>
ERROR: [15] with_mutex('$foreign',load_foreign_library(foreign(socket),socket,[])) <foreign>
ERROR: [11] '$run_init_goal'('$syspreds':use_foreign_library_noi(...)) at c:/users/.../init.pl:823
ERROR: [10] catch(system:'$run_init_goal'(...),_3302,system:'$initialization_error'(_3324,...,...)) at c:/users/.../init.pl:564
ERROR: [9] catch_with_backtrace(system:'$run_init_goal'(...),_3360,system:'$initialization_error'(_3382,...,...)) at c:/users/.../init.pl:644
ERROR:
ERROR: Note: some frames are missing due to last-call optimization.
ERROR: Re-run your program in debug mode (:- debug.) to get more detail.
ERROR: c:/program files/swipl/library/ext/http/http/http_stream.pl:53: Initialization goal raised exception:
ERROR: The specified module can not be found
Alexis Quintana Vega is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.