View Full Version : Incredibly newbie question about MPW
Zachary
2003.07.15, 10:58 AM
Well I've decided to make the extremely dumb move to try and learn some C, and have downloaded MPW, but when I write the "hello world" program, create a makefile and build it, it comes up with an error saying
# Reference to unresolved symbol ".fprint"
I'm pretty sure I haven't typed in the code incorrectly (considering I copied it from a tutorial :p), and I put the .c suffix at the end of the origional file name, attatched the correct source file and made it a SIOW app, but still nothing.
Anyways, in case I did copy the code wrong, here it is (wow, what a masterpeice :p)
#include <stdio.h>
main()
{
fprint ("Hello world \n");
}
Johan
2003.07.15, 11:15 AM
There is no 'fprint' function in stdio.h, use 'printf' to print to stdout or 'fprintf' if you wan't to write to a file.
.johan
Zachary
2003.07.15, 11:34 AM
oh, dang :blush:
Zachary
2003.07.15, 11:39 AM
ok, next problem, I try to build a simple addition program and I get this
File "add.c"; line 5 #Lexical error: unrecognized token
#-----------------------
int Ans;
^
File "add.c"; line 6 #Lexical error: unrecognized token
#-----------------------
Num1 = 5;
^
File "add.c"; line 8 #Lexical error: unrecognized token
#-----------------------
Num2 = 2;
^
File "add.c"; line 9 #Lexical error: unrecognized token
#-----------------------
Ans = Num1 + Num2;
^
File "add.c"; line 10 #Lexical error: unrecognized token
and this is the code:
#include <stdio.h>
main()
{
_ _ _int Num1, Num2;
_ _ _int Ans;
_ _ _Num1 = 5;
_ _ _Num2 = 2;
_ _ _Ans = Num1 + Num2;
_ _ _printf ("The answer is %d\n", Ans);
}
Steven
2003.07.15, 11:47 AM
Are those underscores actually in the code, or are they whitespace? Also, it's customary to have variables be lowercase (num1,num2,ans) instead of Num1 etc. And, if you're on OSX, I'd suggest that you use Project Builder instead of MPW. I'd suggest moving the definition of ans to the same line as num1 and num2, just to see if it fixes it. It shouldn't matter, though.
Zachary
2003.07.15, 11:52 AM
Originally posted by Steven
Are those underscores actually in the code, or are they whitespace? Also, it's customary to have variables be lowercase (num1,num2,ans) instead of Num1 etc. And, if you're on OSX, I'd suggest that you use Project Builder instead of MPW. I'd suggest moving the definition of ans to the same line as num1 and num2, just to see if it fixes it. It shouldn't matter, though.
I'm on OS9, and those underscores are white spaces. I made them all lowercase and put all the variables on the same line, but still got this
File "try1.c"; line 4 #Error: undefined identifier 'Int'
#-----------------------
Int numa, numb, ans;
^
File "try1.c"; line 4 #Warning 6: value of expression is not used
#-----------------------
Int numa, numb, ans;
^
File "try1.c"; line 4 #Warning 6: value of expression is not used
#-----------------------
ans = num1+num2;
^
File "try1.c"; line 7 #Error: undefined identifier 'num1'
#-----------------------
printf ("The answer is %d\n", ans");
^
File "try1.c"; line 8 #Lexical error: unterminated string
#-----------------------
}
^
File "try1.c"; line 9 #Lexical error: unterminated string
#-----------------------
File "try1.c"; line 10 #Lexical error: unterminated string
#-----------------------
Steven
2003.07.15, 11:53 AM
There's the problem. int may not be uppercase. (I think)
Zachary
2003.07.15, 11:57 AM
Originally posted by Steven
There's the problem. int may not be uppercase. (I think)
Well that got rid of some of the errors, but I'm still left with this:
ans = num1+num2;
^
File "try1.c"; line 7 #Error: undefined identifier 'num1'
#-----------------------
printf ("The answer is %d\n", ans");
^
File "try1.c"; line 8 #Lexical error: unterminated string
#-----------------------
}
^
File "try1.c"; line 9 #Lexical error: unterminated string
#-----------------------
File "try1.c"; line 10 #Lexical error: unterminated string
#-----------------------
Fatal error: premature end of source file
Steven
2003.07.15, 12:01 PM
Umm, yeah, that's cuz you defined them as numa and numb but then refer to them as num1 and num2... ;) Unfortunately the compiler isn't smart enough to realize that you mean the same thing :cool:
Johan
2003.07.15, 12:05 PM
You need to remove the last quotation mark.
printf ("The answer is %d\n", ans);
Also you need to define num1 before using it. Link this:int ans, num1 = 1, num2 = 2;
ans = num1 + num2;
printf("1 + 2 = %d\n", ans);
.johan
Steven
2003.07.15, 12:09 PM
Originally posted by Zachary
File "try1.c"; line 4 #Warning 6: value of expression is not used
#-----------------------
Int numa, numb, ans;
^
File "try1.c"; line 4 #Warning 6: value of expression is not used
#-----------------------
ans = num1+num2;
^
I was referring to this... he did attempt to define it before using it, just incorrectly. See the problem now? ;) But of course that quotation was also causing trouble, I missed that.
Zachary
2003.07.15, 12:49 PM
well it compiles, but when I run it it just immediately quits.
:blink: <pulls hair out>
sealfin
2003.07.15, 01:04 PM
If you're on OS9 (which you must be to be using MPW) try using Leonardo (http://www.dis.uniroma1.it/~demetres/Leonardo/) which is designed to be an IDE for learning C.
Also, I haven't used MPW for a few years, but your test may quit as it doesn't have a return value type of 'int' and a 'return 0;' statement at the end - MPW has plenty of little quirks or eccentricies ("Too many errors on one line (make fewer)"?)
TryÖ
#include <stdio.h>
int main( void )
{
int
var1 = 19,
var2 = 21,
sumOfVars;
sumOfVars = ( var1 + var2 );
printf( "The sum of the vars is %d", sumOfVars );
return 0;
}
Steven
2003.07.15, 01:48 PM
Post your entire block of code, and I'll compile it in GCC to see if it quits here too... Oh, btw, does MPW have a debugger? Try it out to see what's wrong.
sealfin
2003.07.15, 01:58 PM
I'd already compiled the code Zachary posted earlier to check whether I'd missed anything - other than warnings about "return type defauls to int" as well as "control reaches end of non-void function", it compiled and ran with no problems other than the exit status being random.)
Steven
2003.07.15, 02:03 PM
Ok, well then maybe MPW is just stupid... ;)
Is there an OS9 port of GCC? Or try out Leonardo, as suggested before by sealfin...
Patrick
2003.07.15, 02:49 PM
There is a MPW debugger, it is called the "PowerMac Debugger" and is on Apple's FTP site.
Take a look around here:
Core MacOS Tools (ftp://ftp.apple.com/developer/Tool_Chest/Core_Mac_OS_Tools)
The PM Debugger is quite good, it is better than Project Builder's actually. Plus you can use MacsBug in combination with it :p
The OS9 ports of GCC2.7 + friends as MPW tools are available somewhere at the squeak.org site (http://www.ira.uka.de/~marcus/_MPW-GCC_.html). But MrC is just as good as such an old GCC and has much better optimization, so I wouldn't see the use in getting them.
#include <stdio.h>
main( void )
{
int num1, num2, ans;
num1 = 5;
num2 = 2;
ans = num1 + num2;
printf("num1+num2 is %d\n", ans);
}
works fine for me in MPW ( you really should use int main() and return 0 though. )
Which MrC version do you have, perhaps you could try downloading MrC 5.0d3 from the FTP site. ( just run the 'mrc' command in the Worksheet to check version numbers)
RedWolf
2003.07.15, 04:19 PM
I think it might just be my machine but when I upgraded from Mac OS 8.6 to 9.0 (then 9.1), the PowerMac Debugger stopped working for me. It will startup just fine but after I try to launch my application, the system hangs. The only way I can now use the debugger is boot back to 8.6. Usually quicker for me to throw in a couple of printfs.
Patrick
2003.07.15, 04:40 PM
It worked fine in 9.2.1 for me. Guess this sort of stuff happens with unsupported software though. :???:
OneSadCookie
2003.07.15, 05:32 PM
Mac OS 9 doesn't have stdout. Does MPW automatically use SIOUX or something? Or will calls to printf just be ignored?
Patrick
2003.07.15, 05:36 PM
MacOS 9 has stdIO, they're filestreams to the files "stdin" "stdout" and "stderr", at least with Apple's C Library.
But, a SIOW project like Zachary is making creates a "Simple Input-Output Window" and redirects StdIO to that, like SIOUX/SIOUX-WASTE does.
vBulletin® v3.8.4, Copyright ©2000-2010, Jelsoft Enterprises Ltd.