'2016/04'에 해당되는 글 2건

  1. 2016.04.28 libwinpthread 가 계속 동적 빌드만 될 때
  2. 2016.04.19 디버깅 매크로

환경: QtCreator3.4.2 / mingw4.9.2 / Qt 4.8.6 static


QThread 를 사용하고 정적 빌드를 하려니 libwinpthread 에 대한 의존성이 생겼나보다.


구글링을 해보니


http://stackoverflow.com/questions/13768515/how-to-do-static-linking-of-libwinpthread-1-dll-in-mingw


요약) -static -lpthread 붙여라


이 답변을 확인하게 되었는데,

막상 위 옵션을 QtCreator의 빌드 옵션에서 컴파일러 옵션에 넣어봤는데 도무지 동작하지가 않았다.

위 링크가 또 다른 여러 곳에서 링크되어 있는 것으로 봐서는 아마도 맞는 답변이지 싶은데 말이다.


컴파일 로그를 살펴보니 다음과 같았다.


...

g++ -static-libgcc -static-libstdc++ -Wl,-s -Wl,-subsystem,windows -o release\sample.exe object_script.trainer.Release  -L"c:\Qt\4.8.6_static\lib" -lmingw32 -lqtmain -lQtXml -lQtGui -lQtNetwork -lgdi32 -lcomdlg32 -loleaut32 -limm32 -lwinmm -lwinspool -lmsimg32 -lQtCore -lole32 -luuid -lws2_32 -ladvapi32 -lshell32 -luser32 -lkernel32


어라..? 내가 추가 한 -static -lpthread가 보이지 않았다.


여러가지 찾아 보다 알아낸 결과는 아래와 같다.


*.pro 파일 내에 사용할 라이브러리를 추가 한다.

LIBS += -static -lwinpthread


나같은 경우 위와 같이 추가하고 빌드한 결과 컴파일 로그에 다음과 같이 추가된 것을 확인할 수 있었다.


g++ -static-libgcc -static-libstdc++ -Wl,-s -Wl,-subsystem,windows -o release\sample.exe object_script.trainer.Release -L"c:\Qt\4.8.6_static\lib" -lmingw32 -lqtmain -static -lwinpthread -lQtXml -lQtGui -lQtNetwork -lgdi32 -lcomdlg32 -loleaut32 -limm32 -lwinmm -lwinspool -lmsimg32 -lQtCore -lole32 -luuid -lws2_32 -ladvapi32 -lshell32 -luser32 -lkernel32


release 시에만 추가하고 싶다면

release {

LIBS += -static -lwinpthread

}

요렇게 해주면 release 시에만 정적으로 추가하게 된다.

'QT' 카테고리의 다른 글

undefined reference to 'vtable for...'  (0) 2016.05.19
반투명 그릴 때 배경 잔상 문제  (0) 2016.05.11
디버깅 매크로  (0) 2016.04.19
QByteArray 의 reserve() vs resize()  (0) 2016.03.18
QT static build with mingw32  (0) 2015.09.17
Posted by 독뽀
,

디버깅 매크로

QT 2016. 4. 19. 15:42

[파일 명][함수:라인] 내용


이런 형식이 필요하여 만들었음.


2018.12.27 수정, 이전 버전은 UTF8 지원이 불가함 (한글 출력 안됨)

수정 버전 사용할 것을 추천..


#ifndef DEFINE_MACRO_H

#define DEFINE_MACRO_H


#include <QDebug>


#define ENTIRE_DEBUG_ON     1

#define DEBUG_VERBOSE       1


#if ENTIRE_DEBUG_ON

#if DEBUG_VERBOSE

#define VERBOSE() qDebug("[%s][%s:%d]", __FILE__, __func__, __LINE__)

#endif

#define DEBUG(MESSAGE) qDebug("[%s][%s:%d] %s", __FILE__, __func__, __LINE__, (MESSAGE))

#define SDEBUG(...) { \

    QString arg; \

    arg.sprintf(__VA_ARGS__); \

    qDebug() << QString("[%1][%2:%3]").arg(__FILE__).arg(__func__).arg(__LINE__) << arg.toUtf8(); \

}

#else

#define VERBOSE() ;

#define DEBUG(MESSAGE) ;

#define SDEBUG(...) ;

#endif


#endif // DEFINE_MACRO_H


ex)

VERBOSE(); // 현재 위치 로그 출력

DEBUG("Something is wrong here"); // 현재 위치에 문자열과 함께 로그 출력

SDEBUG("Something is wrong with value [%d]", wrongValue); // 현채 위치에 printf 포맷 형태로 로그 출력


보면 알겠지만 ENTIRE_DEBUG_ON 을 0으로 바꾸면 모든 디버그 메시지 출력을 끈다.

DEBUG_VERBOSE 를 0으로 바꾸면 VERBOSE만 끈다. 이건 응용해서 디버그 레벨을 조절하면 될듯.



Posted by 독뽀
,