“zsh: killed” — problem in shell, or my own Xcode build?

I have recently moved from a 2014 laptop running Big Sur to a 2021 M1 running Monterey. To make it more complicated I chose this moment to switch from bash to zsh. I am trying to get my own experimental code (“texsyn”) running again.


“texsyn” is a unix executable (command line tool), a c++ program which links to OpenCV. It runs fine using Xcode’s ⌘R command. But it no longer runs from the command line. There I see:


> texsyn 
zsh: killed     texsyn


I poked a bit:


> which texsyn
/usr/local/bin/texsyn
> echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Library/Apple/usr/bin
> /usr/local/bin/texsyn
zsh: killed     /usr/local/bin/texsyn
> ls -l /usr/local/bin/texsyn 
-rwxr-xr-x  1 cwr  admin  937960 Jun 29 10:28 /usr/local/bin/texsyn


Which seemed fine. I found a discussion from about four months ago: zsh: killed - Apple Community


The answer by MrHoffman made sense, and indeed I found 8 year old command in my .zshrc apparently left over from an old project. As MrHoffman suggested I: closed Terminal, set aside the old zsh dot files (.zshrc, .zprofile, and .zlogin), and relaunched Terminal.


The symptom was unchanged “texsyn” → “zsh: killed”.


It dawned on me that I had only seen this symptom with my own executable so that maybe the problem was with my build/install in Xcode?


Does anyone recognize this symptom? Or have a suggestion where to look next?


MacBook Pro Apple Silicon

Posted on Jun 30, 2022 4:48 PM

Reply
Question marked as Top-ranking reply

Posted on Jul 1, 2022 4:48 PM

Thanks to both etresoft and MrHoffman for the helpful information.


I have decided to take the path of least resistance and get on with my life, doing the research this software embodies. 


As I mention earlier, the copy of my executable way inside Xcode’s build directory works exactly as I want. But when I use Build Phases and Copy Files and Code Sign On Co... to put a signed copy in /usr/local/bin, it does not work. So my problem goes away if I use the executable tucked way down inside Xcode’s build folder, found using Show Build Folder in Finder. Aside from having an ungainly pathname, /Users/cwr/Library/Developer/Xcode/DerivedData/TexSyn-gfzhwwjftbwzeiedmqmlvlrtrirm/Build/Products/Release/texsyn runs in Terminal as I need, without any code signing grief.



Huzzah!



In case anyone is still reading at this point: does it seem odd that the one executable works while the signed installed copy of it does not? etresoft has made comments that might relate to this issue, but I don’t have the background to understand. 


And what is the deal with that checkbox labeled “Code Sign On Co...”?! I spent some time just now trying to adjust column widths, removing sidebars, etc. but I can’t make it unabbreviate.

Similar questions

6 replies
Question marked as Top-ranking reply

Jul 1, 2022 4:48 PM in response to cwr

Thanks to both etresoft and MrHoffman for the helpful information.


I have decided to take the path of least resistance and get on with my life, doing the research this software embodies. 


As I mention earlier, the copy of my executable way inside Xcode’s build directory works exactly as I want. But when I use Build Phases and Copy Files and Code Sign On Co... to put a signed copy in /usr/local/bin, it does not work. So my problem goes away if I use the executable tucked way down inside Xcode’s build folder, found using Show Build Folder in Finder. Aside from having an ungainly pathname, /Users/cwr/Library/Developer/Xcode/DerivedData/TexSyn-gfzhwwjftbwzeiedmqmlvlrtrirm/Build/Products/Release/texsyn runs in Terminal as I need, without any code signing grief.



Huzzah!



In case anyone is still reading at this point: does it seem odd that the one executable works while the signed installed copy of it does not? etresoft has made comments that might relate to this issue, but I don’t have the background to understand. 


And what is the deal with that checkbox labeled “Code Sign On Co...”?! I spent some time just now trying to adjust column widths, removing sidebars, etc. but I can’t make it unabbreviate.

