Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Assembly (http://www.programmingforums.org/forum20.html)
-   -   sparc error help! (http://www.programmingforums.org/showthread.php?t=11692)

sackarias Oct 25th, 2006 3:58 PM

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.

FastFish Oct 25th, 2006 4:52 PM

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 Oct 25th, 2006 4:57 PM

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'.

sackarias Oct 25th, 2006 6:15 PM

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.

FastFish Oct 26th, 2006 1:49 AM

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

The Dark Oct 26th, 2006 3:06 AM

FastFish - in the first post he says he figured out the error. He used i instead of idx.


All times are GMT -5. The time now is 1:01 AM.

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