2010-08-01 3 views
0

나는 MinGW의 g ++ 컴파일러로 gcc instrument 함수를 사용하려고 시도하지만, 나는 항상 에 링커 문제가있다. MinGW/MSYS에서 계기 기능을 사용할 수 있습니까?MinGW에서 gcc/g ++ 계측기 기능 사용?

링커 실패 출력 :

$ g++ instrumentFunctions.cpp -o iftest -finstrument-functions >> iflog.txt 
C:/Users/HELLHO~1/AppData/Local/Temp/ccUwxrxt.o:instrumentFunctions.cpp:(.text+0x4e): undefined reference to `__cyg_prof 
ile_func_enter' 
C:/Users/HELLHO~1/AppData/Local/Temp/ccUwxrxt.o:instrumentFunctions.cpp:(.text+0x158): undefined reference to `__cyg_pro 
file_func_exit' 
C:/Users/HELLHO~1/AppData/Local/Temp/ccUwxrxt.o:instrumentFunctions.cpp:(.text+0x179): undefined reference to `__cyg_pro 
file_func_enter' 
C:/Users/HELLHO~1/AppData/Local/Temp/ccUwxrxt.o:instrumentFunctions.cpp:(.text+0x18c): undefined reference to `__cyg_pro 
file_func_exit' 
C:/Users/HELLHO~1/AppData/Local/Temp/ccUwxrxt.o:instrumentFunctions.cpp:(.text+0x1a7): undefined reference to `__cyg_pro 
file_func_enter' 
C:/Users/HELLHO~1/AppData/Local/Temp/ccUwxrxt.o:instrumentFunctions.cpp:(.text+0x1bf): undefined reference to `__cyg_pro 
file_func_exit' 
C:/Users/HELLHO~1/AppData/Local/Temp/ccUwxrxt.o:instrumentFunctions.cpp:(.text+0x1db): undefined reference to `__cyg_pro 
file_func_enter' 
C:/Users/HELLHO~1/AppData/Local/Temp/ccUwxrxt.o:instrumentFunctions.cpp:(.text+0x1f3): undefined reference to `__cyg_pro 
file_func_exit' 
C:/Users/HELLHO~1/AppData/Local/Temp/ccUwxrxt.o:instrumentFunctions.cpp:(.text+0x22f): undefined reference to `__cyg_pro 
file_func_enter' 
C:/Users/HELLHO~1/AppData/Local/Temp/ccUwxrxt.o:instrumentFunctions.cpp:(.text+0x27a): undefined reference to `__cyg_pro 
file_func_exit' 
C:/Users/HELLHO~1/AppData/Local/Temp/ccUwxrxt.o:instrumentFunctions.cpp:(.text+0x29b): undefined reference to `__cyg_pro 
file_func_enter' 
C:/Users/HELLHO~1/AppData/Local/Temp/ccUwxrxt.o:instrumentFunctions.cpp:(.text+0x2e4): undefined reference to `__cyg_pro 
file_func_exit' 
C:/Users/HELLHO~1/AppData/Local/Temp/ccUwxrxt.o:instrumentFunctions.cpp:(.text+0x2ff): undefined reference to `__cyg_pro 
file_func_enter' 
C:/Users/HELLHO~1/AppData/Local/Temp/ccUwxrxt.o:instrumentFunctions.cpp:(.text+0x326): undefined reference to `__cyg_pro 
file_func_exit' 
C:/Users/HELLHO~1/AppData/Local/Temp/ccUwxrxt.o:instrumentFunctions.cpp:(.text+0x341): undefined reference to `__cyg_pro 
file_func_enter' 
C:/Users/HELLHO~1/AppData/Local/Temp/ccUwxrxt.o:instrumentFunctions.cpp:(.text+0x368): undefined reference to `__cyg_pro 
file_func_exit' 
C:/Users/HELLHO~1/AppData/Local/Temp/ccUwxrxt.o:instrumentFunctions.cpp:(.text$printf[_printf]+0x16): undefined referenc 
e to `__cyg_profile_func_enter' 
C:/Users/HELLHO~1/AppData/Local/Temp/ccUwxrxt.o:instrumentFunctions.cpp:(.text$printf[_printf]+0x43): undefined referenc 
e to `__cyg_profile_func_exit' 
C:/Users/HELLHO~1/AppData/Local/Temp/ccUwxrxt.o:instrumentFunctions.cpp:(.text$_ZSt3minIjERKT_S2_S2_[unsigned int const& 
std::min<unsigned int>(unsigned int const&, unsigned int const&)]+0x15): undefined reference to `__cyg_profile_func_ent 
er' 
C:/Users/HELLHO~1/AppData/Local/Temp/ccUwxrxt.o:instrumentFunctions.cpp:(.text$_ZSt3minIjERKT_S2_S2_[unsigned int const& 
std::min<unsigned int>(unsigned int const&, unsigned int const&)]+0x42): undefined reference to `__cyg_profile_func_exi 
t' 
collect2: ld returned 1 exit status 

g ++ 명령 내가 사용 : 내 testsource의

g++ iftest.cpp -o iftest -finstruction-functions 

리스팅 :

#include <stdio.h> 

    void __cyg_profile_func_enter(void *, void *) __attribute__ ((no_instrument_function)); 

    void __cyg_profile_func_enter(void *func, void *callsite) 
    { 
    printf("%p\n", (int)func); 
    } 


    void func_c(void) 
    { 
    return; 
    } 

    void func_b(void) 
    { 
    func_c(); 

    return; 
    } 

    void func_a(void) 
    { 
    func_b(); 
    return; 
    } 


    int main() 
    { 
    func_a(); 
    func_c(); 
    } 

답변

5

을 당신은 "* C를 기능을 __cyg를 제공해야 "연계. C++로 정의 된 함수는 일반적으로 C++로 작성되지 않은 라이브러리에서 사용할 수없는 변형 된 이름을 가져옵니다. 컴파일러에게 'extern "C"{} 블록을 사용하여 C가 제공 할 함수를 제공하도록 요청할 수 있습니다. 다음은 잘 컴파일해야합니다.

#include <stdio.h> 

extern "C" { 
    void __cyg_profile_func_enter(void *, void *) __attribute__ ((no_instrument_function)); 

    void __cyg_profile_func_enter(void *func, void *callsite) 
    { 
    printf("enter %p\n", func); 
    } 
    void __cyg_profile_func_exit(void *, void *) __attribute__ ((no_instrument_function)); 

    void __cyg_profile_func_exit(void *func, void *callsite) 
    { 
    printf("exit %p\n", func); 
    } 

} 
    void func_c(void) 
    { 
    return; 
    } 

    void func_b(void) 
    { 
    func_c(); 

    return; 
    } 

    void func_a(void) 
    { 
    func_b(); 
    return; 
    } 


    int main() 
    { 
    func_a(); 
    func_c(); 
    }