NOTE: This Technical Note has been
retired. Please see the Technical Notes
page for current documentation.![]() ![]() |
IntroductionOctober 1990 Linking a stand-alone code resource that uses sprintfDate Written: 1/21/93 Last reviewed: 7/2/93 I want to use sprintf in a standalone code resource, but I'm having trouble linking my resource because sprintf apparently requires data-to-code references. I get the error shown below; what can I do to avoid this?
Unfortunately, a great deal of the standard C library uses globals, which
necessitates your creating an A5 world as described in the Macintosh Technical
Note "Stand-Alone Code, ad nauseam"(Platforms & Tools 35). Additionally,
some of the global data used is initialized with function pointers. For
example, if you had the following global variable defined
where Fortunately, there's a workaround. Because the standard library is written very generally and uses a lot of indirection, the linker believes sprintf might use some of the standard output calls; however, it never does, and since it's these calls that necessitate the use of the data-to-code references, if we can fool the linker into accepting an innocuous substitute, we won't require the data-to-code references that are causing us such agony now. To cut to the chase, add the following lines to your code somewhere:
The first two calls override Decompressing compressed System 7 file resourcesDate Written: 1/22/91 Last reviewed: 6/14/93 I tried to DeRez some of the resources in my MacintoshSystem 7.0 system file, but for some of them all I got was garbage. Why?
Some of the resources shipped by Apple with System 7.0 are compressed. If you wish to examine the contents of one of these compressed resources, use ResEdit version 2.1. It will warn you that the resource you're about to examine is compressed and that the resource must be decompressed to edit it (after which you can use DeRez to examine it in all its textual glory). InitGraf is only managers' init routine called by MPW ToolsDate Written: 1/28/91 Last reviewed: 8/1/92 I have compiled and linked a multi-segmented MPW tool using the following switches in a Build/MAKE file:
I believe the above set of compile and link switches will, among other things, allow me to generate multi-segmented code without having to resort to #pragma segment directives in the source. Please correct me if I am wrong.
I have no difficulty building a multi-segmented product using THINK C 4.0.
Although the MPW tool seems to build properly, when I run the tool, I get a bus
error deep down in ROM after a call in my source to
The call to
There certainly doesn't appear to be anything wrong with your segmentation approach; it's very unlikely that it's the source of your problem.
What is more likely is that you're initializing more than you need to in your
tool. MPW Tools must call MPW 3.2 'HEXA' resourcesDate Written: 6/11/91 Last reviewed: 6/14/93
What are the four
Each 128 : initial stack size 129 : initial number of master pointers 130 : inital pointer zone size (MPW allocates a block for random pointers) 131 : pointer zone delta (when the zone fills, MPW allocates this much more room).
So, if you want to make more memory available to your MPW tools (like the
linker and compiler), you can try modifying some of these values, starting with
the Balloon Help with MPW ToolsDate Written: 8/13/91 Last reviewed: 6/14/93 Is it possible to add Balloon Help to MPW 3.2 Tools?
After extensive head scratching, the answer is yes/no/no. There are basically
three scenarios that might require Balloon Help: The first is if your tool
takes it upon itself to have its own human interface with dialogs and windows
of its own. This is not supported under MPW, but several people have succeeded
in getting it to work with much work and programming. If you have gotten this
to work, then Balloon Help is easy. It works just like an application; simply
add the As for MPW supplied dialogs and alerts that may come up while your tool is running, there is no way to override the resources being loaded in many cases, since the dialogs are not created from a DLOG. In the case of MPW-supplied dialogs, Balloon Help is non-modifiable for you. As for the only other dialog associated with your tool, the Commando dialog, you cannot add balloons to this either, but that is no real problem since Commando has its own built-in help system that allows you to associate help with any item in the commando dialog. "-model far" and "PC-relative edit" link errorDate Written: 10/4/91 Last reviewed: 6/14/93 When using "-model far," I get the following error from the linker:
What does it mean? In your Link command, you should put Runtime.o and the object file containing your main program close together, and as early in the list as possible. This is because %__MAIN (the part of Runtime.o that actually receives control when your application is launched) uses a PC-relative BSR instruction to transfer control to your "real" main. (OK, so it's "32-bit-almost-everything"!) "-model far" affects jump table & code segment, not code moduleDate Written: 10/4/91 Last reviewed: 6/14/93 I can't define a procedure larger than 32K, even if I use -model far. -Model farcode relaxes the 32K limit on jump table size, and eliminates the 32K limit on code segment size. It does not affect the limit on the size of an individual module: that remains at 32K. This is why you had trouble with your strings. [We don't expect the module-size limitation to be relaxed anytime soon]. MPW linker problem with PC-relative function address productionDate Written: 10/29/91 Last reviewed: 8/1/92 When I use "-model far" in MPW 3.2, all my intra-segment function addresses are calculated from the actual code address, rather than as a jump table address. What can I do to work around this? Thanks for your report of a problem with the MPW linker regarding production of PC-relative function addresses. This is a verified bug. Until it's fixed, you can either (1) place your functions in segments other than the segments where the address is taken, to force A5-relative addressing, or (2) place all functions whose addresses might be taken into a segment which is never unloaded, so that an absolute address is acceptable. MPW ScriptCheck 3.2.1 and file or resource atom size fieldDate Written: 12/19/91 Last reviewed: 6/14/93 Is there a way to keep ScriptCheck 3.2.1 from overwriting the size field in file and resource atoms? I'm implementing a decompression action atom and need the Installer to check that there is sufficient hard disk space to decompress the compressed files.
This is a limitation of the current ScriptCheck version. Engineering is looking
into revising the tool so that ScriptCheck will leave this field alone if
desired. As things stand, after using ScriptCheck, one would need to use
ResEdit to enter the correct values into the MPW Linker "Data initialization code not called" errorDate Written: 5/3/89 Last reviewed: 6/14/93 The MPW linker is reporting a "Data initialization code not called" error. What is wrong? This usually happens when trying to link an INIT or XCMD/XFCN code resource. Code resources are not allowed to use global variables or variables that are initialized at declaration time. First, make sure that you aren't using any global or static variables. In Pascal and C, a global variable is one that is declared outside of any function or procedure. Also note that in MPW C, string constants (e.g. "hello, world") are actually compiled as global variables (MPW C 3.0 has the -b option to override this). If you are using MPW C, check for string constants in your code. To work around the string constant problem, read the string from a resource file:
becomes:
Variables that are initialized at declaration time in the source code are actually initialized when the program starts up. The compiler generates the initialization code and puts it in a segment called %A5INIT. Because XCMDs, for example, must be a single segment, you can't link the %A5INIT segment as well. You need to change the initialization to an explicit assignment at the beginning of the code: becomes:
MPW 3.0 Linker and VaccineDate Written: 5/3/89 Last reviewed: 6/14/93 The MPW 3.0 Linker hangs or prints odd error messages when I try to link my program. What's wrong? This is usually a problem associated with Vaccine, the anti-virus 'INIT'. You will either get the following error messages, or the Linker will apparently hang:
In the former case, either remove Vaccine, or select the option that allows MPW to work (in the current version of Vaccine). In the latter case, the MPW option has already been set, and Vaccine is merely waiting for you to press "y" to signify that the link process should continue. MPW "unable to swap in Shell segment" errorDate Written: 5/3/89 Last reviewed: 8/1/92 What causes an MPW tool to abort with the message, "Unable to swap in Shell segment"? This message almost always means memory allocation problems. It is most often encountered when compiling and linking large programs, especially with the -sym option. It often goes away in subsequent executions of the tool or when you exit and re-launch the shell. Another symptom that MPW is on the edge is the dreaded "bulldozer" cursor. You may think MPW is hung in this case, but thrashing itself to death is a better description. Try increasing the MultiFinder memory partition of the Shell and see if the problem persists. A better option under MPW 3.2 is to use the -mf option to enable the use of MultiFinder temporary memory, if the tool supports it. MPW "unable to swap in tool segment" errorDate Written: 5/3/89 Last reviewed: 8/1/92 When linking my application I get the error "unable to swap in tool segment." What has gone wrong? The MPW linker has run out of memory. The first thing you can try is to turn off the RAM cache (with the Control Panel). If that doesn't work, then take out your debugger. You will also want to remove any memory-hungry cdevs and 'INIT's. Another way to solve your problem is to segment your program using the Segment Loader (that is, make your big app into many little apps). If you still have problems, you need to get more memory. New calls available as MPW 3.2 glue for System 6Date Written: 6/24/91 Last reviewed: 6/14/93 How do I find out what calls in Inside Macintosh Volume VI are accessible from System 6? As it turns out, there isn't a comprehensive list of calls that are available as MPW glue. I used the search command in MPW 3.2 to search for "#ifdef SystemSevenOrLater" to locate the full list:
And also, if you have a sense of history:
In other words, MPW Rez and AnimCursors frame field color cursor bitDate Written: 6/14/91 Last reviewed: 6/14/93
DTS's It looks like the folks who put together the Rez template didn't know about the bit. To get around this, copy the 'acur' template from Types.r into your own include file, and change the first "fill word;" line to */ This should get you on your way (albeit with one more compilation warning). The alternative is to define the resource as raw data, the way the sample does (of course, it has the excuse that it existed before types.r knew about it). MPW Backup command problem reportDate Written: 3/18/91 Last reviewed: 8/1/92
When I use the MPW Backup command to generate a list of
But when I use the form:
The "to" or destination folders are not correctly generated in the output file. An example is shown below:
Note that the
I tried to duplicate everything that you've done, and I came up with exactly
the opposite results: Using the MPW 3.2 Backup command with the -check newer
parameter, subdirectories are NOT generated recursively, but with the -since
'01/01/04' parameter, the MPW Linker (-pg) optionDate Written: 10/31/90 Last reviewed: 6/14/93 Link option (-pg) allows you to set the page size. The use is or some integer greater than 1024, which is the default size. Use "Duplicate" to split file into data & resource fork filesDate Written: 12/14/90 Last reviewed: 6/14/93 Is there any simple way under MPW to split a Macintosh file into two new files--one containing the data fork and the other containing the resource fork? The "Duplicate" tool will do this quite easily. Either use the Commando dialog, or this from the command line:
Debugging MPW Tools with SADEDate Written: 5/1/91 Last reviewed: 6/14/93 How do I debug MPW Tools written in Pascal using SADE 1.0? Keep in mind the following:
To start working with SADE on an MPW tool (in Pascal), compile and link the ResEqual tool in the Pascal examples folder using MPW. Here are the commands I used from MPW to do this:
Once the
You shouldn't have to use the
Next, execute the MPW Shell by double clicking it from the Finder or by
launching it from SADE (the launch command). The target command may launch it,
depending on the version of SADE that you are using. Once you're in MPW,
execute the tool (type in MPW Linker >65K global size error message (Error 34)Date Written: 4/2/92 Last reviewed: 6/14/93 We have been using the -srt option to great effect for several years in order to get around the 32K data limit problem. Recently, we have broken the 64K data barrier by pushing large constant arrays into the "beyond 32K" space. The linker is now giving a warning ### Link: Warning: Size of global data area exceeds 65K. (Error 34) for every such data item! We've been ignoring these warnings, but is this really a problem? Yes, when you compile with MPW C's -m option, you can then safely ignore the message: To entirely avoid getting this error you'd have to use -model farData or -model far in place of -m in your compile. However, you would then be prohibited from using -br on in your link. For those links that you want to use -br on with,you may want to consider using a custom script that filters out these error 34 messages. Linking a driver with MPW 3.2Date Written: 5/6/92 Last reviewed: 6/14/93 When I try to link my driver in MPW 3.2, it tells me ### Link: Error : Output must go to exactly one segment when using "-rt" (Error 98) ### Link: Errors prevented normal completion. In all my source files I have #pragma segment Main {C} and SEG 'Main' {Asm} directives. Why is it doing this? What factors determine how segments are assigned (besides the #pragma stuff)? How can I get it to work?
The problem is probably that you're including modules from the libraries that
are marked for another segment. Usually the culprit here is that some of the
routines in MPW Linker error 114Date Written: 6/15/92 Last reviewed: 6/14/93 Could you tell me where I can get some explanation on the following linker error? MPW's default is to generate 16-bit references for your program. This means that your program's code segments, jump table and global data is limited 32K. In recent versions of MPW these limitations have been overcome. What you should do is compile and link your code with the "-modal far" option. MPW will now generate load-time relocatable 32-bit references. Remember to add -modal far on each compile step, and the link step in your makefile. See the MPW documentation for more information on using the -modal far option with the compilers and linker. There's no additional documentation on MPW Linker errors, other than the Q&A Technical Notes on the Developer CD Series disc. Downloadables
|
Developer Documentation | Technical Q&As | Development Kits | Sample Code |