Pages

Tuesday, June 9, 2015

Building Qt Creator 3.4.1 with mingw-builds 5.1.0R0

There are some issues in building Qt Creator with mingw-builds 5.1.0 Release 0. Here are compile errors and workarounds:

----------------------------------------
[QString::QString(const char *) is private]

The issue occurs in building qbs and on line 108 of file src/lib/corelib/tools/filetime_win.cpp. It seems to be related to QString header file when QT_NO_CAST_FROM_ASCII is defined, but I have no idea on details.

You can see the line looks like this:
const QString result = QString("%1.%2.%3 %4:%5:%6")


And you can change the line like this to workaround:
const QString result = QString(QLatin1String("%1.%2.%3 %4:%5:%6"))

Now it's resolved anyway. ;)

----------------------------------------
[Psapi.lib is not found]
One more build error when building qbs. You've got to manually edit either Makefile.Debug or Makefile.Release in src/shared/qbs/src/lib/corelib directory. Search for Psapi.lib with your favorite text editor, and you'll see this:
LIBS        =        -lglu32 -lopengl32 -lgdi32 -luser32 Psapi.lib -LD:/Components/Qt-5.4.2-MinGW32-5.1.0R0/qtbase/lib -lQt5Script -lQt5Gui -lQt5Xml -lQt5Core release\qbscore_resource_res.o 

Just change Psapi.lib to -lpsapi as shown below and it's done:
LIBS        =        -lglu32 -lopengl32 -lgdi32 -luser32 -lpsapi -LD:/Components/Qt-5.4.2-MinGW32-5.1.0R0/qtbase/lib -lQt5Script -lQt5Gui -lQt5Xml -lQt5Core release\qbscore_resource_res.o

It seems to be human error when copy-and-pasting VC nmake file to GNU makefile. Hey Trolls, WAKE UP!

----------------------------------------
[MIB_TCP_STATE is not declared]
If you're using Visual Studio, it's okay by just including iphlpapi.h in your source code, yet with MinGW you have to declare yourself. If you read the file tcpportsgatherer.cpp in src/lib/utils you'll see something like this:
// Missing declarations for MinGW 32.
#if __GNUC__ == 4 && (!defined(__MINGW64_VERSION_MAJOR) || __MINGW64_VERSION_MAJOR < 2)
typedef enum { } MIB_TCP_STATE;
#endif

Well, this seems to work only if you're using GCC version 4.X, not with 5.1.0. Just comment #if like this and you're done.
// Missing declarations for MinGW 32.
//#if __GNUC__ == 4 && (!defined(__MINGW64_VERSION_MAJOR) || __MINGW64_VERSION_MAJOR < 2)
typedef enum { } MIB_TCP_STATE;
//#endif

Now everything's done. Welcome to the world of Qt Creator 3.4.1! :)

Saturday, May 2, 2015

Windows에서 Qt Widget 프로그램을 cold start하면 시간이 얼마나 오래 걸릴까?

아마 다들 아시겠지만, Qt는 시스템 위젯을 사용하는 대신 전용 위젯을 따로 사용합니다. 덕분에 DLL들 크기가 꽤 큰 편입니다(Qt Core와 Qt GUI, 그리고 기본 플러그인 몇 개만 합쳐도 20MB를 넘어습니다). 뒤집어서 말하자면 프로그램이 cold start를 하면 디스크 읽기 때문에 상대적으로 시작이 느릴 수밖에 없습니다.
그런데, 느리다면 얼마나 느리려나요? 스톱워치로 재보니 한 4초쯤 되는 것 같긴 하던데, 프로그램 동작을 사람 눈대중으로 측정하는건 프로그래머가 할 짓은 아닌 것 같더군요. 해서 Qt Creator가 기본으로 제공하는 Qt Widget application 소스코드를 살짝 수정해봤습니다:

#include “widget.h”
#include <QApplication>
#include <QDateTime>
#include <QMessageBox>
int main(int argc, char *argv[])
{
  QDateTime start=QDateTime::currentDateTime();
  QApplication a(argc, argv);
  Widget w;
  w.show();
  QMessageBox::information(NULL, “Time”, QString::number(start.secsTo(QDateTime::currentDateTime())));
  return 0;
}

간단하죠?
이 프로그램을 2012년쯤에 산 펜티엄에서 돌려보니 한 2초 정도가 걸리더군요. Warm start(재시작)시에 걸린 시간은 1초 미만이라 별 의미는 없어 보입니다.
그런데 이런 쓸데없는 결과에 관심있으신 분이 있으시긴 하려나(……).

How slow is it to cold start a Qt Widget application on Windows?

As you know, Qt uses its own widgets rather than using one system provides. So its DLLs are large(at least 20MB or so for just Qt Core + Qt GUI + some default plugins) so that it takes a bit relatively long to cold start the application.

But how long? I took my stopwatch application on my phone and it says it’s about 4 seconds for just showing blank window, but it’s not fair to rely on human sensory as a programmer myself.

So I tweaked the default Qt Widget application provided by Qt Creator as follows:


#include “widget.h”
#include <QApplication>
#include <QDateTime>
#include <QMessageBox>

int main(int argc, char *argv[])
{
   QDateTime start=QDateTime::currentDateTime();
   QApplication a(argc, argv);
   Widget w;
   w.show();

   QMessageBox::information(NULL, “Time”, QString::number(start.secsTo(QDateTime::currentDateTime())));
   return 0;
}


