Skip to content
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

Bug: history lib not found, even though it is there #155

Open
asharpe-git opened this issue Jan 12, 2025 · 3 comments
Open

Bug: history lib not found, even though it is there #155

asharpe-git opened this issue Jan 12, 2025 · 3 comments
Assignees
Labels

Comments

@asharpe-git
Copy link

Calc bug report template version: 1.3 2022-11-27

Describe the bug
Using Mac Sequoia 15.2, M3 processor. Installed readline with macports. Compiled calc-2.15.1.0 with all the default options, and I get a link error at the end of the build:

cc -dynamiclib -undefined dynamic_lookup -install_name /usr/local/lib/libcalc.2.15.1.0.dylib -current_version 2.15.1 addop.o assocfunc.o blkcpy.o block.o byteswap.o codegen.o comfunc.o commath.o config.o const.o custom.o errtbl.o file.o func.o hash.o help.o hist.o input.o jump.o label.o lib_calc.o lib_util.o listfunc.o matfunc.o math_error.o obj.o opcodes.o pix.o poly.o prime.o qfunc.o qio.o qmath.o qmod.o qtrans.o quickhash.o seed.o sha1.o size.o str.o strl.o symbol.o token.o value.o version.o zfunc.o zio.o zmath.o zmod.o zmul.o zprime.o zrand.o zrandom.o libcustcalc.2.15.1.0.dylib
-lreadline -lhistory -lncurses -o libcalc.2.15.1.0.dylib
ld: library 'history' not found
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [libcalc.2.15.1.0.dylib] Error 1
$ ls -l /opt/local/lib/libhist*
-rwxr-xr-x 1 root admin 73912 Jan 11 20:46 /opt/local/lib/libhistory.8.2.dylib
lrwxr-xr-x 1 root admin 20 Jan 11 20:46 /opt/local/lib/libhistory.8.dylib -> libhistory.8.2.dylib
-rw-r--r-- 1 root admin 46928 Jan 11 20:46 /opt/local/lib/libhistory.a
lrwxr-xr-x 1 root admin 20 Jan 11 20:46 /opt/local/lib/libhistory.dylib -> libhistory.8.2.dylib

To Reproduce
Do what I did above

  1. How you started calc
    n/a

  2. Calc commands and their output

    Or if you cannot compile calc: The make command you used try and compile calc
    and all error and warning messages produced during that action. If long, consider
    attaching a file.

make 2>&1 | tee make.out

  1. Indicate where the problem is
    Referring to the information for step 1 above, indicate where the problem is to be found

Expected behavior
A clear and concise description of what you expected to happen.

Attach debug.out
IMPORTANT: Please run make debug and then attach the debug.out file.

Attached as debug.txt, since github doesn't allow .out
debug.txt

Screen shots
If applicable, attach screen shots to help explain your problem.

Execution environment (please complete the following information):

  • OS: MacOS
    E.g., macOS, FreeBSD, Linux, Windows 11, etc.

  • OS version: Mac Sequoia 15.2, M3 processor.
    E.g., Preferred: give the output of uname -a
    or if no uname command, a description of the OS version/release you are using

  • OS distribution: Sequoia 15.2
    E.g., macOS 13.0.1, contents of /etc/redhat-release, or /etc/os-release, etc.

  • Calc Version 2.15.1.0
    E.g., output of calc -v
    or if you cannot compile calc, the version you downloaded and from where it came from

  • Shell and shell version
    E.g., bash, zsh, power shell, etc.
    and the version of the shell you are using, if known
    $ echo $BASH_VERSION
    3.2.57(1)-release
    $

Calc mods
If you have modified the calc source for some reason, please description what you modified.
Please consider attaching a patch (diff -u) between an official calc release and the source
you are using.

Patch
If you have a recommended code patch to address the problem, please attach your file

Additional context
Add any other context about the problem here.

@lcn2 lcn2 self-assigned this Jan 12, 2025
@lcn2
Copy link
Owner

lcn2 commented Jan 12, 2025

Hello @asharpe-git 👋,

The ${READLINE_LIB} will need to be set properly for macports.

I use HomeBrew on macOS 15.2, so let me first explain how that builds calc:

The HomeBrew code is controlled in Makefile.config by these lines:

