Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Bloupies

macrumors newbie
Original poster
Dec 24, 2012
1
0
Good evening

I apologize beforehand, I am French. It has been several days since I look for solutions concerning NASM and mAC bone, but I find only the English forums..

I am thus on mac bone and I would like to compile a program assembler

For exemple :

Code:
%include "iut.inc" 
segment .text 
global start 

start:
	mov 	eax, msg_Accueil
	call 	write_string

	mov 	eax,msg_Nombre
	call 	write_string

	call 	read_int
	mov 	ebx,eax
	
	mov 	eax,msg_Base
	call 	write_string

	call 	read_int
	mov		ecx,eax

	call 	SousProg	;APPEL DU SOUS PROGRAMME
	mov		edx,eax
	
	mov 	eax, msgResultat
	call	write_string
		
	mov 	eax, ebx
	call	write_int
		
	mov 	eax, msgResultat1
	call	write_string
	
	mov		eax, ecx
	call	write_int
		
	mov 	eax, msgResultat2
	call	write_string

	mov		eax, edx
	call	write_int
		
	ret

SousProg:
	;EMPILEMENT DES REGISTRES UTILISES
	push	ebx
	push	ecx
	;TRAITEMENT
	

	mov 	ebx,1312
	mov 	ecx,5476
	
	mov		eax,45
	;FIN DU TRAITEMENT
	;J'AI MODIFIE LA VALEUR DE ebx ET DE ecx POUR LES BESOINS DU TRAITEMENT
	
	;RESTAURATION DES REGISTRES UTILISES
	pop		ecx
	pop		ebx
	ret
		
segment .data

msg_Accueil:	db	"Convertion d'un nombre en base b en decimal",10,0
msg_Nombre:		db	"Saissez le nombre a convertir",10,0
msg_Base:		db	"Saissez la base du nombre",10,0
msgResultat:	db	10,"le resultat de la convertion du nombre ",0
msgResultat1	db	" en base ",0
msgResultat2	db	" en decimal est ",0


In class, to I was told that to compile under Linux, it was necessary to make:

Code:
nasm –f elf exemple.asm
gcc –o exemple exemple.o –L. –lIUT -lncurses -lpanel

And have librairies : iut.int , libIUT.a

So , when i do
Code:
 nasm -v
in terminal , it's said :
Code:
NASM version 0.98.40 (Apple Computer, Inc. build 11) compiled on Aug  4 2012

So , i try to compile :

Code:
MacBook-Pro-de-Rebouh:Assembleur rebouhaymen$ nasm -f elf Ex_SousP_Pile.asm
MacBook-Pro-de-Rebouh:Assembleur rebouhaymen$ gcc -o Ex_SousP_Pile Ex_SousP_Pile.o -L. -lIUT -lncurses -lpanel
ld: warning: ld: warning: ignoring file ./libIUT.a, file was built for archive which is not the architecture being linked (x86_64): ./libIUT.aignoring file Ex_SousP_Pile.o, file was built for unsupported file format ( 0x7f 0x45 0x4c 0x46 0x 1 0x 1 0x 1 0x 0 0x 0 0x 0 0x 0 0x 0 0x 0 0x 0 0x 0 0x 0 ) which is not the architecture being linked (x86_64): Ex_SousP_Pile.o

Undefined symbols for architecture x86_64:
  "_main", referenced from:
      start in crt1.10.6.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
MacBook-Pro-de-Rebouh:Assembleur rebouhaymen$

Can you help me ? Thanxs you so much ..
 

ytk

macrumors 6502
Jul 8, 2010
252
5
Well, for starters, I have no idea what the contents of iut.inc or libIUT.a are, but it looks at least libIUT.a doesn't contain what you think it does. The magic number (0x7F 45 4C 46) reported is for an ELF executable, not an archive library (which should be 0xCAFEBABE for a universal file, or something like 0x21 3C 61 72 63 68 3E 0A for a single architecture file). To confirm, try running "file libIUT.a" and see what it reports. It should say "current ar archive random library".
 

ytk

macrumors 6502
Jul 8, 2010
252
5
That's Mach-O, not macho. :) But a .a file shouldn't contain a binary executable anyway, regardless of the format. Since it's reporting that it's an ELF executable, you have a problem. It sounds like this libIUT.a file may have been compiled (incorrectly) on a Linux system?
 

subsonix

macrumors 68040
Feb 2, 2008
3,551
79
The correct output format flag for OS X in NASM is indeed macho. Apart from that, is the archive perhaps built on Linux? In that case you have to re-compile it for OS X.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.