x64 데비안에서는 gcc를 사용할 수 없습니다:
$ gcc a.cpp
Assembler messages:
Fatal error: No compiled in support for x86_64
어떻게 해야 합니까? 어떤 사람들은 binutils 설치를 제안하지만 이미 설치되어 있습니다.
(-m64를 추가해도 아무 것도 변경되지 않습니다). 이 소식은 어디에서 왔습니까?
a.cpp는 단지 빈 파일입니다.
--help=대상 지정됨
The following options are target specific:
-m128bit-long-double sizeof(long double) is 16
-m32 Generate 32bit i386 code
-m3dnow Support 3DNow! built-in functions
-m3dnowa Support Athlon 3Dnow! built-in functions
-m64 Generate 64bit x86-64 code
-m80387 Use hardware fp
-m8bit-idiv Expand 32bit/64bit integer divide into 8bit
unsigned integer divide with run-time check
-m96bit-long-double sizeof(long double) is 12
-mabi= Generate code that conforms to the given ABI
-mabm Support code generation of Advanced Bit
Manipulation (ABM) instructions.
-maccumulate-outgoing-args Reserve space for outgoing arguments in the
function prologue
-maes Support AES built-in functions and code generation
-malign-double Align some doubles on dword boundary
-malign-functions= Function starts are aligned to this power of 2
-malign-jumps= Jump targets are aligned to this power of 2
-malign-loops= Loop code aligned to this power of 2
-malign-stringops Align destination of the string operations
-mandroid Generate code for the Android platform.
-march= Generate code for given CPU
-masm= Use given assembler dialect
-mavx Support MMX, SSE, SSE2, SSE3, SSSE3, SSE4.1,
SSE4.2 and AVX built-in functions and code
generation
-mavx2 Support MMX, SSE, SSE2, SSE3, SSSE3, SSE4.1,
SSE4.2, AVX and AVX2 built-in functions and code
generation
-mavx256-split-unaligned-load Split 32-byte AVX unaligned load
-mavx256-split-unaligned-store Split 32-byte AVX unaligned store
-mbionic Use Bionic C library
-mbmi Support BMI built-in functions and code generation
-mbmi2 Support BMI2 built-in functions and code
generation
-mbranch-cost= Branches are this expensive (1-5, arbitrary units)
-mcld Generate cld instruction in the function prologue.
-mcmodel= Use given x86-64 code model
-mcpu= This switch lacks documentation
-mcrc32 Support code generation of crc32 instruction.
-mcx16 Support code generation of cmpxchg16b instruction.
-mdispatch-scheduler Do dispatch scheduling if processor is bdver1 or
bdver2 and Haifa scheduling is selected.
-mf16c Support F16C built-in functions and code
generation
-mfancy-math-387 Generate sin, cos, sqrt for FPU
-mfentry Emit profiling counter call at function entry
before prologue.
-mfma Support MMX, SSE, SSE2, SSE3, SSSE3, SSE4.1,
SSE4.2, AVX and FMA built-in functions and code
generation
-mfma4 Support FMA4 built-in functions and code
generation
-mforce-drap Always use Dynamic Realigned Argument Pointer
(DRAP) to realign stack
-mfp-ret-in-387 Return values of functions in FPU registers
-mfpmath= Generate floating point mathematics using given
instruction set
-mfsgsbase Support FSGSBASE built-in functions and code
generation
-mfused-madd This switch lacks documentation
-mglibc Use GNU C library
-mhard-float Use hardware fp
-mieee-fp Use IEEE math for fp comparisons
-mincoming-stack-boundary= Assume incoming stack aligned to this power of 2
-minline-all-stringops Inline all known string operations
-minline-stringops-dynamically Inline memset/memcpy string operations, but
perform inline version only for small blocks
-mintel-syntax This switch lacks documentation
-mlarge-data-threshold= Data greater than given threshold will go into
.ldata section in x86-64 medium model
-mlwp Support LWP built-in functions and code
generation
-mlzcnt Support LZCNT built-in function and code
generation
-mmmx Support MMX built-in functions
-mmovbe Support code generation of movbe instruction.
-mms-bitfields Use native (MS) bitfield layout
-mno-align-stringops This switch lacks documentation
-mno-fancy-math-387 This switch lacks documentation
-mno-push-args This switch lacks documentation
-mno-red-zone This switch lacks documentation
-mno-sse4 Do not support SSE4.1 and SSE4.2 built-in
functions and code generation
-momit-leaf-frame-pointer Omit the frame pointer in leaf functions
-mpc32 Set 80387 floating-point precision to 32-bit
-mpc64 Set 80387 floating-point precision to 64-bit
-mpc80 Set 80387 floating-point precision to 80-bit
-mpclmul Support PCLMUL built-in functions and code
generation
-mpopcnt Support code generation of popcnt instruction.
-mprefer-avx128 Use 128-bit AVX instructions instead of 256-bit
AVX instructions in the auto-vectorizer.
-mpreferred-stack-boundary= Attempt to keep stack aligned to this power of 2
-mpush-args Use push instructions to save outgoing arguments
-mrdrnd Support RDRND built-in functions and code
generation
-mrecip Generate reciprocals instead of divss and sqrtss.
-mrecip= Control generation of reciprocal estimates.
-mred-zone Use red-zone in the x86-64 code
-mregparm= Number of registers used to pass integer arguments
-mrtd Alternate calling convention
-msahf Support code generation of sahf instruction in
64bit x86-64 code.
-msoft-float Do not use hardware fp
-msse Support MMX and SSE built-in functions and code
generation
-msse2 Support MMX, SSE and SSE2 built-in functions and
code generation
-msse2avx Encode SSE instructions with VEX prefix
-msse3 Support MMX, SSE, SSE2 and SSE3 built-in
functions and code generation
-msse4 Support MMX, SSE, SSE2, SSE3, SSSE3, SSE4.1 and
SSE4.2 built-in functions and code generation
-msse4.1 Support MMX, SSE, SSE2, SSE3, SSSE3 and SSE4.1
built-in functions and code generation
-msse4.2 Support MMX, SSE, SSE2, SSE3, SSSE3, SSE4.1 and
SSE4.2 built-in functions and code generation
-msse4a Support MMX, SSE, SSE2, SSE3 and SSE4A built-in
functions and code generation
-msse5 This switch lacks documentation
-msseregparm Use SSE register passing conventions for SF and
DF mode
-mssse3 Support MMX, SSE, SSE2, SSE3 and SSSE3 built-in
functions and code generation
-mstack-arg-probe Enable stack probing
-mstackrealign Realign stack in prologue
-mstringop-strategy= Chose strategy to generate stringop using
-mtbm Support TBM built-in functions and code generation
-mtls-dialect= Use given thread-local storage dialect
-mtls-direct-seg-refs Use direct references against %gs when accessing
tls data
-mtune= Schedule code for given CPU
-muclibc Use uClibc C library
-mveclibabi= Vector library ABI to use
-mvect8-ret-in-mem Return 8-byte vectors in memory
-mvzeroupper Generate vzeroupper instruction before a transfer
of control flow out of the function.
-mx32 Generate 32bit x86-64 code
-mxop Support XOP built-in functions and code
generation
Known assembler dialects (for use with the -masm-dialect= option):
att intel
Known ABIs (for use with the -mabi= option):
ms sysv
Known code models (for use with the -mcmodel= option):
32 kernel large medium small
Valid arguments to -mfpmath=:
387 387+sse 387,sse both sse sse+387 sse,387
Known vectorization library ABIs (for use with the -mveclibabi= option):
acml svml
Valid arguments to -mstringop-strategy=:
byte_loop libcall loop rep_4byte rep_8byte rep_byte unrolled_loop
Known TLS dialects (for use with the -mtls-dialect= option):
gnu gnu2
답변1
신성한 실체가 포함되지 않는 한 빈 파일을 컴파일할 수 없습니다. 그것은 제빵사에게 허공에서 빵을 만들어 달라고 요청하는 것과 같습니다.
ac "hello world"를 컴파일할 수 있나요? 즉:
#include <stdio.h>
int main (void)
{
printf ("Hello ya!\n");
return 0;
}
-v
옵션으로 컴파일 도 시도했습니다 .
편집: 64비트의 새 데이터:
즉, 32비트 및 64비트 시스템 에서 위 코드의 출력은 다음과 같습니다.
$ 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
단계별로
단계별로(더 깔끔한 방법으로) 수행하십시오 - (이것이 gcc가 수행하는 작업입니다): 필요할 때 대괄호 안에 "Clean" 명령을 추가하십시오.
1단계 - 매크로 확장:
$ cpp hello.c > hello.i
# This gives source code with all macros expanded.
-save-temps
자동 생성을 위해 . C++ 에 주어야 합니다 .ii
.
2단계 - 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'
3단계 - 어셈블리 코드를 기계어 코드로 변환합니다. (예: hello.s -o hello.o)
"man as"를 보면 많은 옵션이 있습니다.
$ 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
4단계 - 링크:
# 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.
5단계 - 실행:
$ ./a.out
Hello ya!
# Optionally run $ strace ./a.out
어느 시점에서 실패했나요?
참고로 내 출력은 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