Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 25th, 2006, 2:58 PM   #1
sackarias
Programmer
 
sackarias's Avatar
 
Join Date: Jan 2006
Posts: 58
Rep Power: 3 sackarias is on a distinguished road
sparc error help!

I'm getting this error which I personally don't get much help from...

Undefined first referenced
symbol in file
i /var/tmp//ccchb2QW.o
ld: fatal: Symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status

My code is...

/*********************************************
File: arrays.m
Date: October 31st, 2006
Author: Zack Hitz
Purpose: Asks the user to enter 10 integers
into 2 arrays.  The arrays will be added up
via their corresponding index, stored into 
a third array, then all 3 arrays will be
outputted.
*********************************************/
	.align 8
	.data
input:	.asciz	"%d"
	.align 8
output: .asciz 	"%d"
	.align 8
prompt: .asciz 	"Enter 10 integers\n"

!Automatic data for a program
define(idx, -20)
define(A, -60)
define(B, -100)
define(C, -140)

	.text
	.align 4
	.global main
main: save %sp,(-108 - 12) & -8, %sp

mov 0, %l0
st %l0, [%fp+idx]

set prompt, %o0
call printf
nop

inputLoop:

	set input, %o0
	add %fp, A, %o2
	ld [%fp+idx],%o1
	sll %o1, 2, %o1
	add %o2, %o1, %o1
	call scanf, 0
	nop

	ld [%fp+idx], %l0
	inc %l0
	st %l0, [%fp+idx] !was originally %fp+i
	cmp %l0, 10
	bl inputLoop
	nop

inputDone: call exit, 0
	mov 0, %o0

Any ideas?

*EDIT*
The boldfaced text is where the error was. I didn't have an "i" allocated anywhere so it freaked out, I meant idx.

Last edited by sackarias; Oct 25th, 2006 at 3:23 PM. Reason: Figured out error
sackarias is offline   Reply With Quote
Old Oct 25th, 2006, 3:52 PM   #2
FastFish
Newbie
 
Join Date: Oct 2006
Posts: 4
Rep Power: 0 FastFish is on a distinguished road
Need to link against standard library

Dude,

You're using printf in your code but your not linking with the library where printf is defined.

I don't know how your compiler and linker are set up but you need to adjust the settings to include this library.

If you're on a Unix box then 'man printf' should provide some clues - look for something like '-lstdio' (stdio is the name of the library) and add this to the command that you're using for linking.

-- FF
FastFish is offline   Reply With Quote
Old Oct 25th, 2006, 3:57 PM   #3
FastFish
Newbie
 
Join Date: Oct 2006
Posts: 4
Rep Power: 0 FastFish is on a distinguished road
P.S. Re. the Unix man page, you may need to specify the manual section because there is a shell command called printf and you want to make sure you get the library routine printf(). On my Linux box I do 'man 3 printf' to get the right page, since you're programming a sparc chip you might be using Solaris and I think the correct man command is something like 'man -s 3 printf'.
FastFish is offline   Reply With Quote
Old Oct 25th, 2006, 5:15 PM   #4
sackarias
Programmer
 
sackarias's Avatar
 
Join Date: Jan 2006
Posts: 58
Rep Power: 3 sackarias is on a distinguished road
I'm not sure, I'm new to assembly, just started the class about a month ago. When I define an output of some sort (such as prompt in my code), if I set the prompt into the o0 ("oh zero")register, then call printf, it takes whatever the prompt is in o0 and outputs it. Same with an input, I can set it to the o0 register and depending upon what and how many things I'm reading in, I use the o1-o5 registers. I'm not sure exactly what you're saying, I wish I could understand. I hope this reply clarifys in some way what I'm doing and why I'm doing it.
sackarias is offline   Reply With Quote
Old Oct 26th, 2006, 12:49 AM   #5
FastFish
Newbie
 
Join Date: Oct 2006
Posts: 4
Rep Power: 0 FastFish is on a distinguished road
From your last post it sounds like you have used printf before without needing to adjust the compiler/linker settings. But the error message is definitely coming from the linker, it is unable to find something you're using in your code in the external libraries.

Is it possible that you have spelled something incorrectly and the reason that the linker is complaining is because it cannot find the incorrectly-spelled thing in the external library?

I'm afraid I can only suggest going through your code with a fine-toothed comb and check everything. Another useful technique is to make a copy of your program and try to reduce it to the smallest number of lines that still cause the error. This can sometimes help figure out what is causing the error.

Are any of your classmates having the same problem?

-- FF
FastFish is offline   Reply With Quote
Old Oct 26th, 2006, 2:06 AM   #6
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 810
Rep Power: 4 The Dark is on a distinguished road
FastFish - in the first post he says he figured out the error. He used i instead of idx.
The Dark is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 1:42 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC