2017-11-09 5 views
1

저는 리눅스에서 gcc 4.8.5를 사용합니다. 주소 살균기를 사용하고 싶지만 프로그램에 대한 정보를 반환하지 않습니다. 플래그 :gcc - 주소 살균제 사용법

SET(CMAKE_CXX_FLAGS "-Wall -Wno-error -g -std=c++11 -fno-omit-frame-pointer -fsanitize=address") 
SET(CMAKE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} -fno-omit-frame-pointer -fsanitize=address") 

링크 라이브러리 :

target_link_libraries(testcpp asan) 

메모리 누수와 테스트 프로그램 :

int main() 
{ 
    int *prt = new int; 
    return 0; 
} 

에 어떤 문제가 있습니까? 최근 데비안/SID/- 64에 GCC7 함께

+0

프로그램을 명령 줄에서 직접 컴파일하십시오 ('cmake'는 우리를 혼란스럽게합니다). 질문에 컴파일 명령을 표시하십시오. –

+1

BTW GCC4.8은 상당히 오래되었으며 주소 소독기가 많이 발전했습니다 (특히 GCC 5 및 GCC 6). ** 새로운 GCC **를 사용해보십시오 ** (가능하면 GCC 7) –

+0

이미'-fsanitize = address'를 지정했다면'asan'에 링크 할 필요가 없다는 것이 나의 이해입니다. 또한 실제로는 살균제가 실행되도록 프로그램을 실행해야합니다. –

답변

1

I 컴파일이

g++ -fsanitize=address -g3 -std=c++11 irbis.cc -o irbis 

./irbis 실행에서 누수가 정당 검출을 사용

// file irbis.cc 
int main() 
{ 
    int *prt = new int; 
    return 0; 
} 

:

================================================================= 
==22742==ERROR: LeakSanitizer: detected memory leaks 

Direct leak of 4 byte(s) in 1 object(s) allocated from: 
    #0 0x7f77ea911340 in operator new(unsigned long) 
      (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdb340) 
    #1 0x55ea91cca81b in main /home/basile/tmp/irbis.cc:4 
    #2 0x7f77e9c1f2e0 in __libc_start_main 
      (/lib/x86_64-linux-gnu/libc.so.6+0x202e0) 

SUMMARY: AddressSanitizer: 4 byte(s) leaked in 1 allocation(s). 

그래서 GCC 컴파일러를 업그레이드하십시오 (적어도 GCC6까지). 나는 GCC4.8이 address sanitizer & C++ 11 (BTW, GCC4.8은 쓸모 없으며 2017 년 11 월에 GCC5도 사용되지 않음)에 대한 불완전한 지원을했다는 것을 알고 있습니다.

+0

gcc와 작동하지 않습니다. 4.8.5 – Irbis

+0

놀랍지 않습니다. 최근 GCC가 필요하고 4.8은 하나가 아닙니다. –