![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Programmer
Join Date: Jan 2006
Posts: 58
Rep Power: 3
![]() |
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 |
|
|
|
|
|
#2 |
|
Newbie
Join Date: Oct 2006
Posts: 4
Rep Power: 0
![]() |
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 |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Oct 2006
Posts: 4
Rep Power: 0
![]() |
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'.
|
|
|
|
|
|
#4 |
|
Programmer
Join Date: Jan 2006
Posts: 58
Rep Power: 3
![]() |
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.
|
|
|
|
|
|
#5 |
|
Newbie
Join Date: Oct 2006
Posts: 4
Rep Power: 0
![]() |
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 |
|
|
|
|
|
#6 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 824
Rep Power: 4
![]() |
FastFish - in the first post he says he figured out the error. He used i instead of idx.
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|