Binary doesn't appear to find linked .dylib library - macos

I have a github action for macos that needs to download a dmg archive, extract binaries
and re-configure binaries so that they can run and link to the downloaded .dylib library. Below is the script I am using.
Unfortunately, when I run the binary (kdu_expand) I get an error
/Users/runner/work/_temp/92b88adb-5bec-4d13-a51d-85fdf4e84e8d.sh: line 16: 1603 Killed: 9 ./kdu_expand -version
Error: Process completed with exit code 137.
Is this the correct way of re-configuring the binary to link to the dynamic library ?
wget -q http://kakadusoftware.com/wp-content/uploads/KDU805_Demo_Apps_for_MacOS_200602.dmg_.zip
mkdir kdu && mv KDU805_Demo_Apps_for_MacOS_200602.dmg_.zip kdu && cd kdu
7z e KDU805_Demo_Apps_for_MacOS_200602.dmg_.zip
7z e KDU805_Demo_Apps_for_MacOS_200602.dmg 2>/dev/null || true
7z e Payload~ 2>/dev/null || true
chmod +x kdu_expand
chmod +x kdu_compress
install_name_tool -id ${PWD}/libkdu_v80R.dylib libkdu_v80R.dylib
install_name_tool -change /usr/local/lib/libkdu_v80R.dylib ${PWD}/libkdu_v80R.dylib kdu_compress
install_name_tool -change /usr/local/lib/libkdu_v80R.dylib ${PWD}/libkdu_v80R.dylib kdu_expand
echo "${{ github.workspace }}/kdu" >> $GITHUB_PATH
./kdu_expand -version

Killed: 9 more often than not hints at a codesigning error.
That is, by changing install names you modified the binaries, thus invalidating their code signatures (and in my case, install_name_tool warns me about this).
To fix it, run the following command against each binary you modified:
codesign -s - -f path/to/binary

Related

ERROR: The Python zlib extension was not compiled. Missing the zlib?

