8

I've been setting up a Basilisk II emulator to try my hand at developing apps for 68k System 7 systems, and have set up the Macintosh Programmer's Workstation (v.3.5 Gold Master from MacintoshRepository.org). I wrote up a standard hello.c program:

#include <stdio.h>

int main (void) {
    printf("hello, world!\n");
    return 0;
}

After compiling with SC hello.c, I got a file hello.c.o, but when I tried executing the program, it tells me that "file hello.c.o is not executable".

I figured to try linking it with link, but am still getting an error:

### link: Error: Main code (-m option) name not found. (Error 53) %__MAIN
### link: Error: No Main code module or entry point. (Error 38)
### link: Errors prevented normal completion.

What to do? Am I missing a step?

8
  • 1
    You should add link option -t 'MPST' to create a command line tool rather than an application (which would need to initialize the GUI Toolbox etc). And -m 'main' will set the main entry point. Commented Mar 28 at 11:02
  • Got this error message, Mr Hugh Fisher ### LINK: Error: Undefined entry, name: (Error 28) "printf" Referenced from: main in file: hello.c.o ### LINK: Errors prevented normal completion.
    – gorgo
    Commented Mar 28 at 11:15
  • As a general observation, if you want to use a runtime library you need to link with the runtime library. How that is done in your case I don't know. Maybe -lc ?
    – dave
    Commented Mar 28 at 11:43
  • 4
    @AaravGarg I'm picking here the comment you made to PoC answer: “I'm new to this space and do not have access to such resources.” So, you want to develop on an environment you don't know, you don't have any documentation upon, and you don't have (as you're running an emulator). May I ask you why you would want to do so, and what you would want to achieve? Not to be disdainful, just really interested in your answer.
    – Olivier
    Commented Mar 28 at 13:53
  • 3
    You may already be aware, @AaravGarg, but MacOS classic is not an older version of modern MacOS. The two are completely different operating systems. Modern MacOS is the current form of the BSD-derived OS that Apple originally called "Mac OS X". What is now called MacOS classic was an all-Apple-developed OS emerging from the company's line of previous OS's, the immediate predecessor being Lisa OS. Commented Mar 28 at 16:38

2 Answers 2

6

TL;DR

It is perfectly possible to run command line tools (that use stdio.h), on a Macintosh, but only from within MPW.

For MPW 3.2.3

C hello.c
Link -d -c 'MPS ' -t MPST hello.c.o "{CLibraries}"StdClib.o "{Libraries}"Stubs.o "{Libraries}"Runtime.o "{Libraries}"Interface.o -o helloapp
helloapp
hello, world!

For MPW 3.5

SC hello.c
Link -d -c 'MPS ' -t MPST hello.c.o "{CLibraries}"StdClib.o "{Libraries}"Stubs.o "{Libraries}"MacRuntime.o "{Libraries}"Interface.o "{Libraries}"IntEnv.o  -o helloapp
helloapp
hello, world!

Note that it is safer (and simpler) to use the Build menu tools, provided by the UI:

  • BuildCreate Build Commands...
  • BuildBuild...

A useful thread

You might find the following useful.

From post#5 on hello world in C on OS 6.0.8 in MPW 3.1, where someone was having the same issue as you (although this issue was on System 6 rather than System 7):

link -d -c 'MPS ' -t MPST ∂
hello.c.o ∂
"{CLibraries}"StdClib.o ∂
"{Libraries}"Stubs.o ∂
"{Libraries}"Runtime.o ∂
"{Libraries}"Interface.o ∂
-o helloapp

where is option+D

This same post goes on to say:

Or, you could just select Create Make Commands... from the build menu, and fill out the dialog, selecting source files, target architecture, etc. -c and -t set the file type and creator. Single quotes on 'MPS ' are required because this is M P S space. The libraries are what you need for a tool. When getting started, Create Make Commands is preferred over doing it yourself because it knows what libraries you need to link.

The following post#8 states:

Yes, the option-d is the continuation character.

Your original error is caused by not linking with Runtime.o. That is where %__MAIN (the entry point) is defined. Did you select the entire thing (all the lines containing the commands to build the program), and then type enter to execute the entire thing? If so, I worry that there might be something wrong with your Runtime.o file. Could it have become corrupted somehow?

If you double click a tool in the Tools Directory, it will only launch MPW. To run make, you don't double click it, but rather type its name in the shell, Unix style. Anyway, you never even need to run Make that way. You can go to the Build menu and select Build... or Show Build Commands.... Build will run Make and build your program. Show Build Commands... will write the lines of shell script needed to build your program. You then select the entire set of lines, and hit enter. Try selecting Build... from the Build menu and see if MPW can build your program.

