agraef / pure-lang

Pure programming language
https://agraef.github.io/pure-lang/
316 stars 20 forks source link

pure-octave: /bin/sh: dynamiclib: command not found #35

Closed ryandesign closed 2 years ago

ryandesign commented 2 years ago

pure-octave 0.13 fails to build for me on macOS 10.15.7 with octave 6.4.0. This happens when running make:

rm -f embed.o
mkoctfile -v -DOCTAVE_MAJOR=6 -DOCTAVE_MINOR=4 -o embed.o -c embed.cc
/usr/bin/clang++ -c -I/opt/local/include -fPIC -I/opt/local/include/octave-6.4.0/octave/.. -I/opt/local/include/octave-6.4.0/octave -I/opt/local/include  -D_THREAD_SAFE -pthread -Os -std=gnu++11 -stdlib=libc++ -arch x86_64    -DOCTAVE_MAJOR=6 -DOCTAVE_MINOR=4 embed.cc -o embed.o
warning: LFLAGS is deprecated and will be removed in a future version of Octave, use LDFLAGS instead
rm -f octave_embed.dylib
dynamiclib -install_name "/opt/local/lib/pure/octave_embed.dylib" -o octave_embed.dylib embed.o -L/opt/local/lib/octave/6.4.0 -L/opt/local/lib -loctinterp -loctave  -L/opt/local/lib -Wl,-headerpad_max_install_names -L/opt/local/libexec/qt5/lib -Wl,-syslibroot,/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk -arch x86_64 -lpure
/bin/sh: dynamiclib: command not found
make: [octave_embed.dylib] Error 127 (ignored)

This is not detected as an error so make install is allowed to proceed, but of course it fails too:

cp gnuplot.pure octave.pure octave_embed.dylib "/path/to/destroot/opt/local/lib/pure"
cp: octave_embed.dylib: No such file or directory

Looks like Octave 6.4.0's mkoctfile at least does not know about LD_CXX anymore but it does have something called CXXLD:

$ mkoctfile -p LD_CXX

$ mkoctfile -p CXXLD
/usr/bin/clang++ -std=gnu++11

This fixes it for me:

--- Makefile.orig   2021-04-26 04:58:58.000000000 -0500
+++ Makefile    2022-01-14 23:39:34.000000000 -0600
@@ -52,7 +52,7 @@
 embed.o: embed.cc embed.h
    rm -f $@
    $(mkoctfile) -v $(octversionflag) -o $@ -c $<
-MKOCT_LDCXX = $(shell $(mkoctfile) -p LD_CXX)
+MKOCT_LDCXX = $(shell $(mkoctfile) -p CXXLD)
 MKOCT_LDFLAGS = $(shell $(mkoctfile) -p LFLAGS) $(shell $(mkoctfile) -p OCTAVE_LIBS) $(shell $(mkoctfile) -p LDFLAGS)
 octave_embed$(DLL): embed.o
    rm -f $@

However, I expect that will make it incompatible with earlier versions of octave that used LD_CXX, so a more nuanced solution may be needed that detects and uses whatever the current version of octave needs.

As for the deprecation of LFLAGS, I'm not sure what to do. The suggestion to use LDFLAGS instead is curious to me. The pure-octave Makefile already uses both LFLAGS and LDFLAGS. And LDFLAGS doesn't contain all the flags LFLAGS does:

$ mkoctfile -p LFLAGS
warning: LFLAGS is deprecated and will be removed in a future version of Octave, use LDFLAGS instead
-L/opt/local/lib/octave/6.4.0 -L/opt/local/lib
$ mkoctfile -p LDFLAGS
-L/opt/local/lib -Wl,-headerpad_max_install_names -L/opt/local/libexec/qt5/lib -Wl,-syslibroot,/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk -arch x86_64

Specifically, LDFLAGS is missing -L/opt/local/lib/octave/6.4.0. If I remove the LFLAGS, the build fails with:

ld: library not found for -loctinterp

If I keep LFLAGS and overlook the deprecation message it builds fine.

agraef commented 2 years ago

Ryan, sorry for getting back so late, and thanks for reporting the issue! I replaced LD_CXX as you suggested, fixed in git. I also agree that we should keep LFLAGS until LDFLAGS does the right thing.