Jun 30, 2022 5:27 PM in response to etresoft

etresoft — thank you for your reply!


Could you explain how to give my executable an “ad-hoc signature”?


I was poking around in my Xcode project and on the settings for Build Phases, there is a Copy Files for /usr/local/bin. Where it lists the target (“texsyn”) there is a checkbox on that which says “Code Sign On Co...” which seems like it is just a few characters too short to be helpful.


I also found the app menu item [Product][Show Build Folder in Finder] I did that and dug down to my executable. When I dragged that into my Terminal window and typed return, it worked fine!

Jun 30, 2022 7:31 PM in response to cwr

Some reading...


https://eclecticlight.co/2020/08/22/apple-silicon-macs-will-require-signed-code/


Code Signing Tasks


codesign -s - {path}


Here's a test:


$ clang x.c -o x
$ chmod +x x
$ ~/x
hello world
$ codesign -s - x
$ ~/x
hello world
$ cat x.c
#include <stdio.h>
#include <stdlib.h>

int  main(void)
{
  printf("hello world\n");
  exit(EXIT_SUCCESS);
}
$ codesign --verify --verbose ~/x
~/x: valid on disk
~/x: satisfies its Designated Requirement
$ 


Jul 1, 2022 1:00 PM in response to cwr

cwr wrote:

Could you explain how to give my executable an “ad-hoc signature”?

Normally it isn't something you need to worry about. Just do an "archive" build and the output should be ready to use.


The trouble comes in when there are bugs in your code and you need to build a few more versions. That is when you can get caught by the caching issues.

I checked the “Code Sign On Co...” (“Code Sign On Copy”?) and rebuilt. Now the executable can run in Terminal but immediately aborts trying to load OpenCV libraries from Homebrew:

Ah, Homebrew. Another likely candidate would be Qt. I can't really help with that. Sorry.

Jun 30, 2022 5:01 PM in response to cwr

This has nothing to do with zsh.


Most likely, your executable isn't signed. On Apple Silicon, it should have at least an ad-hoc signature.


But even then, you can get the same problem due to caching of the executable. You may need to copy the file to a unique path, run it once, and then copy it to the final installation path. Or something like that.

Jun 30, 2022 7:26 PM in response to cwr

I checked the “Code Sign On Co...” (“Code Sign On Copy”?) and rebuilt. Now the executable can run in Terminal but immediately aborts trying to load OpenCV libraries from Homebrew:


> texsyn
dyld[75095]: Library not loaded: /opt/homebrew/opt/opencv/lib/libopencv_gapi.405.dylib
  Referenced from: /usr/local/bin/texsyn
  Reason: tried: '/opt/homebrew/opt/opencv/lib/libopencv_gapi.405.dylib' (code signature in <13B9A264-FD4A-3CE6-9C5D-8DF461301B8F> '/opt/homebrew/Cellar/opencv/4.5.5_2/lib/libopencv_gapi.4.5.5.dylib' not valid for use in process: mapped file has no Team ID and is not a platform binary (signed with custom identity or adhoc?)), '/usr/lib/libopencv_gapi.405.dylib' (no such file), '/opt/homebrew/Cellar/opencv/4.5.5_2/lib/libopencv_gapi.4.5.5.dylib' (code signature in <13B9A264-FD4A-3CE6-9C5D-8DF461301B8F> '/opt/homebrew/Cellar/opencv/4.5.5_2/lib/libopencv_gapi.4.5.5.dylib' not valid for use in process: mapped file has no Team ID and is not a platform binary (signed with custom identity or adhoc?)), '/usr/lib/libopencv_gapi.4.5.5.dylib' (no such file)
zsh: abort      texsyn


In Xcode Project Build Settings, under Signing, I do “Sign to Run Locally”, Enable Hardened Runtime is No.


I am looking for the most permissive way to run my own code on my own machine. Don't need to distribute the executable.



This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

“zsh: killed” — problem in shell, or my own Xcode build?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.