• Updated 2023-07-12: Hello, Guest! Welcome back, and be sure to check out this follow-up post about our outage a week or so ago.

hello world in C on OS 6.0.8 in MPW 3.1

ctarstar

Member
I'm trying to write a simple Hello World! in C in MPW on my Mac Plus running 6.0.8. I've gotten as far as getting MPW 3.1 installed - I have the C compiler and the link linker. 

I have what I believe are the right C libraries and interfaces - my program is the same as the one in the wiki:

#include <stdio.h>

void main () {
printf("Hello World");
}


So, I save this as hello.c, and in the MPW shell, I run:

C hello.c

and I get a hello.c.o file with no errors. Then, I'm trying to link as follows, and get the following errors:

link hello.c.o -o helloapp

### 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

I'm also not sure if I should be linking the stdclib.o file? I tried this, but getting the same error. Also, I'm not sure if I need to include other Mac-specific windowing code in order for this to actually run and do something. I'm looking for the simplest hello world example as possible just to understand how this works end-to-end before trying to do anything more complicated. The link command does produce hello.app with an app icon, but it doesn't run, and complains about being busy or damaged. 

Any pointers greatly appreciated!

 

IPalindromeI

Well-known member
just some random thinkies: Is this this the right function signature or name for main? Are you using a SIOW project? (SIOW is basically, give me stdio shims)

 

ctarstar

Member
just some random thinkies: Is this this the right function signature or name for main? Are you using a SIOW project? (SIOW is basically, give me stdio shims)
I have no idea! :)  

I'm just piecing together the breadcrumbs I found on a few sites, including these pages:

http://www.gryphel.com/c/minivmac/appc/

https://wiki.68kmla.org/C/C%2B%2B_Programming_for_68k

https://github.com/autc04/Retro68/tree/master/Samples/HelloWorld

I did come across something that showed how to walk through the build process, including selecting SIOW, but I no longer see that option (I think that was a later or earlier MPW? I had played around with a few to see what would work on 6.0.8 w/ a 4M Plus) and I also don't see a 68000 option on the build dialog window (only 68020 and higher). I was hoping to do everything within MPW shell, as examples above seemed to indicate that was possible (although part of the 68kmla wiki does reference a MainLoop() function, but not sure if that is the Main that OS 6 is looking for or not...

 

basalgangster

Well-known member
link -d -c 'MPS ' -t MPST ∂

hello.c.o ∂

"{CLibraries}"StdClib.o ∂

"{Libraries}"Stubs.o ∂

"{Libraries}"Runtime.o ∂

"{Libraries}"Interface.o ∂

-o helloapp

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. 

 

james_w

Well-known member
basalgangster, this is totally OT, but just wanted to say that I read *all* of your articles that are now archived on macgui.com and I really really enjoyed them - super informative and interesting!

 

ctarstar

Member
Thanks - I tried this, but actually still get the exact same error. I can tell that the libraries are being found, because if I misspell one, I get an error 'Bad parameter' complaining about the path for that particular library .o file. 

I assume your ∂ marks just mean to continue on the same line? Or, some equivalent to \ in unix? 

I did try to create the make file using the build dialog - so, I should just include my hello.c in the sources, and it should take care of the rest? It seemed to create the file OK, but when I go to build, I get an error 'Unable to open the resource fork of "224M os6 HD:MPW 3.1: Tools:Make' and when I try to run Make on its own out of the tools dir, it opens up MPW. 

Yes, actually, your article on MPW is one of the other ones I ran into, but I couldn't find it again. 

link -d -c 'MPS ' -t MPST ∂

hello.c.o ∂

"{CLibraries}"StdClib.o ∂

"{Libraries}"Stubs.o ∂

"{Libraries}"Runtime.o ∂

"{Libraries}"Interface.o ∂

-o helloapp

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. 
 

basalgangster

Well-known member
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.

Hope that helps.

 

ctarstar

Member
Ok, maybe I will try to replace Runtime.o or take one from a different MPW version/collection. I brought these files over from macintosh garden I think, to Mini vMac to a hard drive image to a Floppy EMU that is plugged into my Plus. Haven't had any other issues with corrupted files, so I'd be surprised if that's the case, but its possible the source was corrupted. 

I didn't notice a difference whether I just typed Enter at the end of the line, middle of the line, or after highlighting the entire line (I tried all three, but get the same error)

I also tried the multi-line version with the option-d ∂ (is that a sigma or a delta?) just in case, but got the same error. (and, again, I highlighted all lines before pressing Enter). I was just including the fact that running Make opens MPW to (I think?) validate that it 'works' or isn't damaged/corrupted. 

Thanks again - will let you know if replacing Runtime.o helps. I did try mis-spelling the reference in the link command as well, and then MPW complains about it, so it is at least finding the file. 

 
Top