Qt5 (5.11.2 기준) MySQL 함께 빌드

1. MySQL 홈페이지에서 MySQL 서버 다운로드
https://dev.mysql.com/downloads/windows/installer/8.0.html
Connector/C++은 Qt의 SQL 플러그인에서 지원안하며, Connector/C는 서버 패키지에 포함되어있다… 다른건 다 개별로 배포하면서 C 라이브러리는 서버 패키지에서 설치하도록 변경되었는지는 이유를 모르겠다.

2. Connector/C 설치
Custom 설치로 선택 후 아래와같이 트리뷰를 펼치면 x64, x86 두가지 아키텍처가 있으며 이 중 한가지만 설치가능하다(…)

필요한 아키텍처를 선탁하여 설치하면 각각 아래 경로에 설치된다. (8버전 기준)
x86: C:\Program Files (x86)\MySQL\MySQL Connector C 6.1
x64: C:\Program Files\MySQL\MySQL Connector C 6.1
폴더가 서로 다른데 왜 둘 다 설치 못하는지는 미지수.

3. 필수 유틸 설치
Python 2.7버전, 그리고 펄을 다운받아 설치한다. 설치 후 콘솔에서 python, perl 실행해보고 INCLUDE, LIB 변수 값 수정.

4. 환경변수 설정
명령 도구모음 x86 또는 x64를 실행한 후 아래와같이 실행하여 환경변수에 추가.
x86:
set INCLUDE=%INCLUDE%;C:\Program Files (x86)\MySQL\MySQL Connector C 6.1\include
set LIB=%LIB%;C:\Program Files (x86)\MySQL\MySQL Connector C 6.1\lib

x64:
set INCLUDE=%INCLUDE%;C:\Program Files\MySQL\MySQL Connector C 6.1\include
set LIB=%LIB%;C:\Program Files\MySQL\MySQL Connector C 6.1\lib

5. 빌드 준비
configure -opensource -confirm-license -prefix D:\OpenSource\Qt5.11.2.x86 -nomake examples -nomake tests -opengl dynamic -mediaplayer-backend wmf -force-debug-info
소스를 압축푼 후 해당 경로에서 위와같이 입력한다.
D:\OpenSource
– Qt5.11.2.x86.build
– qt-everywhere-src-5.11.2
이와같은 구조라면 ..\qt-everywhere-src-5.11.2\configure -opensource…. 와 같이 입력한다.
x86과 x64 타겟 둘 다 빌드하려면 이렇게 쉐도우빌드하는게 좋다. (이미 빌드, configure 완료 된 설정과 충돌이 발생하지 않기때문.) 또한 prefix를 지정하면 빌드 완료 후 nmake install하여 헤더와 바이너리파일을 소스와 오브젝트 파일 따로 둘 수 있다.

아래는 MySQL을 포함 한 configure 결과내용.

Configure summary:

Build type: win32-msvc (x86_64, CPU features: sse sse2)
Configuration: sse2 aesni sse3 ssse3 sse4_1 sse4_2 avx avx2 avx512f avx512bw avx512cd avx512dq avx512er avx512ifma avx512pf avx512vbmi avx512vl compile_examples f16c force_debug_info largefile precompile_header rdrnd shani x86SimdAlways shared debug_and_release release debug build_all c++11 c++14 c++1z concurrent dbus no-pkg-config release_tools stl
Build options:
  Mode ................................... debug and release (with debug info); default link: debug; optimized tools

... 중략 ...

Qt Gui:
  Accessibility .......................... yes
  FreeType ............................... yes
    Using system FreeType ................ no
  HarfBuzz ............................... yes
    Using system HarfBuzz ................ no
  Fontconfig ............................. no
  Image formats:
    GIF .................................. yes
    ICO .................................. yes
    JPEG ................................. yes
      Using system libjpeg ............... no
    PNG .................................. yes
      Using system libpng ................ no
  EGL .................................... yes
  OpenVG ................................. no
  OpenGL:
    ANGLE ................................ yes
    Combined ANGLE Library ............... no
    Desktop OpenGL ....................... no
    Dynamic OpenGL ....................... yes
    OpenGL ES 2.0 ........................ no
    OpenGL ES 3.0 ........................ no
    OpenGL ES 3.1 ........................ no
    OpenGL ES 3.2 ........................ no
  Vulkan ................................. no
  Session Management ..................... yes

... 중략 ...

Qt Sql:
  DB2 (IBM) .............................. no
  InterBase .............................. no
  MySql .................................. yes
  OCI (Oracle) ........................... no
  ODBC ................................... yes
  PostgreSQL ............................. no
  SQLite2 ................................ no
  SQLite ................................. yes
    Using system provided SQLite ......... no
  TDS (Sybase) ........................... no

... 중략 ...

