[comp.sys.mac.programmer] INIT problem

purcell@sciences.sdsu.edu (Guy B. Purcell) (07/21/90)

I am having problems linking an INIT in MPW 3.1.  I followed the gist of the
CDEF example in the manual, but get a link error:
### Link: Error: Undefined entry, name: (Error 28) "main"
  Referenced from: CMain in file: Beyond Help:Development:MPW:Libraries:CLibrari
es:CRuntime.o

The name of my entry point is "main".  However, I noticed that the in the
CDEF example, the entry point is not all in caps but the -m link option
is.  So, I changed my -m option to "MAIN" & I get a different error:
### Link: Error: Data Initialization code is not being called. (Error 57) 

My question:  which is the correct -m option -- all caps or exactly as
the function is declared in the code?  If the latter, how do I link with the
runtime unit without the error?  Thanks lots.

Guy (purcell@zeus.sdsu.edu)

austing@Apple.COM (Glenn L. Austin) (07/21/90)

purcell@sciences.sdsu.edu (Guy B. Purcell) writes:

>I am having problems linking an INIT in MPW 3.1.  I followed the gist of the
>CDEF example in the manual, but get a link error:
>### Link: Error: Undefined entry, name: (Error 28) "main"
>  Referenced from: CMain in file: Beyond Help:Development:MPW:Libraries:CLibrari
>es:CRuntime.o

>The name of my entry point is "main".  However, I noticed that the in the
>CDEF example, the entry point is not all in caps but the -m link option
>is.  So, I changed my -m option to "MAIN" & I get a different error:
>### Link: Error: Data Initialization code is not being called. (Error 57) 

>My question:  which is the correct -m option -- all caps or exactly as
>the function is declared in the code?  If the latter, how do I link with the
>runtime unit without the error?  Thanks lots.

The second (all caps) is correct because the entry point should be defined as
a pascal procedure.  However, if you are using global data, static data, or
sprintf, the data initialization code needs to be called, since it isn't
called explicitly (this is done by an MPW-generated app at launch).  My
suggestion to you is:  if you are using sprintf, don't.  Use a combination of
the Mac Toolbox NumToString, strcat, p2cstr, etc.  You'll have to write a
little more code, but you'll have just as much control as you did with sprintf,
and you lose a lot of extra code baggage as well!

-- 
-----------------------------------------------------------------------------
| Glenn L. Austin               | "Turn too soon, run out of room,          | 
| Auto Racing Enthusiast and    |   Turn too late, much better fate"        |
| Communications Toolbox Hacker |   - Jim Russell Racing School Instructors |
| Apple Computer, Inc.          | "Drive slower, race faster" - D. Waltrip  | 
| Internet:   austing@apple.com |-------------------------------------------|
| AppleLink:  AUSTIN.GLENN      | All opinions stated above are mine --     |
| Bellnet:    (408) 974-0876    |                who else would want them?  |
-----------------------------------------------------------------------------