BLARGH! Won't compile!

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
mrdelayer
Posts: 16
Joined: Sun Jul 10, 2005 4:30 pm

BLARGH! Won't compile!

Post by mrdelayer »

so i wrote a little psp pi calculation program based on one of the ones found at projectpi (http://projectpi.sourceforge.net) and some of pspkrazy's logging code... when i go to make it, it does this:

Code: Select all

Matt@steamloller /usr/local/pspdev/psp/sdk/samples/pi
$ psp-gcc -I. -I/usr/local/pspdev/psp/sdk/include -O2 -G0 -Wall -L. -L/usr/local/pspdev/psp/sdk/lib main.o -lpspdebug -lpsplibc -lpspkernel -lm -o pi.elf
/usr/local/pspdev/lib/gcc/psp/4.0.0/../../../../psp/lib/crt0.o: In function `__e
ntrytable':
crt0.S:(.rodata.sceResident+0xc): undefined reference to `module_info'
/usr/local/pspdev/lib/gcc/psp/4.0.0/../../../../psp/lib/libm.a(w_sqrt.o): In function `sqrt':
../../../../../newlib/libm/math/w_sqrt.c:83: undefined reference to `__errno'
../../../../../newlib/libm/math/w_sqrt.c:86: undefined reference to `__errno'
collect2: ld returned 1 exit status
here is the code to my program:

Code: Select all

#include <pspkernel.h>
#include <pspdebug.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdarg.h>
#include <math.h>

#define O_RDONLY    0x0001
#define O_WRONLY    0x0002
#define O_RDWR      0x0003
#define O_NBLOCK    0x0010
#define O_APPEND    0x0100
#define O_CREAT     0x0200
#define O_TRUNC     0x0400
#define O_NOWAIT    0x8000 

int file = 0;

int LogOpen&#40;char *path&#41; &#123;
	file = sceIoOpen&#40;path, PSP_O_CREAT|PSP_O_RDWR|PSP_O_TRUNC, 0777&#41;;
	return file;
&#125;

int LogClose&#40;&#41; &#123;
	if&#40;file&#41;
		sceIoClose&#40;file&#41;;
	return 0;
&#125;

int LogPrintf&#40;char *fmt, ...&#41; &#123;
	va_list opt;
  
	char buff&#91;2048&#93;;
	int bufsz;
  
	va_start&#40;opt, fmt&#41;;
	bufsz = vsnprintf&#40; buff, &#40;size_t&#41; sizeof&#40;buff&#41;, fmt, opt&#41;;
	sceIoWrite&#40;file, buff, bufsz&#41;;

	return 0;
&#125;

double find&#40;double x,double a&#41; &#123;
	double y;
	y=sqrt&#40;&#40;a*a&#41;-&#40;x*x&#41;&#41;;
	return y;
&#125;;

int main&#40;&#41; &#123;
	file = LogOpen&#40;"ms0&#58;/pi.txt"&#41;;
	double ind,delta,rad,dec,sum=0.0,x,y,xnow,ynow,length;
	rad = 300;
	printf&#40;"Radius = 300\n"&#41;;
	LogPrintf&#40;"Radius = 300\n"&#41;;
	dec = 0.1;
	printf&#40;"Decrease in x = 0.1\n"&#41;;
	LogPrintf&#40;"Decrease in x = 0.1\n"&#41;;
	x=rad;
	y=0.0;
	delta=rad/100.0;
	ind=1.0;
	for&#40;xnow=rad;xnow>=0.0;xnow=xnow-dec&#41; &#123;
		ynow=find&#40;xnow,rad&#41;;
		length=sqrt&#40;&#40;&#40;x-xnow&#41;*&#40;x-xnow&#41;&#41;+&#40;&#40;ynow-y&#41;*&#40;ynow-y&#41;&#41;&#41;;
		sum=sum+length;
		x=xnow;
		y=ynow;
		if&#40;xnow<=rad-&#40;ind*delta&#41;&#41; &#123;
			printf&#40;"\n%.0lf of 100 completed.",ind&#41;;
			LogPrintf&#40;"\n%.0lf of 100 completed.",ind&#41;;
			ind=ind+1.0;
		&#125;;
	&#125;;
	LogPrintf&#40;"Pi=%.10lf",2.0*sum/rad&#41;;
	LogClose&#40;&#41;;
	printf&#40;"\nPi=%.10lf",2.0*sum/rad&#41;;
	sceKernelExitGame&#40;&#41;;
	return&#40;0&#41;;
&#125;;
it's probably something really minor that i overlooked because it's 2:30 in the morning :| any ideas, though?
deagle
Posts: 8
Joined: Wed Jun 29, 2005 5:12 am

Post by deagle »

crt0.S:(.rodata.sceResident+0xc): undefined reference to `module_info'
I think you've forgotten to add the PSP_MODULE_INFO line in the code
example :
PSP_MODULE_INFO("Name of your program", 0, 1, 1);
right after the headers includes
mrdelayer
Posts: 16
Joined: Sun Jul 10, 2005 4:30 pm

Post by mrdelayer »

well, that fixed the module_info thing... no luck with the __errno errors though :|
squiggle
Posts: 9
Joined: Sun Jun 26, 2005 8:33 pm

Post by squiggle »

worked for me when I tried to build it with the latest pspsdk out of svn. So it looks like the bugs been fixed.

Radius = 300
Decrease in x = 0.1

1 of 100 completed.
2 of 100 completed.
3 of 100 completed.
4 of 100 completed.
5 of 100 completed.
6 of 100 completed.
7 of 100 completed.
8 of 100 completed.
9 of 100 completed.
10 of 100 completed.
11 of 100 completed.
12 of 100 completed.
13 of 100 completed.
14 of 100 completed.
15 of 100 completed.
16 of 100 completed.
17 of 100 completed.
18 of 100 completed.
19 of 100 completed.
20 of 100 completed.
21 of 100 completed.
22 of 100 completed.
23 of 100 completed.
24 of 100 completed.
25 of 100 completed.
26 of 100 completed.
27 of 100 completed.
28 of 100 completed.
29 of 100 completed.
30 of 100 completed.
31 of 100 completed.
32 of 100 completed.
33 of 100 completed.
34 of 100 completed.
35 of 100 completed.
36 of 100 completed.
37 of 100 completed.
38 of 100 completed.
39 of 100 completed.
40 of 100 completed.
41 of 100 completed.
42 of 100 completed.
43 of 100 completed.
44 of 100 completed.
45 of 100 completed.
46 of 100 completed.
47 of 100 completed.
48 of 100 completed.
49 of 100 completed.
50 of 100 completed.
51 of 100 completed.
52 of 100 completed.
53 of 100 completed.
54 of 100 completed.
55 of 100 completed.
56 of 100 completed.
57 of 100 completed.
58 of 100 completed.
59 of 100 completed.
60 of 100 completed.
61 of 100 completed.
62 of 100 completed.
63 of 100 completed.
64 of 100 completed.
65 of 100 completed.
66 of 100 completed.
67 of 100 completed.
68 of 100 completed.
69 of 100 completed.
70 of 100 completed.
71 of 100 completed.
72 of 100 completed.
73 of 100 completed.
74 of 100 completed.
75 of 100 completed.
76 of 100 completed.
77 of 100 completed.
78 of 100 completed.
79 of 100 completed.
80 of 100 completed.
81 of 100 completed.
82 of 100 completed.
83 of 100 completed.
84 of 100 completed.
85 of 100 completed.
86 of 100 completed.
87 of 100 completed.
88 of 100 completed.
89 of 100 completed.
90 of 100 completed.
91 of 100 completed.
92 of 100 completed.
93 of 100 completed.
94 of 100 completed.
95 of 100 completed.
96 of 100 completed.
97 of 100 completed.
98 of 100 completed.
99 of 100 completed.Pi=3.1415908644
mrdelayer
Posts: 16
Joined: Sun Jul 10, 2005 4:30 pm

Post by mrdelayer »

whoo! i'll grab the latest pspsdk from svn sometime today. that pi is horrible inaccurate though :D i'll mess with the numbers later too...
User avatar
Jim
Posts: 476
Joined: Sat Jul 02, 2005 10:06 pm
Location: Sydney
Contact:

Post by Jim »

Until the sdk is fixed for __errno just add

Code: Select all

int __errno = 0;
to your main C file.

Jim
mrbrown
Site Admin
Posts: 1537
Joined: Sat Jan 17, 2004 11:24 am

Post by mrbrown »

It's been fixed in Subversion for quite some time.
mrdelayer
Posts: 16
Joined: Sun Jul 10, 2005 4:30 pm

Post by mrdelayer »

blargh. grabbed it out of subversion, and now...

Code: Select all

Matt@steamloller /usr/local/pspdev/psp/sdk/samples/pi
$ make
psp-gcc -I. -I/usr/local/pspdev/psp/sdk/include -O2 -G0 -Wall  -L. -L/usr/local/
pspdev/psp/sdk/lib   main.o  -lpspdebug -lpspdisplay -lpspge -lpspctrl -lc -lpsp
glue -lpspuser -lpspkernel -o kptest.elf
main.o&#58; In function `find'&#58;
main.c&#58;&#40;.text+0x150&#41;&#58; undefined reference to `sqrt'
main.o&#58; In function `main'&#58;
main.c&#58;&#40;.text+0x2e8&#41;&#58; undefined reference to `sqrt'
/usr/local/pspdev/lib/gcc/psp/4.0.0/../../../../psp/lib/libc.a&#40;sbrkr.o&#41;&#58; In func
tion `_sbrk_r'&#58;
../../../../../newlib/libc/reent/sbrkr.c&#58;60&#58; undefined reference to `sbrk'
/usr/local/pspdev/lib/gcc/psp/4.0.0/../../../../psp/lib/libc.a&#40;writer.o&#41;&#58; In fun
ction `_write_r'&#58;
../../../../../newlib/libc/reent/writer.c&#58;58&#58; undefined reference to `write'
/usr/local/pspdev/lib/gcc/psp/4.0.0/../../../../psp/lib/libc.a&#40;closer.o&#41;&#58; In fun
ction `_close_r'&#58;
../../../../../newlib/libc/reent/closer.c&#58;53&#58; undefined reference to `close'
/usr/local/pspdev/lib/gcc/psp/4.0.0/../../../../psp/lib/libc.a&#40;fstatr.o&#41;&#58; In fun
ction `_fstat_r'&#58;
../../../../../newlib/libc/reent/fstatr.c&#58;62&#58; undefined reference to `fstat'
/usr/local/pspdev/lib/gcc/psp/4.0.0/../../../../psp/lib/libc.a&#40;lseekr.o&#41;&#58; In fun
ction `_lseek_r'&#58;
../../../../../newlib/libc/reent/lseekr.c&#58;58&#58; undefined reference to `lseek'
/usr/local/pspdev/lib/gcc/psp/4.0.0/../../../../psp/lib/libc.a&#40;readr.o&#41;&#58; In func
tion `_read_r'&#58;
../../../../../newlib/libc/reent/readr.c&#58;58&#58; undefined reference to `read'
collect2&#58; ld returned 1 exit status
make&#58; *** &#91;kptest.elf&#93; Error 1
User avatar
Agoln
Posts: 326
Joined: Wed Jun 08, 2005 3:14 am
Location: Fort Wayne, IN

Post by Agoln »

mrdelayer wrote:

Code: Select all

main.o&#58; In function `find'&#58;
main.c&#58;&#40;.text+0x150&#41;&#58; undefined reference to `sqrt'
main.o&#58; In function `main'&#58;
main.c&#58;&#40;.text+0x2e8&#41;&#58; undefined reference to `sqrt'
I'm not sure but I think you have to link the math library in to use sqrt... -lm
Lego of my Ago!
mrdelayer
Posts: 16
Joined: Sun Jul 10, 2005 4:30 pm

Post by mrdelayer »

that fixes that.. but not all the other stuff :|
mrbrown
Site Admin
Posts: 1537
Joined: Sat Jan 17, 2004 11:24 am

Post by mrbrown »

When in doubt about undefined references, grab the latest psptoolchain from ooPo's site. We don't usually leave the tree broken for long, so chances are your SDK or tools are out of date if you get any errors.
Post Reply