외국 도서관을로드 할 수 없습니다

Nov 19 2020

AC 라이브러리에는 다음 코드가 포함되어 있습니다.

/*
 * 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는 공유 라이브러리를 만드는 데 사용됩니다 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

로드 실패 :

$ 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
?- 

왜?

답변

Aubin Nov 20 2020 at 09:32

UNIX 라이브러리에 대한 규칙은 여기에 적용되지 않으며 LD_LIBRARY_PATH.

C 코드에서 설치 메소드 이름은 라이브러리 파일의 이름에서 추론됩니다. 기존 방식으로 라이브러리 libelevatorMessages.so이름을 지정하면 install메소드 이름도 변경해야합니다 .

마지막으로 이름과 경로는 다음과 같습니다.

  1. 프롤로그에서 : :- use_foreign_library( './Debug/libelevatorMessages' ).
  2. C에서 : void install_libelevatorMessages( void )

라이브러리에 액세스하기위한 상대 경로와 .so.