2014-10-04 2 views
3

x86 컴퓨터에서 gcc를 사용하여 MIPS 바이너리를 생성하고 싶습니다. MIPS 크로스 컴파일러를 설치하기 위해서 나는 this page에 대한 지시를 따랐다. gcc와 binutils를 성공적으로 설치할 수 있습니다. 크로스 컴파일러를 사용하여 간단한 hello world 프로그램을 컴파일하려고했습니다.밉스 크로스 컴파일러에서 crt1.o 오류가 발생했습니다.

/opt/cross/bin/mipsel-unknown-linux-gnu-gcc -mips1 hi.c 

다음과 같은 오류가 발생했습니다.

/opt/cross/lib/gcc/mipsel-unknown-linux-gnu/4.8.2/../../../../mipsel-unknown-linux-gnu/bin/ld: cannot find crt1.o: No such file or directory 
/opt/cross/lib/gcc/mipsel-unknown-linux-gnu/4.8.2/../../../../mipsel-unknown-linux-gnu/bin/ld: cannot find crti.o: No such file or directory 
/opt/cross/lib/gcc/mipsel-unknown-linux-gnu/4.8.2/../../../../mipsel-unknown-linux-gnu/bin/ld: cannot find -lc 
/opt/cross/lib/gcc/mipsel-unknown-linux-gnu/4.8.2/../../../../mipsel-unknown-linux-gnu/bin/ld: cannot find crtn.o: No such file or directory 
collect2: error: ld returned 1 exit status 

나는 문제를 파악하기 위해 온라인 조사를 몇 차례했고, 다음에 익숙한 명령을 변경했습니다.

/opt/cross/lib/gcc/mipsel-unknown-linux-gnu/4.8.2/../../../../mipsel-unknown-linux-gnu/bin/ld: /usr/lib/i386-linux-gnu/crt1.o: Relocations in generic ELF (EM: 3) 
/usr/lib/i386-linux-gnu/crt1.o: error adding symbols: File in wrong format 
collect2: error: ld returned 1 exit status 

나는 문제가 무엇인지 확실하지 않다 :

/opt/cross/bin/mipsel-unknown-linux-gnu-gcc -B/usr/lib/i386-linux-gnu -mips1 hi.c 

지금이 오류 메시지가 표시됩니다. 내가 생각할 수있는 유일한 것은 gcc를 빌드 할 때 프로그램을 구성하기 위해 전달되는 "--without-headers"옵션이다. linux-mips 페이지에 주어진 gcc에 대한 설정 명령어는 아래와 같습니다.

% ../gcc-3.8.2/configure --target=$TARGET --prefix=$PREFIX \ 
    --enable-languages=c --without-headers \ 
    --with-gnu-ld --with-gnu-as \ 
    --disable-shared --disable-threads \ 
    --disable-libmudflap --disable-libgomp \ 
    --disable-libssp --disable-libquadmath \ 
    --disable-libatomic 

몇 가지 도움을 주시면 감사하겠습니다. 크로스 컴파일러를 생성 한 시스템은 gcc4.7.2-5를 사용합니다. gcc-4.8.2와 binutils-2.24 소스를 사용하여 크로스 컴파일러를 생성했습니다.

+0

mips-linux 용으로 교차 컴파일하려는 경우 http://ellcc.org를 참조하십시오. 바이너리도 다운로드 할 수 있습니다. –

+0

런타임 라이브러리가 누락되었습니다. 전체 개발 환경에는 컴파일러와 binutils 외에도 MIPS 용 라이브러리가 필요합니다. –

답변

2

/옵션/크로스/빈 /에는 mipsel-알 - 리눅스 GNU-GCC -mips1의 hi.c

는 컴파일 명령에 SYSROOT를 추가합니다.

/opt/cross/bin/mipsel-unknown-linux-gnu-gcc -mips1 --sysroot=/opt/cross/... hi.c 

자동으로 헤더와 라이브러리 경로를 제공 할 것입니다 SYSROOT (오히려 -I-L 개별적를 추가하는 대신) :이 비슷한을 보일 것입니다.

사용 된 경로에 bin/, include/lib/이 있으므로 사용자가 SYSROOT 일 때 알 수 있습니다.

$ ls /usr/arm-linux-gnueabi 
bin include lib 

그래서,이 예제에서, 당신은 --sysroot=/usr/arm-linux-gnueabi을 사용하십시오 SYSROOTarm-linux-gnueabi (즉, arm-linux-gnueabi-gccarm-linux-gnueabi-g++)에 대한 예를 들어, 여기. 당신이 다음 find 수행합니다 SYSROOT의 위치를 ​​도움이 필요한 경우

: 귀하의 경우에는

$ find /usr -name crt1.o 
/usr/arm-linux-gnueabi/lib/crt1.o 
/usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o 
/usr/lib/x86_64-linux-gnu/crt1.o 

을, 당신은 아마 /opt/cross에서 검색합니다. 분명히 목표물 (arm-linux-gnueabi)에 대한 것이고 호스트 (x86_64-linux-gnu)에 대한 것이 아닙니다.

+0

sysroot 옵션을 사용할 때 다음 오류가 발생합니다. '/opt/cross/lib/gcc/mipsel-unknown-linux-gnu/4.8.2/../../../../mipsel-unknown-linux-gnu/bin/ld :이 링커는 다음과 같습니다. sysroot를 사용하도록 구성되지 않았습니다 .' sysroot 옵션으로 모든 것을 다시 컴파일해야합니다. – puck

+0

죄송합니다. 본 적이 없습니다. 그러나 나는 내 자신의 툴 체인을 만들지 않습니다. – jww

0

--sysroot =를 추가하면이 문제가 해결됩니다. 크로스 컴파일 할 때 crt1.o 또는 crtX.o가있는 다른 폴더 만 sysroot 디렉토리로 선택하면 안됩니다. 호스트 컴퓨터의 파일 일 수 있습니다. (당신이 x86에서 돌아가고 있다면, x86을위한 것입니다). 다시 32 비트와 64 비트에서 다릅니다.

최신 버전의 GCC 툴체인에는 적절한 sysroot 및 crt1.o가있는 sdk 부분이 있어야합니다. 이것은 ABI와 타겟 아키텍처와 함께해야합니다.

관련 문제