FWIW, The author of these two posts, basalgangster, has written extensively on macgui.com.


Error reproduction in MPW 3.5

I have reproduced your errors, and yes Runtime.o is missing. The linked thread also states (in post#9) that the MPW collection from Macintosh Garden is also missing Runtime.o:

link -d -c 'MPS ' -t MPST hello.c.o "{CLibraries}"StdClib.o "{Libraries}"Stubs.o "{Libraries}"Runtime.o "{Libraries}"Interface.o -o helloapp

### link: File not found (OS error -43)  
### link: Error: Can't open object file for input. (Error 32) Macintosh HD:MPW-GM:MPW::Interfaces&Libraries:Libraries:Libraries:Runtime.o
### link: Errors prevented normal completion.

Screenshot of errors

If you follow the path (MPW-GM:MPW::Interfaces&Libraries:Libraries:Libraries), you will see that Runtime.o isn't there, but MacRuntime.o is (due to changes made to MPW circa version 3.4/3.5). If you use MacRuntime.o instead, then you get a bit further, but with a different set of errors

link -d -c 'MPS ' -t MPST hello.c.o "{CLibraries}"StdClib.o "{Libraries}"Stubs.o "{Libraries}"MacRuntime.o "{Libraries}"Interface.o -o helloapp
### link: Error: Undefined entry, name: (Error 28) "_iob"
  Referenced from: printf in file: Macintosh HD:MPW-GM:MPW::Interfaces&Libraries:Libraries:CLibraries:StdClib.o
### link: Error: Undefined entry, name: (Error 28) "_flsbuf"
  Referenced from: _doprnt in file: Macintosh HD:MPW-GM:MPW::Interfaces&Libraries:Libraries:CLibraries:StdClib.o
### link: Error: Undefined entry, name: (Error 28) "_wrtchk"
  Referenced from: fwrite in file: Macintosh HD:MPW-GM:MPW::Interfaces&Libraries:Libraries:CLibraries:StdClib.o
### link: Error: Undefined entry, name: (Error 28) "write"
  Referenced from: fwrite in file: Macintosh HD:MPW-GM:MPW::Interfaces&Libraries:Libraries:CLibraries:StdClib.o
### link: Error: Undefined entry, name: (Error 28) "errno"
  Referenced from: fwrite in file: Macintosh HD:MPW-GM:MPW::Interfaces&Libraries:Libraries:CLibraries:StdClib.o
### link: Error: Undefined entry, name: (Error 28) "MacOSErr"
  Referenced from: fwrite in file: Macintosh HD:MPW-GM:MPW::Interfaces&Libraries:Libraries:CLibraries:StdClib.o
### link: Error: Undefined entry, name: (Error 28) "_xflsbuf"
  Referenced from: fwrite in file: Macintosh HD:MPW-GM:MPW::Interfaces&Libraries:Libraries:CLibraries:StdClib.o
### link: Error: Undefined entry, name: (Error 28) "_bufsync"
  Referenced from: fwrite in file: Macintosh HD:MPW-GM:MPW::Interfaces&Libraries:Libraries:CLibraries:StdClib.o
### link: Errors prevented normal completion.

To fix these errors you need to also include IntEnv.o (see below).

Further notes

For MPW v3.2.3

If you use MPW 3.2.3, again from Macintosh Repository (MPW_1.0_3.1_3.2_and_68k_Developer_Kit.zip), then the commands (from the thread linked to above) work fine.

C hello.c
link -d -c 'MPS ' -t MPST hello.c.o "{CLibraries}"StdClib.o "{Libraries}"Stubs.o "{Libraries}"Runtime.o "{Libraries}"Interface.o -o helloapp

Here is a screen shot, showing the hello world code compiling, linking and running, from within MPW 3.2.3:

Screenshot of success in MPW 3.2.3

In text form:

C hello.c
Link -d -c 'MPS ' -t MPST hello.c.o "{CLibraries}"StdClib.o "{Libraries}"Stubs.o "{Libraries}"Runtime.o "{Libraries}"Interface.o -o helloapp
helloapp
hello, world!

For MPW 3.5

Changes made around MPW v3.4/3.5, mean that Runtime.o is now MacRuntime.o and you also have to include IntEnv.o:

SC hello.c -sym off -model near
Link -d -c 'MPS ' -t MPST hello.c.o "{CLibraries}"StdClib.o "{Libraries}"Stubs.o "{Libraries}"MacRuntime.o "{Libraries}"Interface.o "{Libraries}"IntEnv.o  -o helloapp

The Link command above is a severely pruned version of the command generated by the MPW Build... menu item:

ILink -o helloapp ":hello.c.o" "{Libraries}Stubs.o" "{Libraries}MathLib.o" "{CLibraries}StdCLib.o" "{Libraries}MacRuntime.o" "{Libraries}IntEnv.o" "{Libraries}ToolLibs.o" "{Libraries}Interface.o" -sym off -mf -d -t 'MPST' -c 'MPS ' -model near -state rewrite -compact -pad 0

Here is a screen shot, showing the hello world code compiling, linking and running, from within MPW 3.5:

Screenshot of success in MPW 3.5

In text form:

SC hello.c
Link -d -c 'MPS ' -t MPST hello.c.o "{CLibraries}"StdClib.o "{Libraries}"Stubs.o "{Libraries}"MacRuntime.o "{Libraries}"Interface.o "{Libraries}"IntEnv.o  -o helloapp
helloapp
hello, world!

Summary

  • Note that for both versions of MPW, there is no need to use the -m 'main' option - that is a red herring from your original linker error.

  • The main issue why the commands from the thread do not work in MPW 3.5 is that:

    • MPW version 3.5 does not have the file

      Libraries:Libraries:Runtime.o
      

      whereas version 3.2.3 does. MPW 3.5 has MacRuntime.o instead.

    • MPW 3.5 also requires that you include

      "{Libraries}"IntEnv.o
      
  • You can not double click the application, or rather, the "MPW tool" - for obvious reasons (there is no standard IO) - you have to run helloapp from within MPW environment.

  • MPW 3.2.3 uses C, whereas MPW 3.5 uses either SC (Symantec C) for 68k, or MrC for PowerPC - see this answer to Building hello world on a Macintosh IIfx with MPW for more details.

  • If you want to see the full story, please read Building a “hello, world!” program using MPW – Reproduction steps.

Documentation

You can find a wealth of documentation on vintageapple.org.

Inside Macintosh:

MPW:

An assortment of programming guides:

3
  • 1
    By the way, the first code snippet didn't work; Runtime.o is not a thing? But the Create Build Commands step worked like a charm!
    – gorgo
    Commented Mar 29 at 5:21
  • 1
    In the makefile generated by Create Build, these are the libraries specified. LibFiles-68K = ∂ "{Libraries}MathLib.o" ∂ "{CLibraries}StdCLib.o" ∂ "{Libraries}SIOW.o" ∂ "{Libraries}MacRuntime.o" ∂ "{Libraries}IntEnv.o" ∂ "{Libraries}ToolLibs.o" ∂ "{Libraries}Interface.o"
    – gorgo
    Commented Mar 31 at 4:14
  • Comments are not for extended discussion. Please continue this discussion in chat.
    – wizzwizz4
    Commented Apr 4 at 1:48
4

Classic MacOS has no concept of stdin/stdout compared to POSIX conformant platforms. See the comment of Hugh Fisher for a workaround.

It might be beneficial to read the initial Inside Macintosh books for general ideas how to program applications for the older MacOS environment.

9
  • 1
    But command-line programs are supported? Mr. Fisher's comment was helpful but gave an error message as I have posted above. While I'd love to read the Inside Macintosh books, I'm afraid I'm new to this space and do not have access to such resources.
    – gorgo
    Commented Mar 28 at 12:07
  • @AaravGarg Inside Macintosh is basically the classic Mac OS Apple equivalent to the MSDN library. While I don't personally know whether Apple ever offered a downloadable version on their website, I know they did make tons of digital releases of it over the years. (eg. At least one of the monthly Apple Developer CDs would include it each year... probably more before they needed to split off the QuickDraw GX stuff and put it on a different month's CD.)
    – ssokolow
    Commented Mar 28 at 14:18
  • 3
    MPW acts as a command shell, which can run programs that interact with stdin, stdout, and stderr, and can make them interact with the Workspace, or redirect them using less-than (stdin), greater-than (stdout), greater-than-or-equal (stderr), or uppercase sigma (both stdout and stderr).
    – supercat
    Commented Mar 28 at 14:38
  • 1
    As an aside, with the Aztec C development kit for the Macintosh, this would have "just worked". They provided a more conventional command line style development environment with a shell, and vi as the editor. Very basic UNIX-like environment. But it was designed to create Mac applications. Commented Mar 28 at 16:59
  • 1
    This isn't an answer to the question. The link step has failed because there's no __MAIN symbol defined. I wonder if -m allows you to specify a main function
    – JeremyP
    Commented Mar 28 at 17:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .