2 Replies - 1130 Views - Last Post: 25 January 2013 - 02:44 PM

#1 c3phalex1n  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 25-January 13

i have a problem when used c function in my program

Posted 25 January 2013 - 02:12 PM

Hi everyone...!
Friends, i have a probelm in programing with GNU assembller...!
When i want linked my program!
following code!
.section .data 
output: .asciz “The value is: %d\n”
.section .text
.globl _start 
_start: 
nop
movl $100, %ecx 
movl $0, %eax 
loop1: 
addl %ecx, %eax 
loop loop1 
pushl %eax 
pushl $output 
call printf 
add $8, %esp 
movl $1, %eax 
movl $0, %ebx 
int $0x80


linker displayed this error for me.
undifined refrence to "printf"

with command i linked this code ....
ld -dynamic-linker /lib/ld-linux.so.2 mycode.o -o mycode

but showing error in the output..
how i can fix this problem?!

sorry for bad english speaking!

Is This A Good Question/Topic? 0
  • +

Replies To: i have a problem when used c function in my program

#2 NathanMullenax  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 86
  • View blog
  • Posts: 189
  • Joined: 23-September 12

Re: i have a problem when used c function in my program

Posted 25 January 2013 - 02:22 PM

If you use gcc as a front end instead of invoking gas directly, libc will be automatically linked.

.section .data 
output: .asciz "The value is: %d\n"
.section .text
.globl main 
main: 
nop
movl $100, %ecx 
movl $0, %eax 
loop1: 
addl %ecx, %eax 
loop loop1 
pushl %eax 
pushl $output 
call printf 
add $8, %esp 
movl $1, %eax 
movl $0, %ebx 
int $0x80


Assembled fine on my machine with:

gcc ./hello.S -ohello

If you're using gas directly, you'll have to link libc:

http://stackoverflow...thout-using-gcc

This post has been edited by NathanMullenax: 25 January 2013 - 02:24 PM

Was This Post Helpful? 2
  • +
  • -

#3 c3phalex1n  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 25-January 13

Re: i have a problem when used c function in my program

Posted 25 January 2013 - 02:44 PM

Thanks my friend for replay...
My problem fixed with your help..
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1