fremde Bibliothek kann nicht geladen werden

Nov 19 2020

Die AC-Bibliothek enthält diesen Code:

/*
 * Custom specific code here...
 * several static functions.
 */
/**
 * receiveMessages( +Socket, ?DoorsAreOpen, ?DoorsAreClosed, ?CabinRequests, ?CabinLocation, ?LandingRequests )
 */
static foreign_t receiveMessages(
   term_t Socket,
   term_t doorsAreOpen,
   term_t doorsAreClosed,
   term_t cabinRequests,
   term_t cabinLocation,
   term_t landingRequests )
{
   int sockfd;
   return PL_get_integer_ex( Socket, &sockfd )
      &&  sockfd
      &&  udpReceive( sockfd, doorsAreOpen, doorsAreClosed, cabinRequests, cabinLocation, landingRequests );
}

void install_elevatorMessages( void ) {
   request2 = PL_new_functor( PL_new_atom( "request" ), 2 );
   PL_register_foreign( "receiveMessages", 6, receiveMessages, 0 );
}

Eclipse CDT wird zum Erstellen der gemeinsam genutzten Bibliothek verwendet libelevatorMessages.so.

$ nm /home/aubin/Dev/IA/prolog-Ascenseur/Debug/libelevatorMessages.so | grep -w T
0000000000001210 T _fini
0000000000000918 T _init
00000000000011c5 T install_elevatorMessages

Ladefehler:

$ swipl
Welcome to SWI-Prolog (threaded, 64 bits, version 8.3.13)
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).

?- assertz( file_search_path( elevatorLibsPath, '/home/aubin/Dev/IA/prolog-Ascenseur/Debug/' )).
true.

?- load_foreign_library( elevatorLibsPath( elevatorMessages )).
ERROR: source_sink `elevatorLibsPath(elevatorMessages)' does not exist
ERROR: In:
ERROR:   [16] throw(error(existence_error(source_sink,...),_14836))
ERROR:   [14] shlib:load_foreign_library(elevatorLibsPath(elevatorMessages),user,default(install)) at /usr/lib/swi-prolog/library/shlib.pl:381
ERROR:   [13] <meta call>
ERROR:   [12] with_mutex('$foreign',load_foreign_library(elevatorLibsPath(elevatorMessages),user,default(install))) <foreign>
ERROR:    [9] toplevel_call(user:user: ...) at /usr/lib/swi-prolog/boot/toplevel.pl:1113
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.
   Exception: (14) shlib:load_foreign_library(elevatorLibsPath(elevatorMessages), user, default(install)) ? abort
% Execution Aborted
?- 

Warum?

Antworten

Aubin Nov 20 2020 at 09:32

Die Konventionen zu UNIX-Bibliotheken gelten hier nicht und die Verwendung von LD_LIBRARY_PATH.

Der Name der Installationsmethode in C-Code wird aus dem Namen der Bibliotheksdatei abgeleitet. Wenn wir die Bibliothek konventionell libelevatorMessages.sobenennen, müssen wir auch die installMethode umbenennen .

Schließlich sind die Namen und Pfade:

  1. In Prolog: :- use_foreign_library( './Debug/libelevatorMessages' ).
  2. In C: void install_libelevatorMessages( void )

Beachten Sie den relativen Pfad für den Zugriff auf die Bibliothek und das Auslassen von .so.