Compilation on MacOS, readline problems

Dear MacOS users,

I have tried to compile swipl under MacOS (not on my own computer, but on r-hub, the platform is called “macos-highsierra-release-cran”). I get the cmake output and the compilation error below. Does this indicate a problem with “Apple readline” instead of “GNU readline”?

Best wishes,

Matthias

CMAKE

#> -- Found Readline: /usr/local/include
1146#> -- Looking for readline/readline.h
1147#> -- Looking for readline/readline.h - found
1148#> -- Looking for readline/history.h
1149#> -- Looking for readline/history.h - found
1150#> -- Looking for rl_completion_matches
1151#> -- Looking for rl_completion_matches - not found
1152#> -- Looking for rl_insert_close
1153#> -- Looking for rl_insert_close - not found
1154#> -- Looking for rl_set_prompt
1155#> -- Looking for rl_set_prompt - not found
1156#> -- Looking for rl_clear_pending_input
1157#> -- Looking for rl_clear_pending_input - not found
1158#> -- Looking for rl_cleanup_after_signal
1159#> -- Looking for rl_cleanup_after_signal - not found
1160#> -- Looking for rl_filename_completion_function
1161#> -- Looking for rl_filename_completion_function - not found
1162#> -- Looking for rl_readline_state
1163#> -- Looking for rl_readline_state - not found
1164#> -- Looking for rl_done
1165#> -- Looking for rl_done - not found
1166#> -- Looking for rl_event_hook
1167#> -- Looking for rl_event_hook - not found
1168#> -- Configuring done

Later, while compiling:

#> Scanning dependencies of target plugin_readline4pl
#> [100%] Building C object packages/readline/CMakeFiles/plugin_readline4pl.dir/readline4pl.c.o
#> /Users/user4t5BxaDC/Rtemp/RtmpwwY7Md/R.INSTALL912339c51557/rolog/src/swipl-devel/packages/readline/readline4pl.c:576:15: warning: implicit declaration of function 'completion_matches' is invalid in C99 [-Wimplicit-function-declaration]
#> matches = rl_completion_matches((char *)text, /* for pre-4.2 */
#> ^
#> /Users/user4t5BxaDC/Rtemp/RtmpwwY7Md/R.INSTALL912339c51557/rolog/src/swipl-devel/packages/readline/readline4pl.c:106:31: note: expanded from macro 'rl_completion_matches'
#> #define rl_completion_matches completion_matches
#> ^
#> /Users/user4t5BxaDC/Rtemp/RtmpwwY7Md/R.INSTALL912339c51557/rolog/src/swipl-devel/packages/readline/readline4pl.c:576:13: warning: incompatible integer to pointer conversion assigning to 'char **' from 'int' [-Wint-conversion]
#> matches = rl_completion_matches((char *)text, /* for pre-4.2 */
#> ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#> /Users/user4t5BxaDC/Rtemp/RtmpwwY7Md/R.INSTALL912339c51557/rolog/src/swipl-devel/packages/readline/readline4pl.c:579:13: warning: incompatible integer to pointer conversion assigning to 'char **' from 'int' [-Wint-conversion]
#> matches = rl_completion_matches((char *)text,
#> ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#> 3 warnings generated.
#> [100%] Linking C shared module readline4pl.so
#> Undefined symbols for architecture x86_64:
#> "_tgetent", referenced from:
#> __rl_init_terminal_io in libreadline.a(terminal.o)
#> "_tgetflag", referenced from:
#> __rl_init_terminal_io in libreadline.a(terminal.o)
#> "_tgetnum", referenced from:
#> __rl_get_screen_size in libreadline.a(terminal.o)
#> "_tgetstr", referenced from:
#> __rl_init_terminal_io in libreadline.a(terminal.o)
#> "_tgoto", referenced from:
#> _update_line in libreadline.a(display.o)
#> "_tputs", referenced from:
#> _rl_redisplay in libreadline.a(display.o)
#> _update_line in libreadline.a(display.o)
#> __rl_clear_to_eol in libreadline.a(display.o)
#> __rl_move_vert in libreadline.a(display.o)
#> __rl_move_cursor_relative in libreadline.a(display.o)
#> __rl_clear_screen in libreadline.a(display.o)
#> __rl_update_final in libreadline.a(display.o)
#> ...
#> ld: symbol(s) not found for architecture x86_64
#> clang: error: linker command failed with exit code 1 (use -v to see invocation)
#> make[3]: *** [packages/readline/readline4pl.so] Error 1
#> make[2]: *** [packages/readline/CMakeFiles/plugin_readline4pl.dir/all] Error 2
#> make[1]: *** [all] Error 2
#> make: *** [swipl] Error 2
#> ERROR: compilation failed for package ‘rolog’
#> * removing ‘/Users/user4t5BxaDC/R/rolog’

Looks like an inconsistency. readline.h from /usr/local indicates non-Apple, but found symbols indicate it picks up the Apple library. Either make sure it finds the whole GNU readline or disable it.

In fact, it is for the rolog package, so readline is not needed.

I’ll try the following: manually specify the Readline_INCLUDE_DIR and the Readline_LIBRARY, as before in other packages. If that works, I’m done. If that fails, how can I disable it? Is there a cmake option?

I added a status message to packages/readline/CMakeLists.txt

find_package(Readline)
message(WARNING "Found readline at ${Readline_INCLUDE_DIR}, and ${Readline_LIBRARY}.")

The result does not look suspicious,

#> -- Found Readline: /usr/local/include
#> CMake Warning at packages/readline/CMakeLists.txt:17 (message):
#> Found readline at /usr/local/include, and /usr/local/lib/libreadline.a.

Is there a cmake switch that I can use for disabling specific packages? Or should I invent my own, along the lines of -DSWIPL_PACKAGES_JAVA=OFF? The strange thing is that there’s no SWIPL_PACKAGES_JAVA other than in CMAKE.md at the top level.

For any package we can use -DSWPL_PACKAGES_<name>=OFF

Interesting, thanks. IIRC I tried this w/o success yesterday, but I might have used the singular (package instead of packages). I’ll try again.

I found it! I can disable readline and libedit using the cmake switch -DSWIPL_PACKAGES_TERM=OFF, see swipl-devel/cmake/PackageSelection.cmake

I guess TERM refers to terminal (?)

I guess so. Note there is little reason to exclude libedit. SWI-Prolog should work with all versions. Problem is that libedit comes with an emulation for GNU readline, but that is too incomplete to be usable by SWI-Prolog. Anyway, the libedit based commandline editor is the preferred one.