[OS X] gcc로 -static 옵션을 사용하면 clang : error가 납니다.

조회수 2685회

간단한 쉘 실행하는 c코드를 작성해서 gcc로 -static 옵션을 주고 컴파일 했는데요. 다음과 같은 오류가 납니다.

ld: library not found for -lcrt0.o clang: error: linker command failed with exit code 1 (use -v to see invocation)

어떻게 해결해야 할까요?

  • (•́ ✖ •̀)
    알 수 없는 사용자

2 답변

  • 위 설명처럼 gcc 라이브러리들 자체가 static 으로 모두 컴파일 된 것이 아니라서 무조건 static 라이브러리를 쓰도록 하는 -static 을 쓸 수가 없습니다. 어떤 라이브러리가 스태틱으로 컴파일 된 경우라면 -llibrary.a 처럼 스태틱 라이브러리를 직접 지시하던가 -Bstatic 명령을 써서 static 라이브러리를 검색하도록 지시하면 됩니다.

    • (•́ ✖ •̀)
      알 수 없는 사용자
  • Apple은 Mac OS X의 gcc에서 static linking를 지원하지 않는다고 합니다.

    Apple does not support statically linked binaries on Mac OS X. A statically linked binary assumes binary compatibility at the kernel system call interface, and we do not make any guarantees on that front. Rather, we strive to ensure binary compatibility in each dynamically linked system library and framework.

    참고: https://developer.apple.com/library/mac/qa/qa1118/_index.html

    • (•́ ✖ •̀)
      알 수 없는 사용자

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)