A menos que haja alguma entidade divina envolvida, você não poderá compilar um arquivo vazio. É como pedir a um padeiro que faça pão do nada.
Um c "hello world" é compilado? Ou seja:
#include <stdio.h>
int main (void)
{
printf ("Hello ya!\n");
return 0;
}
Tente também compilar com a opção -v
.
EDIT: Novos dados de 64 bits:
Ou seja: minha saída no código acima em uma máquina de 64 bits 32bit produz:
$ gcc -Wall -Wextra -pedantic -v -o hello hello.c
Using built-in specs.
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 4.4.5-8' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.4 --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --with-arch-32=i586 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.4.5 (Debian 4.4.5-8)
COLLECT_GCC_OPTIONS='-Wall' '-Wextra' '-pedantic' '-v' '-o' 'hello' '-mtune=generic'
/usr/lib/gcc/x86_64-linux-gnu/4.4.5/cc1 -quiet -v hello.c -quiet -dumpbase hello.c -mtune=generic -auxbase hello -Wall -Wextra -pedantic -version -o /tmp/cclZGw1d.s
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/4.4.5/../../../../x86_64-linux-gnu/include"
ignoring nonexistent directory "/usr/include/x86_64-linux-gnu"
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/usr/lib/gcc/x86_64-linux-gnu/4.4.5/include
/usr/lib/gcc/x86_64-linux-gnu/4.4.5/include-fixed
/usr/include
End of search list.
GNU C (Debian 4.4.5-8) version 4.4.5 (x86_64-linux-gnu)
compiled by GNU C version 4.4.5, GMP version 4.3.2, MPFR version 3.0.0-p3.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: dac4d891d068d1bed01868869b00bd17
COLLECT_GCC_OPTIONS='-Wall' '-Wextra' '-pedantic' '-v' '-o' 'hello' '-mtune=generic'
as -V -Qy -o /tmp/ccx0akTi.o /tmp/cclZGw1d.s
GNU assembler version 2.20.1 (x86_64-linux-gnu) using BFD version (GNU Binutils for Debian) 2.20.1-system.20100303
COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/4.4.5/:/usr/lib/gcc/x86_64-linux-gnu/4.4.5/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.4.5/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.4.5/:/usr/lib/gcc/x86_64-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/4.4.5/:/usr/lib/gcc/x86_64-linux-gnu/4.4.5/:/usr/lib/gcc/x86_64-linux-gnu/4.4.5/../../../../lib/:/lib/../lib/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/4.4.5/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-Wall' '-Wextra' '-pedantic' '-v' '-o' 'hello' '-mtune=generic'
/usr/lib/gcc/x86_64-linux-gnu/4.4.5/collect2 --build-id --eh-frame-hdr -m elf_x86_64 --hash-style=both -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o hello /usr/lib/gcc/x86_64-linux-gnu/4.4.5/../../../../lib/crt1.o /usr/lib/gcc/x86_64-linux-gnu/4.4.5/../../../../lib/crti.o /usr/lib/gcc/x86_64-linux-gnu/4.4.5/crtbegin.o -L/usr/lib/gcc/x86_64-linux-gnu/4.4.5 -L/usr/lib/gcc/x86_64-linux-gnu/4.4.5 -L/usr/lib/gcc/x86_64-linux-gnu/4.4.5/../../../../lib -L/lib/../lib -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/4.4.5/../../.. /tmp/ccx0akTi.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/x86_64-linux-gnu/4.4.5/crtend.o /usr/lib/gcc/x86_64-linux-gnu/4.4.5/../../../../lib/crtn.o
Passo a passo
Para um passo a passo (e abordagem mais limpa) faça - (Isto é o que o gcc faz): Comando "Clean" entre parênteses, quando necessário.
Etapa 1 - expanda macros:
$ cpp hello.c > hello.i
# This gives source code with all macros expanded.
Use -save-temps
para geração automática. Deve dar .ii
para c ++.
Passo 2 - Crie o código assembly em hello.s (gcc -S hello.i):
$ gcc -Wall -Wextra -pedantic -S -v hello.i
Using built-in specs.
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 4.4.5-8' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.4 --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --with-arch-32=i586 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.4.5 (Debian 4.4.5-8)
COLLECT_GCC_OPTIONS='-Wall' '-Wextra' '-pedantic' '-S' '-v' '-mtune=generic'
/usr/lib/gcc/x86_64-linux-gnu/4.4.5/cc1 -fpreprocessed hello.i -quiet -dumpbase hello.i -mtune=generic -auxbase hello -Wall -Wextra -pedantic -version -o hello.s
GNU C (Debian 4.4.5-8) version 4.4.5 (x86_64-linux-gnu)
compiled by GNU C version 4.4.5, GMP version 4.3.2, MPFR version 3.0.0-p3.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: dac4d891d068d1bed01868869b00bd17
COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/4.4.5/:/usr/lib/gcc/x86_64-linux-gnu/4.4.5/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.4.5/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.4.5/:/usr/lib/gcc/x86_64-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/4.4.5/:/usr/lib/gcc/x86_64-linux-gnu/4.4.5/:/usr/lib/gcc/x86_64-linux-gnu/4.4.5/../../../../lib/:/lib/../lib/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/4.4.5/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-Wall' '-Wextra' '-pedantic' '-S' '-v' '-mtune=generic'
Etapa 3 - Converter o assembly em código de máquina. (como hello.s -o hello.o)
Veja "man as" para muitas opções.
$ as hello.s -ag -al -o hello.o
GAS LISTING hello.s page 1
GNU assembler version 2.20.1 (x86_64-linux-gnu)
using BFD version (GNU Binutils for Debian) 2.20.1-system.20100303.
options passed : -ag -al
input file : hello.s
output file : hello.o
target : x86_64-pc-linux-gnu
time stamp : 2012-12-09T00:25:03.000+0100
GAS LISTING hello.s page 2
1 .file "hello.c"
2 .section .rodata
3 .LC0:
4 0000 48656C6C .string "Hello ya!"
4 6F207961
4 2100
5 .text
6 .globl main
7 .type main, @function
8 main:
9 .LFB0:
10 .cfi_startproc
11 0000 55 pushq %rbp
12 .cfi_def_cfa_offset 16
13 0001 4889E5 movq %rsp, %rbp
14 .cfi_offset 6, -16
15 .cfi_def_cfa_register 6
16 0004 B8000000 movl $.LC0, %eax
16 00
17 0009 4889C7 movq %rax, %rdi
18 000c B8000000 movl $0, %eax
18 00
19 0011 E8000000 call printf
19 00
20 0016 B8000000 movl $0, %eax
20 00
21 001b C9 leave
22 001c C3 ret
23 .cfi_endproc
24 .LFE0:
25 .size main, .-main
26 .ident "GCC: (Debian 4.4.5-8) 4.4.5"
27 .section .note.GNU-stack,"",@progbits
Etapa 4 - vinculação:
# Highly dependable on arch and libs and etc.
# For me it is:
$ ld -dynamic-linker /lib64/ld-linux-x86-64.so.2 /usr/lib/crt1.o /usr/lib/crti.o /usr/lib/gcc/x86_64-linux-gnu/4.4.5/crtbegin.o -L/usr/lib/gcc/x86_64-linux-gnu/4.4.5 hello.o -lgcc_eh -lc -lgcc -lgcc_eh /usr/lib/gcc/x86_64-linux-gnu/4.4.5/crtend.o /usr/lib/crtn.o
# Shorter option:
$ gcc hello.o
# Using -v option you should get some more information.
Etapa 5 - executar:
$ ./a.out
Hello ya!
# Optionally run $ strace ./a.out
Em qual etapa ele falha?
Como nota, minha saída de as -V --target-help
$ as -V --target-help
GNU assembler version 2.20.1 (x86_64-linux-gnu) using BFD version
(GNU Binutils for Debian) 2.20.1-system.20100303
-Q ignored
-V print assembler version number
-k ignored
-n Do not optimize code alignment
-q quieten some warnings
-s ignored
--32/--64 generate 32bit/64bit code
--divide ignored
-march=CPU[,+EXTENSION...]
generate code for CPU and EXTENSION, CPU is one of:
i8086, i186, i286, i386, i486, pentium, pentiumpro,
pentiumii, pentiumiii, pentium4, prescott, nocona,
core, core2, corei7, l1om, k6, k6_2, athlon, k8,
amdfam10, generic32, generic64
EXTENSION is combination of:
8087, 287, 387, no87, mmx, nommx, sse, sse2, sse3,
ssse3, sse4.1, sse4.2, sse4, nosse, avx, noavx,
vmx, smx, xsave, movbe, ept, aes, pclmul, fma,
clflush, syscall, rdtscp, 3dnow, 3dnowa, sse4a,
svme, abm, padlock, fma4
-mtune=CPU optimize for CPU, CPU is one of:
i8086, i186, i286, i386, i486, pentium, pentiumpro,
pentiumii, pentiumiii, pentium4, prescott, nocona,
core, core2, corei7, l1om, k6, k6_2, athlon, k8,
amdfam10, generic32, generic64
-msse2avx encode SSE instructions with VEX prefix
-msse-check=[none|error|warning]
check SSE instructions
-mmnemonic=[att|intel] use AT&T/Intel mnemonic
-msyntax=[att|intel] use AT&T/Intel syntax
-mindex-reg support pseudo index registers
-mnaked-reg don't require '%' prefix for registers
-mold-gcc support old (<= 2.8.1) versions of gcc