MacOS bundle's binary can't run

I made a project with MacOS/Bundle/Objective-C. I added main.m as like:

#import <Foundation/Foundation.h> int main (int argc, const char * argv[]) { printf("Test\n"); }

Built it and the generated bundle. I open the bundle with Finder and located the binary in the MacOS directory within the bundle. The file command returned as like:

<path...>TestProject: Mach-O universal binary with 2 architectures: [x86_64:Mach-O 64-bit bundle x86_64] [arm64:Mach-O 64-bit bundle arm64] <path...>TestProject (for architecture x86_64):Mach-O 64-bit bundle x86_64 <path...>TestProject (for architecture arm64): Mach-O 64-bit bundle arm64

It apparently generated the Universal binary. Of course, no error were reported on building.

I tried to execute the binary with drag&drop the file into Terminal, but shell reported as like:

zsh: exec format error: <path..>TestProject

These are reproducing my trouble. My target project is so old but it can generate executable x86_64 only binary. I want to be universal binary. My Xcode is 15.4 on Sonoma.

In the future, please format your code as code blocks (using triple backquotes). That’ll make it easier to read. See Quinn’s Top Ten DevForums Tips for this and other hints.

Regarding your main issue, I’m not sure I understand what you’re doing here. I tried replicating your steps, and things worked for me. Let me explain the steps I took, and then perhaps you can point out where I went wrong.

Here’s what I did:

  1. Using Xcode 15.4 on macOS 14.5, I created a new project from the macOS > App template. I selected Storyboard for the Interface and Objective-C for the language.

  2. I replaced main.m with this code:

    #import <Cocoa/Cocoa.h>
    
    int main(int argc, const char * argv[]) {
        printf("Hello Cruel World!\n");
        return EXIT_SUCCESS;
    }
    
  3. I built the app.

  4. I moved the built app to my home directory, just to make it easier to access.

  5. I double clicked the app in the Finder. It launched and then immediately quit, which is what I expected.

  6. I opened a window in Terminal and then ran the app’s main executable:

    % ~/Test6531724.app/Contents/MacOS/Test6531724 
    Hello Cruel World!
    

As you can see, it ran and printed the expected string.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

MacOS bundle's binary can't run
 
 
Q