I'm trying to install Python 2.7.7 using Homebrew AND pyenv on my Mac (MacBook Air, OSX 12.5 Monterrey, 1.6 GHz Dual-Core Intel Core i5) but keep getting this “Missing zlib” error.
Just for reference, I have done the following:
When I Installed pyenv, I ran command nano ~/.bashrc (I'm using bash shell) - and pasted and saved on /.bashrc ---> eval "$(pyenv init -)"
then I ran pyenv install 2.7.7 (didn't work and found online step 3.)
CPPFLAGS="-I$(brew --prefix zlib)/include" pyenv install -v 2.7.7 (Again, same error and did step 4.)
ran brew reinstall zlib and overrode on "/.bashrc" eval "$(pyenv init -)" to:
export PATH="/usr/local/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
export LDFLAGS="-L/usr/local/opt/zlib/lib -L/usr/local/opt/bzip2/lib"
export CPPFLAGS="-I/usr/local/opt/zlib/include -I/usr/local/opt/bzip2/include"
-------------Start of Error ----------------
rm -f /Users/victor/.pyenv/versions/2.7.7/bin/python2
(cd /Users/victor/.pyenv/versions/2.7.7/bin; ln -s python2.7 python2)
rm -f /Users/victor/.pyenv/versions/2.7.7/bin/python2-config
(cd /Users/victor/.pyenv/versions/2.7.7/bin; ln -s python2.7-config python2-config)
rm -f /Users/victor/.pyenv/versions/2.7.7/bin/python-config
(cd /Users/victor/.pyenv/versions/2.7.7/bin; ln -s python2-config python-config)
test -d /Users/victor/.pyenv/versions/2.7.7/lib/pkgconfig || /usr/bin/install -c -d -m 755 /Users/victor/.pyenv/versions/2.7.7/lib/pkgconfig
rm -f /Users/victor/.pyenv/versions/2.7.7/lib/pkgconfig/python2.pc
(cd /Users/victor/.pyenv/versions/2.7.7/lib/pkgconfig; ln -s python-2.7.pc python2.pc)
rm -f /Users/victor/.pyenv/versions/2.7.7/lib/pkgconfig/python.pc
(cd /Users/victor/.pyenv/versions/2.7.7/lib/pkgconfig; ln -s python2.pc python.pc)
rm -f /Users/victor/.pyenv/versions/2.7.7/share/man/man1/python2.1
(cd /Users/victor/.pyenv/versions/2.7.7/share/man/man1; ln -s python2.7.1 python2.1)
rm -f /Users/victor/.pyenv/versions/2.7.7/share/man/man1/python.1
(cd /Users/victor/.pyenv/versions/2.7.7/share/man/man1; ln -s python2.1 python.1)
ERROR: The Python zlib extension was not compiled. Missing the zlib?
Please consult to the Wiki page to fix the problem.
https://github.com/pyenv/pyenv/wiki/Common-build-problems
BUILD FAILED (OS X 12.5 using python-build 20180424)
Inspect or clean up the working tree at /var/folders/__/1_b0871s7fl7fpwydg4ycjj80000gn/T/python-build.20220729111901.75727
Results logged to /var/folders/__/1_b0871s7fl7fpwydg4ycjj80000gn/T/python-build.20220729111901.75727.log
Last 10 log lines:
(cd /Users/victor/.pyenv/versions/2.7.7/bin; ln -s python2-config python-config)
test -d /Users/victor/.pyenv/versions/2.7.7/lib/pkgconfig || /usr/bin/install -c -d -m 755 /Users/victor/.pyenv/versions/2.7.7/lib/pkgconfig
rm -f /Users/victor/.pyenv/versions/2.7.7/lib/pkgconfig/python2.pc
(cd /Users/victor/.pyenv/versions/2.7.7/lib/pkgconfig; ln -s python-2.7.pc python2.pc)
rm -f /Users/victor/.pyenv/versions/2.7.7/lib/pkgconfig/python.pc
(cd /Users/victor/.pyenv/versions/2.7.7/lib/pkgconfig; ln -s python2.pc python.pc)
rm -f /Users/victor/.pyenv/versions/2.7.7/share/man/man1/python2.1
(cd /Users/victor/.pyenv/versions/2.7.7/share/man/man1; ln -s python2.7.1 python2.1)
rm -f /Users/victor/.pyenv/versions/2.7.7/share/man/man1/python.1
(cd /Users/victor/.pyenv/versions/2.7.7/share/man/man1; ln -s python2.1 python.1)
Victors-MacBook-Air:~ victor$ xcode-select --install
xcode-select: error: command line tools are already installed, use "Software Update" to install updates
Victors-MacBook-Air:~ victor$
Victors-MacBook-Air:~ victor$ xcode-select --install
xcode-select: error: command line tools are already installed, use "Software Update" to install updates
Victors-MacBook-Air:~ victor$
Victors-MacBook-Air:~ victor$ xcode-select --install
xcode-select: error: command line tools are already installed, use "Software Update" to install updates
Victors-MacBook-Air:~ victor$
Victors-MacBook-Air:~ victor$ software update
-bash: software: command not found
------------- End of Error -----------------
Any idea?.... Please let me know... I'd highly appreciate it
With a similar configuration, 2018 MBA on Monterey, I was having the same problem as you with pyenv install 2.7.6
I was able to go past the missing zlib issue with the following additions to the shell's profile:
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
export LDFLAGS="-L/usr/local/opt/zlib/lib"
export CPPFLAGS="-I/usr/local/opt/zlib/include"
export PKG_CONFIG_PATH="/usr/local/opt/zlib/lib/pkgconfig"
As a side note, the installation still didn't go through due to a different issue:
That OpenSSL issue has to do with OpenSSL 1.0 being EOL, more info here.
At the end I just went with 2.7.14 which is OpenSSL 2.0 compatible and good enough for my use case.
command line tools are already installed, use "Software Update" to install updates
This is indicating you need to use the Settings to update the command line tools.
$ software update
-bash: software: command not found
There is no command line called "software". Instead open system preferences. Then click on this:
Install any updates requested.

Is there a way to unarchive a dmg file like a tar.gz file? (Using Mac OS)

I'm trying to use a program that uses Linux versions of other programs.
I ran this in bash:
c3dpath=$( command -v c3d )
if [[ -z "${c3dpath}" ]]; then
echo "Command c3d was not found. Downloading and installing software to ${SCRIPTPATH}/depends/c3d. Path will be added to PATH environment variable."
mkdir -p "${SCRIPTPATH}/depends/c3d/"
wget https://downloads.sourceforge.net/project/c3d/c3d/Nightly/c3d-nightly-Linux-x86_64.tar.gz && \
tar -xzvf c3d-nightly-Linux-x86_64.tar.gz && mv c3d-1.1.0-Linux-x86_64/* "${SCRIPTPATH}/depends/c3d/" && \
rm c3d-nightly-Linux-x86_64.tar.gz
export PATH="${SCRIPTPATH}/depends/c3d/c3d-1.1.0-Linux-x86_64/bin/:$PATH"
fi
But it downloads the linux version of the program files into my directory -- yielding the error:
{..omitted}/HippMapp3r/depends/c3d/bin/c3d: cannot execute binary file
Return Code: 126
I understand in order for this to work on my computer, I need to use the version for Mac OS, however, I stuck on how one might go about "unarchiving" the files contained within a .dmg file so I can access c3d in bin.
I edited it to this, but I understand I cannot use the tar -xzvf command in this context -- is there an equivalent to tar -xzvf to "unpack" dmg files?
c3dpath=$( command -v c3d )
if [[ -z "${c3dpath}" ]]; then
echo "Command c3d was not found. Downloading and installing software to ${SCRIPTPATH}/depends/c3d. Path will be added to PATH environment variable."
mkdir -p "${SCRIPTPATH}/depends/c3d/"
wget https://downloads.sourceforge.net/project/c3d/c3d/Nightly/c3d-nightly-MacOS-x86_64.dmg && \
tar -xzvf c3d-nightly-MacOS-x86_64.dmg * "${SCRIPTPATH}/depends/c3d/" && \
rm c3d-nightly-MacOS-x86_64.dmg
export PATH="${SCRIPTPATH}/depends/c3d/c3d-nightly-MacOS-x86_64/bin/:$PATH"
fi
Try using 7-zip. You can install it on a Mac with homebrew using:
brew install p7zip
Then run it with:
7z
Please see comment by #StefanSchmidt about a possible alternative package.
First you have to mount the DMG file.
command: hdiutil mount test.dmg

Sketchup API on Mac

I am not able to have my CLI tool linked to slapi.framework working. It can be built, linked to the framework. I have added a Run Script build phase to copy the framework near the executable, and to change the #rpath of the executable:
set -x
DEST="$TARGET_BUILD_DIR"
mkdir -p "$DEST/Frameworks"
ln -fs "MY_PLACE/sdk/google-sketchup/macosx/slapi.framework" "$DEST/Frameworks"
install_name_tool -change #rpath/slapi.framework/Versions/Current/slapi #executable_path/Frameworks/slapi.framework/Versions/Current/slapi "$DEST/$TARGET_NAME"
When I run the executable, I got:
bash-3.2$ ./test_slapi
dyld: Library not loaded: #executable_path/../Frameworks/libCommonUnits.dylib
Referenced from: /Users/gdw/Documents/dev/code/test_slapi/Debug/./Frameworks/slapi.framework/Versions/Current/slapi
Reason: image not found
Trace/BPT trap: 5
Do not change the install name of slapi as you are doing. Instead, you should add slapi.framework's Libraries directory to your program's "Runpath Search paths".
But there is also a problem with the packaging of the framework. Please try the following commands in the terminal:
cd slapi.framework/Versions/Current/Libraries
install_name_tool -id #rpath/libCommonUnits.dylib libCommonUnits.dylib
install_name_tool -change #executable_path/../Frameworks/libCommonUtils.dylib #rpath/libCommonUtils.dylib libCommonUnits.dylib
install_name_tool -change #executable_path/../Frameworks/libCommonGeometry.dylib #rpath/libCommonGeometry.dylib libCommonUnits.dylib
That should fix the install name for libCommonUnits.dylib.
Thank you for your help... So it is common to change slapi rpath...
I have made a shell to change every thing...
! /bin/sh
for d in ./Versions/Current/slapi ./Versions/Current/Libraries/*.dylib; do
for p in $(otool -L "$d" | grep "#executable_path/../Frameworks/" | cut -f1 -d'('); do
echo "$p"
install_name_tool -id #rpath/$(basename "$p") "$p"
install_name_tool -change "$p" #rpath/$(basename "$p") "$d"
done
done
Now, when I run the tool, I do no longer have link error, but an Illegal instruction: 4
The call stack shows:
_xpc_runtime_init_once (Thread 1: EXE_BAD_INSTRUCTION (code=EXC_i386_INVOP, subcode=0x0)
dyldbootstrap::start(macho_header const*,in, char const**, long, macho_header const*, unsigned long *)

How to unpack and pack pkg file?

I have a pkg file created by Install Maker for Mac.
I want to replace one file in pkg. But I must do this under Linux system, because this is a part of download process. When user starts to download file server must replace one file in pkg.
I have a solution how unpack pkg and replace a file but I dont know how pack again to pkg.
http://emresaglam.com/blog/1035
http://ilostmynotes.blogspot.com/2012/06/mac-os-x-pkg-bom-files-package.html
Packages are just .xar archives with a different extension and a specified file hierarchy. Unfortunately, part of that file hierarchy is a cpio.gz archive of the actual installables, and usually that's what you want to edit. And there's also a Bom file that includes information on the files inside that cpio archive, and a PackageInfo file that includes summary information.
If you really do just need to edit one of the info files, that's simple:
mkdir Foo
cd Foo
xar -xf ../Foo.pkg
# edit stuff
xar -cf ../Foo-new.pkg *
But if you need to edit the installable files:
mkdir Foo
cd Foo
xar -xf ../Foo.pkg
cd foo.pkg
cat Payload | gunzip -dc |cpio -i
# edit Foo.app/*
rm Payload
find ./Foo.app | cpio -o | gzip -c > Payload
mkbom Foo.app Bom # or edit Bom
# edit PackageInfo
rm -rf Foo.app
cd ..
xar -cf ../Foo-new.pkg
I believe you can get mkbom (and lsbom) for most linux distros. (If you can get ditto, that makes things even easier, but I'm not sure if that's nearly as ubiquitously available.)
Here is a bash script inspired by abarnert's answer which will unpack a package named MyPackage.pkg into a subfolder named MyPackage_pkg and then open the folder in Finder.
#!/usr/bin/env bash
filename="$*"
dirname="${filename/\./_}"
pkgutil --expand "$filename" "$dirname"
cd "$dirname"
tar xvf Payload
open .
Usage:
pkg-upack.sh MyPackage.pkg
Warning: This will not work in all cases, and will fail with certain files, e.g. the PKGs inside the OSX system installer. If you want to peek inside the pkg file and see what's inside, you can try SuspiciousPackage (free app), and if you need more options such as selectively unpacking specific files, then have a look at Pacifist (nagware).
You might want to look into my fork of pbzx here: https://github.com/NiklasRosenstein/pbzx
It allows you to stream pbzx files that are not wrapped in a XAR archive. I've experienced this with recent XCode Command-Line Tools Disk Images (eg. 10.12 XCode 8).
pbzx -n Payload | cpio -i
In addition to what #abarnert said, I today had to find out that the default cpio utility on Mountain Lion uses a different archive format per default (not sure which), even with the man page stating it would use the old cpio/odc format. So, if anyone stumbles upon the cpio read error: bad file format message while trying to install his/her manipulated packages, be sure to include the format in the re-pack step:
find ./Foo.app | cpio -o --format odc | gzip -c > Payload
#shrx I've succeeded to unpack the BSD.pkg (part of the Yosemite installer) by using "pbzx" command.
pbzx <pkg> | cpio -idmu
The "pbzx" command can be downloaded from the following link:
pbzx Stream Parser
If you are experiencing errors during PKG installation following the accepted answer, I will give you another procedure that worked for me (please note the little changes to xar, cpio and mkbom commands):
mkdir Foo
cd Foo
xar -xf ../Foo.pkg
cd foo.pkg
cat Payload | gunzip -dc | cpio -i
# edit Foo.app/*
rm Payload
find ./Foo.app | cpio -o --format odc --owner 0:80 | gzip -c > Payload
mkbom -u 0 -g 80 Foo.app Bom # or edit Bom
# edit PackageInfo
rm -rf Foo.app
cd ..
xar --compression none -cf ../Foo-new.pkg
The resulted PKG will have no compression, cpio now uses odc format and specify the owner of the file as well as mkbom.
Bash script to extract pkg: (Inspired by this answer:https://stackoverflow.com/a/23950738/16923394)
Save the following code to a file named pkg-upack.sh on the $HOME/Downloads folder
#!/usr/bin/env bash
filename="$*"
dirname="${filename/\./_}"
mkdir "$dirname"
# pkgutil --expand "$filename" "$dirname"
xar -xf "$filename" -C "$dirname"
cd "$dirname"/*.pkg
pwd
# tar xvf Payload
cat Payload | gunzip -dc |cpio -i
# cd usr/local/bin
# pwd
# ls -lt
# cp -i * $HOME/Downloads/
Uncomment the last four lines, if you are using a rudix package.
Usage:
cd $HOME/Downloads
chmod +x ./pkg-upack.sh
./pkg-upack.sh MyPackage.pkg
This was tested with the ffmpeg and mawk package from rudix.org (https://rudix.org) search for ffmpeg and mawk packages on this site.
Source : My open source projects : https://sourceforge.net/u/nathan-sr/profile/

Installing readline 6.0 on OS X

I'm trying to install readline 6 from source but run into an error during 'make install'.
Here is the end of the output after executing 'sudo make install'
( cd shlib ; make DESTDIR= install )
/bin/sh ../support/mkdirs /usr/local/lib
/bin/sh ../support/shlib-install -O darwin9.7.0 -d /usr/local/lib -b /usr/local/bin -i "/usr/bin/install -c -m 644" libhistory.6.0.dylib
/bin/sh ../support/shlib-install -O darwin9.7.0 -d /usr/local/lib -b /usr/local/bin -i "/usr/bin/install -c -m 644" libreadline.6.0.dylib
install: you may need to run ldconfig
I know that ldconfig isn't installed by default on OS X, and I read somewhere that it shouldn't be needed to fix this issue. I believe it has something to do with dynamic libraries, but I haven't been able to find out how to fix the issue, anyone have any insight?
FYI, I'm running OS X on an intel 2.4ghz macbook
thanks
P.S. I also applied the 3 available readline 6 patches before running configure and make
Actually, this isn't an error at all... it's just a notice message at the end of the install. It get this too, and my readline 6 is happily installed.
If you check /usr/local/lib and see readline there, you're done :-) No need to run any equivalent of ldconfig.
$ ls /usr/local/lib | grep readline
libreadline.6.0.dylib
libreadline.6.dylib
libreadline.a
libreadline.dylib

Resources