Какой формат файла используется GCC в OSX?
-
19-09-2019 - |
Вопрос
Я пытаюсь выучить сборку, используя NASM, PCASM -book.pdf от доктора Пола Картера - http://www.drpaulcarter.com/pcasm/ - На моем Mac OS X Snow Leopard.
Я пытаюсь связать предыдущий скомпилированный образец C с образцами ASM:
gcc first.o driver.c asm_io.o -o first
Но он возвращает это:
driver.c:3: warning: ‘cdecl’ attribute ignored
ld: warning: in first.o, **file is not of required architecture**
ld: warning: in asm_io.o, file is not of required architecture
Undefined symbols:
"_asm_main", referenced from:
_main in ccjLqYJn.o
ld: symbol(s) not found
Я использую формат Mach-O для компиляции образцов ASM, и у меня нет ошибок:
nasm -f macho **first.asm**
nasm -f macho asm_io.asm
Если я попытаюсь использовать только GCC -C в Driver.c, используя LD для связи всех объектных файлов, LD, похоже, не ссылается на Format.o Format.
ld -o first asm_io.o first.o driver.o
Он возвращается:
ld: warning: in driver.o, file is not of required architecture
Undefined symbols:
"_putchar", referenced from:
print_char in asm_io.o
print_nl in asm_io.o
"_printf", referenced from:
print_int in asm_io.o
print_string in asm_io.o
push_of in asm_io.o
sub_dump_stack in asm_io.o
stack_line_loop in asm_io.o
sub_dump_mem in asm_io.o
mem_outer_loop in asm_io.o
mem_hex_loop in asm_io.o
sub_dump_math in asm_io.o
tag_loop in asm_io.o
print_real in asm_io.o
invalid_st in asm_io.o
"_scanf", referenced from:
read_int in asm_io.o
"_getchar", referenced from:
read_char in asm_io.o
ld: symbol(s) not found for inferred architecture i386
В чем проблема? Какой правильный формат для работы с GCC и NASM на OS X?
Спасибо. Даниэль Кох
Решение
The "file is not of required architecture" indicates that you're trying to link object files with different architectures: probably x86_64 and i386. As it appears your nasm output is i386, try using -arch i386
with gcc. You can also use file
to display the architecture of a given object file or library.
% touch foo.c ; gcc -c foo.c
% file foo.o
foo.o: Mach-O 64-bit object x86_64
% gcc -c -arch i386 foo.c
% file foo.o
foo.o: Mach-O object i386