MinGW
MinGW는 마이크로소프트 윈도로 포팅한 GNU 소프트웨어 도구 모음이다. mingw32로도 알려져 있다.
MinGW는 윈도 API를 구현할 수 있는 헤더 파일들을 가지고 있으며 이로써 개발자들이 "자유롭게 쓸 수 있는" 컴파일러인 GCC를 사용할 수 있다. 시그윈 포팅을 사용할 경우 컴파일한 프로그램 결과물이 유닉스 계통의 기능을 가상으로 구현하는 런타임에 의존하는 반면, MinGW의 경우 이러한 기능에 의존하지 않고 마이크로소프트 윈도 기반 프로그램들을 만들 수 있다.
이 MinGW 프로젝트는 두 개의 기본 꾸러미를 관리하고 배포한다. 첫째로는 포팅된 GCC 컴파일러들은 윈도 명령 줄에서, 아니면 IDE에 통합된 채로 쓸 수 있다. 아니면 둘째로는 MSYS(minimal system의 약자)를 쓸 수도 있는데, 이것은 가벼운 유닉스 계통의 셸 환경을 제공한다. 이러한 환경은 rxvt와 autoconf 스크립트들을 실행하는 데에 충분한 POSIX 도구들이 집약되어 있다.
두 개의 꾸러미들은 원래 시그윈 일부의 forks였으며 forks는 네이티브 윈도 기능 덕에 더 포괄적인 유닉스 계통의 지원을 제공한다. 두 개의 꾸러미들은 자유 소프트웨어이다. Win32 헤더 파일들은 공용 도메인에 공개된다. 반면 GNU에서 포팅되는 프로그램들은 GNU 일반 공중 사용 허가서 하에서 사용할 수 있다. 완전한 MSYS 꾸러미와 개별 MinGW GNU 유틸리티들의 바이너리 파일들은 MinGW 사이트에서 내려 받을 수 있다.
Categories
- MinGW:Windres: MS resource compiler
MinGW 설치방법
mingw-get을 사용하여 mingw와 관련된 다른 패키지를 다운받을 수 있다. 만약 GDB를 설치하고싶을 경우 아래와 같이 입력하면 된다.
윈도우 프로그래밍시에 콘솔(Console)창 없애는 방법
링커 옵션에 -mwindows
를 추가하면 된다.
다른 플랫폼의 경우 C++:Troubleshooting#Hide terminal window를 참조.
mingw10.dll 의존성 제거하기
옵션으로 -mthreads
를 주게 되면 dependency가 발생한다. -mthreads
옵션은 __gthread_key_create가 필요한 경우에만 의미가 있다.
The gcc manual says:
-mthreads
Support thread-safe exception handling on Mingw32. Code that relies on thread-safe exception handling must compile and link all code with the -mthreads option. When compiling,
-mthreads defines -D_MT; when linking, it links in a special thread helper library -lmingwthrd which cleans up per thread exception handling data.
Mingw-w64/w32 specifics
When running an autotools configure script, these options will come in handy:
- for a 64-bit build:
--host=x86_64-w64-mingw32
- for a 32-bit build:
--host=i686-w64-mingw32
If you are experiencing problems, you can also set --build
to the same value. Some configure scripts also use --target
instead of --host
. Use configure --help
to get all possible options.
--host
, --target
, and --build
explained
--host
specifies on what platform/architecture the compiled program is going to run. --target
specifies the platform/architecture that the program should be configured for and will be compiled for. This should only have effect when building cross-compilers. --build
specifies the platform/architecture the build process is going to be executed.
DLLs dragging in LIBSTDC++-6.DLL and LIBGCC_S_DW2-1.DLL?
MinGW로 컴파일된 실행파일을 실행할 경우 libgcc_s_dw2-1.dll, libstdc++-6.dll 종속성이 발생된다. 해당 종속성을 제거하기 위해 정적링크를 진행해야 한다. 아래와 같은 LINK FLAG를 추가해야 한다.
-
-static-libgcc
-
-static-libstdc++
How to create import library
The import library created by the --out-implib
linker option.
MinGW Preprocessor
- Pre-defined C/C++ Compiler Macros
- Stackoverflow: How can I detect g++ and mingw in c++ preprocessor?
MinGW는 Preprocessor에서 아래와 같이 확인할 수 있다.
MSVC and MinGW DLLs
gcc -shared -o testdll.dll testdll.c -Wl,--output-def,testdll.def,--out-implib,libtestdll.a
lib /machine:i386 /def:testdll.def
cl testmain.c testdll.lib
cl /LD testdll.c
gcc -o testmain testmain.c testdll.lib
Cross Compile
$ sudo apt-get install mingw-w64
## C
$ i686-w64-mingw32-gcc hello.c -o hello32.exe # 32-bit
$ x86_64-w64-mingw32-gcc hello.c -o hello64.exe # 64-bit
## C++
$ i686-w64-mingw32-g++ hello.cc -o hello32.exe # 32-bit
$ x86_64-w64-mingw32-g++ hello.cc -o hello64.exe # 64-bit
Tcltk Blog - Mingw Tutorials
Tcltk 블로그의 Mingw관련 자료.
- http://blog.tcltk.co.kr/?cat=5 - Tcltk_blog_mingw01.pdf
- http://blog.tcltk.co.kr/?cat=5&paged=2 - Tcltk_blog_mingw02.pdf
- http://blog.tcltk.co.kr/?cat=5&paged=3 - Tcltk_blog_mingw03.pdf
- http://blog.tcltk.co.kr/?cat=5&paged=4 - Tcltk_blog_mingw04.pdf
- http://blog.tcltk.co.kr/?cat=5&paged=5 - Tcltk_blog_mingw05.pdf
- http://blog.tcltk.co.kr/?cat=5&paged=6 - Tcltk_blog_mingw06.pdf
- http://blog.tcltk.co.kr/?cat=5&paged=7 - Tcltk_blog_mingw07.pdf
- http://blog.tcltk.co.kr/?cat=5&paged=8 - Tcltk_blog_mingw08.pdf
- http://blog.tcltk.co.kr/?cat=5&paged=9 - Tcltk_blog_mingw09.pdf
- http://blog.tcltk.co.kr/?cat=5&paged=10 - Tcltk_blog_mingw10.pdf
- http://blog.tcltk.co.kr/?cat=5&paged=11 - Tcltk_blog_mingw11.pdf
- http://blog.tcltk.co.kr/?cat=5&paged=12 - Tcltk_blog_mingw12.pdf
- http://blog.tcltk.co.kr/?cat=5&paged=13 - Tcltk_blog_mingw13.pdf
- http://blog.tcltk.co.kr/?cat=5&paged=14 - Tcltk_blog_mingw14.pdf
- http://blog.tcltk.co.kr/?cat=5&paged=15 - Tcltk_blog_mingw15.pdf
Troubleshooting
MSYS및 MinGW사용중 발생할 수 있는 문제점 및 해결 방법에 대하여 정리한다.
directory path
디렉터리 경로에 공백입력을 가급적 삼가해야 한다.
MinGW may have problems with paths containing spaces, and if not, usually other programs used with MinGW will experience problems with such paths. Thus, we strongly recommend that you do not install MinGW in any location with spaces in the path name reference. You should avoid installing into any directory or subdirectory having names like "Program Files" or "My Documents", etc. |
See also
Favorite site
Libraries
- Mingw 라이브러리 만들어보기
- the MinGW + MSYS environment
- MinGW/MSYS development environment Part 3: Building GTK+
- [추천] MSVC and MinGW DLLs
MinGW-w64 libraries
- MinGW-w64 설치하기
- MinGW-w64 library들 설치하기-0 : zlib, libiconv, gettext, jpeg 3
- MinGW-w64 library들 설치하기-1 : png, freeGlut, tiff, PROJ.4, geotiff, lzo2, freetype, libxml2 4
- MinGW-w64 library들 설치하기-2 : GLEW, plib, OpenAL, OpenSceneGraph 5
- MinGW-w64로 boost 빌드하기 6