어셈블리 코드 (nasm) 컴파일에 문제가 있습니다.GCC에 링크 어셈블리 NASM 코드
Linux (elf32)에서는 g ++를 사용하여 컴파일 한 후에도 오류가 발생하지 않지만 i686-w64-mingw32-g ++ (Win32 용)로 빌드하려고하면 오류가 발생합니다.
내 build.sh 스크립트 : 어셈블리 코드
#!/bin/bash
nasm -fwin32 wct.asm
i686-w64-mingw32-g++ -m32 -O2 -Wall -fno-exceptions -ffloat-store -ffast-math -fno-rounding-math -fno-signaling-nans -fcx-limited-range -fno-math-errno -funsafe-math-optimizations -fassociative-math -freciprocal-math -ffinite-math-only -fno-signed-zeros -fno-trapping-math -frounding-math -fsingle-precision-constant -fcx-fortran-rules -fno-rtti -mfpmath=387 -mfancy-math-387 -fno-ident -fmerge-all-constants -mpreferred-stack-boundary=2 -falign-functions=1 -falign-jumps=1 -falign-loops=1 -fno-unroll-loops -fno-math-errno -s main.cpp wct.obj -o wct.exe
strip --strip-unneeded wct.exe
있습니다 :
[bits 32]
section .text
global wct
wct:
mov esi, [esp+4]
mov edi, esi
mov ecx, [esp+8]
@L:
lodsw
sub ax, 04141h
cmp al,0Fh
jne @F
dec al
jmp @E
@F:
cmp al,0Eh
jne @E
inc al
@E:
mov bx, ax
shr bx, 8
cmp bl,0Fh
jne @@F
dec bl
jmp @@E
@@F:
cmp bl,0Eh
jne @@E
inc bl
@@E:
shl al, 4
add ax, bx
stosb
loop @L
ret
MAIN.CPP : 나는 분명히 뭔가 잘못하고있는 중이 야
#include <fstream>
using namespace std;
extern "C" int wct(char* buff, int N);
#define N 1024*1024
char buff[N];
ifstream in;
ofstream out;
int size;
int main(int argc, char* argv[]) {
if (argc == 1) return 0;
in.open(argv[1], ios_base::in | ios_base::binary);
if (argc >= 3)
out.open(argv[2], ios_base::out | ios_base::binary);
if(in.is_open())
{
while(!in.eof())
{
in.read((char *)&buff, sizeof buff);
size = in.gcount()/2;
wct((char *)&buff, size);
if (out.is_open())
out.write((char *)&buff, size);
else
{
out.close();
}
}
}
in.close();
out.close();
return 0;
}
때문에 I의 build.sh 스크립트를 사용하는 동안 항상 동일한 오류가 발생합니다.
/tmp/cc3SD7dA.o:main.cpp:(.text.startup+0x90): undefined reference to `wct'
collect2: error: ld returned 1 exit status
어떻게 해결할 수 있습니까?
smac89 @ *의 wct.obj의 *에서, NASM은 컴파일리스트와 오브젝트 코드. undecorated와 데코 레이팅 된 심볼을 사용하는 것 사이에 불일치가 있다고 생각합니다. NASM은 그것을 망가 뜨리거나 GCC를 망가 뜨린다. 어느 쪽이든 그것은 호출 규칙도 필요합니다. – IInspectable
@IInspectable, 어떻게 대회에 전화 할 수 있습니까? –
[컴파일러 사용 설명서] (https://gcc.gnu.org/onlinedocs/gcc/x86-Function-Attributes.html)를 참조하십시오. – IInspectable