# Handle the case where macOS is being used with HomeBrew
# # and using the readline, history, and ncurses libraries.
# #
ifneq ($(HOMEBREW_PREFIX),)
READLINE_LIB:= -L${HOMEBREW_PREFIX}/opt/readline/lib -lreadline
READLINE_INCLUDE:= -I${HOMEBREW_PREFIX}/opt/readline/include
endif   # ($(HOMEBREW_PREFIX),)

This works because HomeBrew sets the following environment variable:

export HOMEBREW_PREFIX=/opt/homebrew

This results in:

cc  -DCALC_SRC -DCUSTOM -Wall -Wextra -pedantic     -UUNBAN -fPIC -O3 -g3 -Wno-strict-prototypes  -DUSE_READLINE -I/opt/homebrew/opt/readline/include \
	    -c hist.c
...

cc  calc.o   -Wl,-dead_strip -Wl,-dead_strip_dylibs   libcalc.2.15.1.0.dylib libcustcalc.2.15.1.0.dylib \
	      -L/opt/homebrew/opt/readline/lib -lreadline -lhistory -lncurses -o calc

I'm guessing that somehow you compiled hist.c into hist.o and that somehow macports put readline/readline.h somewhere that the compiler found it.

So I'm guessing that setting ${READLINE_INCLUDE} must not be critical for macports.

So ${READLINE_LIB} needs to be set properly.

I'm guessing that this might work for you:

make clobber all READLINE_LIB="-L/opt/local/lib -lreadline"

If that is the case, you could compile calc more "automatically" by adding to the borrow of Makefile.local:

READLINE_LIB:= -L/opt/local/lib -lreadline

QUESTION

Is there an equivalent environment variable to ${HOMEBREW_PREFIX} for macports?

If there is, then a similar set of lines could be added to Makefile.config to allow for calc to be compiled directly under macports like it does for HomeBrew.

@asharpe-git
Copy link
Author

Hi Landon! Yes, you are absolutely correct, your make invocation with READLINE_LIB worked. Macports doesn't put anything like a home directory for it, all it does is put the following in your .bash_profile:

# MacPorts Installer addition on 2025-01-11_at_20:42:45: adding an appropriate PATH variable for use with MacPorts.
export PATH="/opt/local/bin:/opt/local/sbin:$PATH"
# Finished adapting your PATH environment variable for use with MacPorts.

I'd expect that if there was such a thing, it would have put it there, too. I took a quick look at some of the Macports doc, here: https://guide.macports.org/#installing.shell , but that is unhelpful. I guess they just expect you to use DYLD_LIBRARY_PATH or some such.

Thanks again for your help. After using calc for something like 40 years, even though I can use a browser, I still find it quicker to use.

@lcn2
Copy link
Owner

lcn2 commented Mar 16, 2025

Auto detecting macports readline

Hello @asharpe-git and @pmetzger,

As a followup to this issue and to GH-issuecomment-2585679510 plus GH-issuecomment-2585899967:

We wish to modify Makefile.config so that users of macports (and in particular readline under macports) can be "autodetected", and folks such as @asharpe-git do not have to manually set READLINE_LIB="-L/opt/local/lib -lreadline".

Please apply the follow patch to Makefile.config and then recompile and test from scratch (make clobber all chk):

diff --git a/Makefile.config b/Makefile.config
index 4af112c..88d9815 100644
--- a/Makefile.config
+++ b/Makefile.config
@@ -1137,6 +1137,16 @@ READLINE_INCLUDE=
 ifneq ($(HOMEBREW_PREFIX),)
 READLINE_LIB:= -L${HOMEBREW_PREFIX}/opt/readline/lib -lreadline
 READLINE_INCLUDE:= -I${HOMEBREW_PREFIX}/opt/readline/include
+
+# If not HomeBrew, then try to detect macports and/or using /opt/local/{lib,include}
+#
+else   # perhaps macports and/or using /opt/local/{lib,include} ?
+ifneq ($(wildcard /opt/local/lib/*),)
+READLINE_LIB:= -L/opt/local/lib -lreadline
+endif
+ifneq ($(wildcard /opt/local/incliude/*),)
+READLINE_INCLUDE:= -I/opt/local/include
+endif
 endif  # ($(HOMEBREW_PREFIX),)

 # If $PAGER is not set, use this program to display a help file

Does that work for folks with macports and macports readline installed? I did under our "macports simulation".

Thanks!

UPDATE 0

Comments, suggestions and corrections welcome.

@lcn2 lcn2 reopened this Mar 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants