2014-12-25 4 views
-1

그게 질문입니다. 기본적으로 내 문제는 옵션을 -fsanitize=address -static-libasan (잘못된 포인터 디버깅을위한 멋진 것들 등)와 ARM에 대한 응용 프로그램을 컴파일하려고하는 것입니다. 이 명령은 실행 파일에 직접 컴파일되지만 오브젝트 파일에서 컴파일 할 때는 작동하지 않습니다. Ofc는 정적 라이브러리가 libasan.a이라는 것을 알았습니다. 어쨌든 객체 파일의 모든 것을 링크하려고 할 때,«pthread»에있는 정의되지 않은 참조들과 lib-owner를 찾지 못했던 몇몇 함수에 대해 말하고 있습니다.GCC : 정적으로 링크 된 라이브러리 나열

따라서 파일을 -fsanitize=address -static-libasan으로 컴파일하고 라이브러리가 정적으로 링크 된 것을 확인하여 나중에 오브젝트 파일에서 라이브러리를 만들 수 있습니다.

+2

_ "... pthread에서 정의되지 않은 참조에 대해 말합니다 ..."_ 컴파일러 및 링커 옵션에'-pthread '를 추가하려고 시도 했습니까? 물론 –

+0

@ πάνταῥε. –

+0

명사 앞에 "a"를 사용하면 명사를 복수로 사용할 수 없습니다. "라이브러리", "잘못된 포인터", "객체 파일"-이 모든 것은 똑같이 무의미합니다. –

답변

1

실행 파일은 개체 파일을 가져온 정적 라이브러리의 추적을 저장하지 않습니다. 그러나 대부분이 라이브러리는 링크 할 때 명시 적으로 지정됩니다. 컴파일러는 몇 가지 표준 정적 라이브러리 만 가져옵니다. gcc의 경우 -v 옵션을 사용하여 링커에 전달 된 실제 명령 줄을 비롯한 다양한 정보를 볼 수 있습니다 (일부 구현에서는 --verbose을 사용하고 링커 -Wl,--verbose을 사용하려는 것 같습니다). 이 출력은 -lgcc-lstdc++과 같이 암시 적으로 링크 된 모든 라이브러리를 표시해야합니다.

컴파일 할 때 언어 별 프론트 엔드와 컴파일러 플래그를 사용해야합니다. 컴파일 할 때 -pthreadg++과 같이 사용했지만 gcc 플래그를 사용하지 않고 연결하려고 시도한 것처럼 문제 설명이 들립니다 (설명과 관련하여 몇 가지 스레딩 관련 플래그가 있지만 사용 된 설명이 없습니다). 내 컴퓨터에 -v 옵션을 사용할 때

그냥 여기, 모욕을 다루는 예제 출력합니다 : 실제로 연결하기 위해 설치된 모든 정적 라이브러리는

ThreadGard:stackoverflow kuehl$ cat hello.cpp 
#include <iostream> 

int main() 
{ 
    std::cout << "hello, world\n"; 
    return 0; 
} 
ThreadGard:stackoverflow kuehl$ g++ -v -static hello.cpp 
Using built-in specs. 
COLLECT_GCC=g++ 
COLLECT_LTO_WRAPPER=/opt/gcc-4.9.2/libexec/gcc/x86_64-apple-darwin13.4.0/4.9.2/lto-wrapper 
Target: x86_64-apple-darwin13.4.0 
Configured with: ../gcc-4.9.2/configure --prefix=/opt/gcc-4.9.2 --with-gmp=/opt/gcc-infrastructure --with-mpfr=/opt/gcc-infrastructure --enable-decimal-float=bid --enable-lto --enable-languages=c,c++ 
Thread model: posix 
gcc version 4.9.2 (GCC) 
COLLECT_GCC_OPTIONS='-mmacosx-version-min=10.9.4' '-v' '-static' '-mtune=core2' 
/opt/gcc-4.9.2/libexec/gcc/x86_64-apple-darwin13.4.0/4.9.2/cc1plus -quiet -v -D__STATIC__ hello.cpp -quiet -dumpbase hello.cpp -mmacosx-version-min=10.9.4 -mtune=core2 -auxbase hello -version -o /var/folders/b_/64plfvs936v5ylx36qwc8rg00000gp/T//ccrt7fXS.s 
GNU C++ (GCC) version 4.9.2 (x86_64-apple-darwin13.4.0) 
    compiled by GNU C version 4.9.2, GMP version 5.0.5, MPFR version 3.1.1, MPC version 1.0.1 
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 
ignoring nonexistent directory "/opt/gcc-4.9.2/lib/gcc/x86_64-apple-darwin13.4.0/4.9.2/../../../../x86_64-apple-darwin13.4.0/include" 
#include "..." search starts here: 
#include <...> search starts here: 
/opt/gcc-4.9.2/lib/gcc/x86_64-apple-darwin13.4.0/4.9.2/../../../../include/c++/4.9.2 
/opt/gcc-4.9.2/lib/gcc/x86_64-apple-darwin13.4.0/4.9.2/../../../../include/c++/4.9.2/x86_64-apple-darwin13.4.0 
/opt/gcc-4.9.2/lib/gcc/x86_64-apple-darwin13.4.0/4.9.2/../../../../include/c++/4.9.2/backward 
/opt/gcc-4.9.2/lib/gcc/x86_64-apple-darwin13.4.0/4.9.2/include 
/usr/local/include 
/opt/gcc-4.9.2/include 
/opt/gcc-4.9.2/lib/gcc/x86_64-apple-darwin13.4.0/4.9.2/include-fixed 
/usr/include 
/System/Library/Frameworks 
/Library/Frameworks 
End of search list. 
GNU C++ (GCC) version 4.9.2 (x86_64-apple-darwin13.4.0) 
    compiled by GNU C version 4.9.2, GMP version 5.0.5, MPFR version 3.1.1, MPC version 1.0.1 
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 
Compiler executable checksum: fea0def5b69cf8ae349b2f1faf4b1d23 
COLLECT_GCC_OPTIONS='-mmacosx-version-min=10.9.4' '-v' '-static' '-mtune=core2' 
as -arch x86_64 -force_cpusubtype_ALL -static -o /var/folders/b_/64plfvs936v5ylx36qwc8rg00000gp/T//ccPF77oR.o /var/folders/b_/64plfvs936v5ylx36qwc8rg00000gp/T//ccrt7fXS.s 
COMPILER_PATH=/opt/gcc-4.9.2/libexec/gcc/x86_64-apple-darwin13.4.0/4.9.2/:/opt/gcc-4.9.2/libexec/gcc/x86_64-apple-darwin13.4.0/4.9.2/:/opt/gcc-4.9.2/libexec/gcc/x86_64-apple-darwin13.4.0/:/opt/gcc-4.9.2/lib/gcc/x86_64-apple-darwin13.4.0/4.9.2/:/opt/gcc-4.9.2/lib/gcc/x86_64-apple-darwin13.4.0/ 
LIBRARY_PATH=/opt/gcc-4.9.2/lib/gcc/x86_64-apple-darwin13.4.0/4.9.2/:/opt/gcc-4.9.2/lib/gcc/x86_64-apple-darwin13.4.0/4.9.2/../../../:/usr/lib/ 
COLLECT_GCC_OPTIONS='-mmacosx-version-min=10.9.4' '-v' '-static' '-mtune=core2' 
/opt/gcc-4.9.2/libexec/gcc/x86_64-apple-darwin13.4.0/4.9.2/collect2 -static -arch x86_64 -macosx_version_min 10.9.4 -weak_reference_mismatches non-weak -o a.out -lcrt0.o -L/opt/gcc-4.9.2/lib/gcc/x86_64-apple-darwin13.4.0/4.9.2 -L/opt/gcc-4.9.2/lib/gcc/x86_64-apple-darwin13.4.0/4.9.2/../../.. /var/folders/b_/64plfvs936v5ylx36qwc8rg00000gp/T//ccPF77oR.o /opt/gcc-4.9.2/lib/gcc/x86_64-apple-darwin13.4.0/4.9.2/../../../libstdc++.a -no_compact_unwind -no_pie -lgcc_eh -lgcc -v 
collect2 version 4.9.2 
/usr/bin/ld -static -arch x86_64 -macosx_version_min 10.9.4 -weak_reference_mismatches non-weak -o a.out -lcrt0.o -L/opt/gcc-4.9.2/lib/gcc/x86_64-apple-darwin13.4.0/4.9.2 -L/opt/gcc-4.9.2/lib/gcc/x86_64-apple-darwin13.4.0/4.9.2/../../.. /var/folders/b_/64plfvs936v5ylx36qwc8rg00000gp/T//ccPF77oR.o /opt/gcc-4.9.2/lib/gcc/x86_64-apple-darwin13.4.0/4.9.2/../../../libstdc++.a -no_compact_unwind -no_pie -lgcc_eh -lgcc -v 
@(#)PROGRAM:ld PROJECT:ld64-241.9 
configured to support archs: armv6 armv7 armv7s arm64 i386 x86_64 x86_64h armv6m armv7m armv7em 
Library search paths: 
    /opt/gcc-4.9.2/lib/gcc/x86_64-apple-darwin13.4.0/4.9.2 
    /opt/gcc-4.9.2/lib 
    /usr/lib 
    /usr/local/lib 
Framework search paths: 
    /Library/Frameworks/ 
    /System/Library/Frameworks/ 
ld: library not found for -lcrt0.o 
collect2: error: ld returned 1 exit status 

가 없습니다.

는/usr/빈/LD -static -arch x86_64에 -macosx_version_min 10.9.4이 -lcrt0의 a.out이 아닌 약한 -o를 -weak_reference_mismatches : 출력이 명확하게 링커 호출을 나열하지만, ​​그 점 외에입니다. lib/gcc/x86_64-apple-darwin13.4.0/4.9.2 -L/opt/gcc-4.9.2/lib/gcc/x86_64-apple-darwin13.4.0/4.9.2 /../../ ../var/folders/b_/64plfvs936v5ylx36qwc8rg00000gp/T//ccPF77oR.o /opt/gcc-4.9.2/lib/gcc/x86_64-apple-darwin13.4.0/4.9. 2 /../../../ 된 libstdC++ -no_compact_unwind -no_pie -lgcc_eh 약간의 강조는 독자를 위해 쉽게하기 위해 추가로 -v

이 (-lgcc -. NE 것 같다 cessary)

+0

전혀 대답하지 않습니다. 정적 libs에 대한 컴파일 된 바이너리 정보를 얻고 싶지 않습니다. 컴파일 할 때 정적 링크 된 libs를 보여주는 옵션이 필요합니다. 예 : 간단한«helloworld를 만들려고 노력하십시오.cpp»를 실행하고'g ++ -static-libgcc helloworld.cpp'로 컴파일합니다. 라이브러리가 정적으로 정확히 링크 된 것을 어떻게 알 수 있습니까? * (이 예제에서는 분명히'libgcc'이지만, 제 질문에서 이것은 작동하지 않습니다 - 이미'libasan'을 발견했으며'-static-libasan'에 의해 영향을받는 라이브러리가 남아 있습니다) * –

+0

'-v' 옵션의 어느 부분에서 정확히 언급하지 않았습니까? –

+0

실제로, Dietmar Kühl은 너 혼자 해봤습니까? 이전 예제의 작은 예제에서'libgcc'가 정적으로 링크된다는 힌트를 출력으로 보지 못했습니다. –