Qt Multimedia:
  ALSA ................................... no
  GStreamer 1.0 .......................... no
  GStreamer 0.10 ......................... no
  Video for Linux ........................ no
  OpenAL ................................. no
  PulseAudio ............................. no
  Resource Policy (libresourceqt5) ....... no
  Windows Audio Services ................. yes
  DirectShow ............................. yes
  Windows Media Foundation ............... yes
  Media player backend ................... Windows Media Foundation
Qt WebEngine:
  Embedded build ......................... no
  Pepper Plugins ......................... yes
  Printing and PDF ....................... yes
  Proprietary Codecs ..................... no
  Spellchecker ........................... yes
  Native Spellchecker .................... no
  WebRTC ................................. yes
  Use System Ninja ....................... no
  Geolocation ............................ yes
  Use v8 snapshot ........................ yes

Note: No wayland-egl support detected. Cross-toolkit compatibility disabled.

Qt is now configured for building. Just run 'nmake'.
Once everything is built, you must run 'nmake install'.
Qt will be installed into 'D:\OpenSource\Qt5.11.2.x64'.

Prior to reconfiguration, make sure you remove any leftovers from
the previous build.

만약 MySQL 부분이 활성화 안되어 환경설정 후 그 부분만 다시 체크되도록 하려면 config.cache 파일을 메모장에서 열어 아래와 같이 cache.mysql로 시작하는 라인을 전부 지우고 다시 configure하면 된다.

cache.mysql._KEYS_ = result msgs source sources.5.libs sources.5.includedir sources.5.cflags sources.5.version sources.5.export
cache.mysql.result = true
cache.mysql.msgs = "Trying source 0 (type mysqlConfig) of library mysql ..." "mysql_config not found." "  => source produced no result." "Trying source 1 (type mysqlConfig) of library mysql ..." "mysql_config not found." "  => source produced no result." "Trying source 2 (type mysqlConfig) of library mysql ..." "mysql_config not found." "  => source produced no result." "Trying source 3 (type mysqlConfig) of library mysql ..." "mysql_config not found." "  => source produced no result." "Trying source 4 (type inline) of library mysql ..." "  => source failed condition \'!config.win32\'." "Trying source 5 (type inline) of library mysql ..." "+ cd /d D:\\OpenSource\\Qt5.11.2.x86.build\\config.tests\\mysql && D:\\OpenSource\\Qt5.11.2.x86.build\\qtbase\\bin\\qmake.exe \"CONFIG -= qt debug_and_release app_bundle lib_bundle\" \"CONFIG += shared warn_off console single_arch\" \"LIBS += -llibmysql\" D:/OpenSource/Qt5.11.2.x86.build/config.tests/mysql" "+ cd /d D:\\OpenSource\\Qt5.11.2.x86.build\\config.tests\\mysql && set MAKEFLAGS=& nmake" "> Microsoft(R) Program Maintenance Utility ���� 14.16.27024.1" "> Copyright (c) Microsoft Corporation. All rights reserved." "> $$escape_expand(\\t)cl -c -nologo -Zc:wchar_t -FS -Zc:rvalueCast -Zc:inline -Zc:strictStrings -Zc:throwingNew -Zc:referenceBinding -Zc:__cplusplus -Zi -MDd -W0 -EHsc /Fdmysql.vc.pdb -DUNICODE -D_UNICODE -DWIN32 -D_ENABLE_EXTENDED_ALIGNED_STORAGE -I. -ID:\\OpenSource\\qt-everywhere-src-5.11.2\\qtbase\\mkspecs\\win32-msvc -Fo @C:\\Users\\star\\AppData\\Local\\Temp\\nm8248.tmp" "> main.cpp" "> $$escape_expand(\\t)link /NOLOGO /DYNAMICBASE /NXCOMPAT /DEBUG /SUBSYSTEM:CONSOLE \"/MANIFESTDEPENDENCY:type=\'win32\' name=\'Microsoft.Windows.Common-Controls\' version=\'6.0.0.0\' publicKeyToken=\'6595b64144ccf1df\' language=\'*\' processorArchitecture=\'*\'\" /MANIFEST:embed /OUT:mysql.exe @C:\\Users\\star\\AppData\\Local\\Temp\\nm869F.tmp" " => source accepted."
cache.mysql.source = 5
cache.mysql.sources.5.libs = -llibmysql
cache.mysql.sources.5.includedir = 
cache.mysql.sources.5.cflags = 
cache.mysql.sources.5.version = 
cache.mysql.sources.5.export = 

6. 빌드
qt에서 제공하는 jom을 쓴다면 jom, 아니라면 nmake 명령으로 빌드. 주위할 점으로 시스템 로케일을 영어(미국)으로 하는게 좋다. 웹킷은 경고도 에러로 처리하고 이 편이 훨씬 깔끔하게 한번에 빌드된다.

7. 기타
귀차니즘 덕분에 이정도로 마무리. 더 자세한 내용은 이곳 참조.