SImple, huh?

I ran the application on my Pentium which I bought at 2012 or so and found out that it takes 2 seconds to create the widget and show. For warm start(restart), it takes less than 1 second so it’s meaningless.

Anyone interested in this result?

Thursday, April 16, 2015

One Year after Sinking of the MV Sewol

I’m sorry.I’m ashamed.I cannot raise my face.

The crybaby became father of a child, and soon becomes father of two children, but now he turns to the crybaby again.

My deepest apologies and regrets to the souls sacrificed in the sinking; children, fathers, mothers, brothers and sisters.

The present of the living is really a shame for those in heaven, yet I’ll step forward, however slow and hard it is.

Rest in peace.

세월호 참사 1주기입니다

미안합니다.
부끄럽습니다.
고개를 들 수가 없습니다.
어렸을 적 울보였던 아이는 이제 한 아이의 아버지이자 곧 두 아이의 아버지가 될 사람이 되었지만 오늘 또다시 울보 아이가 되어 눈물을 흘립니다.

세월호 참사로 희생된 영혼들. 아이들. 아버지들. 엄마들. 그리고 형과 누나와 동생들. 그 모든 분들께 그저 죄송스러울 따름입니다.

삶이 남은 자의 현재는 걸음을 멈추신 그대들이 하늘 위에서 내려다보기에 부끄러울 뿐입니다만, 아무리 느리더라도 어떻게든 한 발 한 발 앞으로 나가보겠습니다.

Thursday, November 27, 2014

Windows에서 libssh2를 MinGW로 빌드하기

cmake를 사용하는 libssh와는 달리, libssh2는 Windows에서 리눅스와 같은 환경에서 프로그램을 컴파일하기를 요구합니다-이를테면 MSYS같은게 필요하죠. 인터넷에 보면 libssh2를 빌드하는 많은 방법들이 있습니다만, 이들 중 상당수는 소스코드나 빌드파일을 어느 정도까지는 스스로 고쳐야 합니다.

그래서…… 평소 성향대로, 이 포스팅에서는 좀 반대로 가려고 합니다.소스코드에 손대지 않고 빌드하는 방법을 소개합니다.

준비물은 아래와 같습니다:

  1. MSYS
  2. MinGW-w64 기반 빌드가 필요합니다. 제가 테스트한 환경은 두 군데입니다: MinGW-builds 64bit-winthreads-SEH exception build와 TDM-GCC 64bi
  3. 물론, libssh2의 소스코드도 필요합니다. :P
빌드는 다음 순서대로 진행합니다:
  1. 소스코드 압축을 해제합니다.
  2. 가장 중요한 단계입니다: configure에서 OpenSSL과 OpenSSL이 의존하는 Win32 라이브러리를 강제로 참조하도록 합니다. 이를테면 이런 식입니다:
    ./configure –with-libs-prefix=“/d/Components/openssl” –with-libssl-prefix=“/d/Components/z"  LDFLAGS=”-L/d/Components/openssl/lib -lssl -l crypto -lgdi32 -lws2_32"
  3. [Optional] 만일 64비트로 빌드해야 한다면 –build=amd64를 LDFLAGS 이전에 삽입해주세요. 이런 요령으로 하시면 됩니다:
    ./configure –with-libs-prefix=“/d/Components/openssl” –with-libssl-prefix=“/d/Components/z” –build=amd64 LDFLAGS=“-L/d/Components/openssl/lib -lssl -l crypto -lgdi32 -lws2_32”
  4. make 실행후 모니터를 감상해주세요. :)
  5. 빌드 끝!
별건 아닙니다만, 이 글이 libssh2를 손수 빌드하려는 길잃은 양(……)들께 도움이 되셨으면 합니다.

Compiling libssh2 in Windows with MinGW-builds

Unlike libssh, which uses cmake, libssh2 forces you to use Linux-like environment even in Windows, which eventually makes you to install MSYS on your system. You can find many ways are to build libssh2 in Windows on the net, but most of them requires you to manually edit configuration files in some way.

OK, here goes the opposite…… You’ll NOT MAKE ANY CHANGES in the source code.

First, the requirements:

  1. MSYS
  2. MinGW-w64 based build. I used two variants: MinGW-builds 64bit-winthreads-SEH exception build, but TDM-GCC 64bit also works
  3. libssh2 source codes(of course! :P)
And the procedure:
  1. Decompress the source code.
  2. The most important step: force to add OpenSSL and Win32 libraries OpenSSL needs on configure step, something like this:
    ./configure –with-libs-prefix=“/d/Components/openssl” –with-libssl-prefix=“/d/Components/z” LDFLAGS=“-L/d/Components/openssl/lib -lssl -l crypto -lgdi32 -lws2_32”
  3. [Optional] If you’re building 64bit binary, dont forget to add –build=amd64 before LDFLAGS, like this:
    ./configure –with-libs-prefix=“/d/Components/openssl” –with-libssl-prefix=“/d/Components/z” –build=amd64 LDFLAGS=“-L/d/Components/openssl/lib -lssl -l crypto -lgdi32 -lws2_32”
  4. run make and enjoy. :)
  5. PROFIT!
Hope this helps some lost sheeps who want to build libssh2 in his/her own.