New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
morxa opened this Issue Jan 24, 2017 · 2 comments

Comments

Projects
None yet
3 participants
@morxa
Copy link

morxa commented Jan 24, 2017

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.

@morxa morxa changed the title undefined symbol: PL_new_atom when reading files Error "undefined symbol: PL_new_atom" when reading files Jan 24, 2017

@jannikb

This comment has been minimized.

Copy link

jannikb commented Mar 17, 2018

I had a similiar issue while loading the odbc library on ubuntu 16.04 and swi-prolog 7.6.4:
'$open_shared_object'/3: /usr/lib/swi-prolog/lib/amd64/odbc4pl.so: undefined symbol: PL_get_long

The workaround with LD_PRELOAD also worked for me with an adjusted path:
export LD_PRELOAD=/usr/lib/libswipl.so

@yuce yuce closed this in 1d560cc May 24, 2018

yuce added a commit that referenced this issue May 24, 2018

@yuce

This comment has been minimized.

Copy link
Owner

yuce commented May 24, 2018

Thanks @morxa. The test case you provided was very useful. Passing mode=RTLD_GLOBAL to library loader fixed this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment