Skip to content

Error "undefined symbol: PL_new_atom" when reading files #10

@morxa

Description

@morxa

When reading files, I always get the following error:

python3: symbol lookup error: /usr/lib64/swipl-7.2.3/lib/x86_64-linux/readutil.so: undefined symbol: PL_new_atom

How to reproduce

  1. Copy the following into read.pl

    read_file(Filename, Strings) :-
      setup_call_cleanup(
      open(Filename, read, Stream),
      read_stream_string(Stream, Strings),
      close(Stream)
    ).
    
    read_stream_string(Stream, Strings) :-
      read_line_to_string(Stream, String),
      ( String == end_of_file -> Strings = []
      ;
        read_stream_string(Stream, RStrings),
        Strings = [String|RStrings]
      ).
    
  2. Copy the following to read.py:

    from pyswip.prolog import Prolog
    from pyswip.core import *
    
    prolog = Prolog()
    prolog.consult('read.pl')
    list(prolog.query('read_file("read.pl", S)'))
    
  3. Run python3 read.py, which will produce the output:

    python3: symbol lookup error: /usr/lib64/swipl-7.2.3/lib/x86_64-linux/readutil.so: undefined symbol: PL_new_atom
    

Workaround

PL_new_atom is defined in libswipl.so, but readutil.so is not linked against libswipl. As a workaround, libswipl.so can be LD_PRELOADed:

$ export LD_PRELOAD=/usr/lib64/swipl-7.2.3/lib/x86_64-linux/libswipl.so.7.2.3
$ python3 read.py

After preloading the shared lib, the error disappears (and #9 occurs). This show that this is indeed a problem with linking.

I'm not sure if this is an error on the pyswip side or the swipl side, but I assume if you always load libswipl.so, then the error will disappear.

This is on Fedora 25 with SWi-Prolog 7.2.3.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions