2014-04-11 2 views
1

간단한 C 프로그램을 컴파일하려고하는데 분명히 프로그램이 제대로 연결되어 있지 않습니다.간단한 C 프로그램 컴파일이 제대로 연결되지 않았습니다.

내가/컴파일 할 때 내가 갖는 출력 프로그램을 링크 나는 다음과 같은 명령을 사용하여 프로그램을 컴파일하려고

/* Simple C program. */ 
#include<stdio.h> 

int main() { 
printf("Hello MIPS! \n"); 

return 0; 
} 

, mips-gcc -v hello.c -o hello

에서는 hello.c,

Using built-in specs. 
COLLECT_GCC=bin/mips-gcc 
COLLECT_LTO_WRAPPER=/opt/cross/gcc-mips/libexec/gcc/mips/4.8.2/lto-wrapper 
Target: mips 
Configured with: ../gcc-4.8.2/configure --target=mips --prefix=/opt/cross/gcc-mips --enable-interwork --enable-multilib --enable-languages=c --with-newlib --with-headers=/opt/cross/src/newlib-2.1.0/newlib/libc/include/ --disable-libssp --disable-nls 
Thread model: single 
gcc version 4.8.2 (GCC) 
COLLECT_GCC_OPTIONS='-v' '-o' 'hello' 
/opt/cross/gcc-mips/libexec/gcc/mips/4.8.2/cc1 -quiet -v hello.c -quiet -dumpbase hello.c -auxbase hello -version -o /var/folders/1z/k_by6wd95tsccc6s1_tkttpr0000gn/T//ccqPwmTq.s 
GNU C (GCC) version 4.8.2 (mips) 
    compiled by GNU C version 4.2.1 Compatible Apple LLVM 5.1 (clang-503.0.38), GMP version 4.3.2, MPFR version 2.4.2, MPC version 0.8.1 
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 
#include "..." search starts here: 
#include <...> search starts here: 
/opt/cross/gcc-mips/lib/gcc/mips/4.8.2/include 
/opt/cross/gcc-mips/lib/gcc/mips/4.8.2/include-fixed 
/opt/cross/gcc-mips/lib/gcc/mips/4.8.2/../../../../mips/sys-include 
/opt/cross/gcc-mips/lib/gcc/mips/4.8.2/../../../../mips/include 
End of search list. 
GNU C (GCC) version 4.8.2 (mips) 
    compiled by GNU C version 4.2.1 Compatible Apple LLVM 5.1 (clang-503.0.38), GMP version 4.3.2, MPFR version 2.4.2, MPC version 0.8.1 
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 
Compiler executable checksum: e28a4def2fba399e5af333f18f473404 
COLLECT_GCC_OPTIONS='-v' '-o' 'hello' 
/opt/cross/gcc-mips/lib/gcc/mips/4.8.2/../../../../mips/bin/as -EB -O1 -no-mdebug -mabi=32 -o /var/folders/1z/k_by6wd95tsccc6s1_tkttpr0000gn/T//ccgd49A6.o /var/folders/1z/k_by6wd95tsccc6s1_tkttpr0000gn/T//ccqPwmTq.s 
COMPILER_PATH=/opt/cross/gcc-mips/libexec/gcc/mips/4.8.2/:/opt/cross/gcc-mips/libexec/gcc/mips/4.8.2/:/opt/cross/gcc-mips/libexec/gcc/mips/:/opt/cross/gcc-mips/lib/gcc/mips/4.8.2/:/opt/cross/gcc-mips/lib/gcc/mips/:/opt/cross/gcc-mips/lib/gcc/mips/4.8.2/../../../../mips/bin/ 
LIBRARY_PATH=/opt/cross/gcc-mips/lib/gcc/mips/4.8.2/:/opt/cross/gcc-mips/lib/gcc/mips/4.8.2/../../../../mips/lib/ 
COLLECT_GCC_OPTIONS='-v' '-o' 'hello' 
/opt/cross/gcc-mips/libexec/gcc/mips/4.8.2/collect2 -EB -o hello /opt/cross/gcc-mips/lib/gcc/mips/4.8.2/crti.o /opt/cross/gcc-mips/lib/gcc/mips/4.8.2/crtbegin.o -L/opt/cross/gcc-mips/lib/gcc/mips/4.8.2 -L/opt/cross/gcc-mips/lib/gcc/mips/4.8.2/../../../../mips/lib /var/folders/1z/k_by6wd95tsccc6s1_tkttpr0000gn/T//ccgd49A6.o -lgcc -lgcc /opt/cross/gcc-mips/lib/gcc/mips/4.8.2/crtend.o /opt/cross/gcc-mips/lib/gcc/mips/4.8.2/crtn.o 
/opt/cross/gcc-mips/lib/gcc/mips/4.8.2/../../../../mips/bin/ld: warning: cannot find entry symbol _start; defaulting to 0000000000400038 
/var/folders/1z/k_by6wd95tsccc6s1_tkttpr0000gn/T//ccgd49A6.o: In function `main': 
(.text+0x18): undefined reference to `puts' 
collect2: error: ld returned 1 exit status 
+0

링커 명령에 C 라이브러리가 자동으로 포함되어있는 것으로 나타나지 않습니다. gcc 커맨드 라인에'-lc'를 추가하면 도움이됩니까? – twalberg

+0

다음과 같이 컴파일 해 보았습니다.'mips-gcc -lc -v hello.c -o hello'하지만 같은 에러 결과가 나옵니다. – Chris

+0

끝에 '-lc'을 넣어보세요. 'mips-gcc -v -o hello hello.c -lc' – twalberg

답변

2

중지 통과 -v; 그것은 단지 당신의 문제와 관련이없는 디버그 아웃풋의 미친 양을 만들어 낸다.

mips-gcc -o hello hello.c는 두 번째 오류는 (puts를 제공하는)를 libc 도서관에서 끌어 명령 줄의 끝에 -lc이 필요하다는 것을 나타냅니다

ld: warning: cannot find entry symbol _start; defaulting to 0000000000400038 
ccgd49A6.o: In function `main': (.text+0x18): undefined reference to `puts' 

같은 것을 생산하고 있습니다. 첫 번째 오류는 crt0.o (어딘가에서 _start 제공)이 필요하다는 것을 나타냅니다. 다른 말로하면, "베어 메탈 (bare-metal)"모드에서 컴파일러를 호출하는 것입니다.이 모드에서는 호스팅 된 C 환경이 아닌 머신에서 직접 실행되는 코드를 작성한다고 가정합니다. 명령 줄 인수, 표준 라이브러리 및 파일 시스템 등)를 제공합니다.

귀하의 문제는 2006 년에이 사람의 유사 보인다 http://osdir.com/ml/lib.newlib/2006-07/msg00029.html 솔루션 crt0.o을 포함 링커 지시 파일을 지정 -T nullmon.ld를 사용하는이 있었다; mips-gcc 대신 mips-elf-gcc을 사용하는 것이 좋습니다.

그러나 베어 메탈 프로그래밍은 보통 매우 낮은을 시작해야하며 어셈블리에 익숙해지기 전까지는 C만큼 복잡하지는 않습니다. 자세한 내용은 Bare metal cross compilers input에 대한 답변을 참조하십시오 (MIPS에 대해서도 구체적으로 설명합니다).

관련 문제