What I use to build most binaries here? MSYS+MinGW, yet I rarely post something specific about it...
Tonight I cleaned up my toolchains and dump everything into one kind of integrated package, a porting kit I would say. Formerly it just a small set of MSYS and TDM's GCC, slowly it grew up by adding some tools for packaging/deployment. Recently I even build my own GCC (i686-w64-mingw32 multilib) based on 4.6.2 version due to TDM's GCC multilib have default 64bit target which not so parallel with the spirit of 32-bitness of this blog fu fu fu... so I compile GCC multilib that do the opposite (32-bit by default and optionally targeting 64-bit). Furthermore as with MinGW-W64 get matured but not fully compatible with MinGW32 I made alternate GCC mimicking official MinGW32 which migrated to dwarf2 based exceptions and switch between them as needed.
Tips for complete noob (to be continued..)
- to install just run the self extracting installer, it will extract to [current folder]\MSYS, once finished run msys.bat (it is portable installation)
- to see compilers and gdb manual use "info" or "man"
- in msys "/" is the [current folder]\MSYS above and all driveletters mounted after "/" e.g "D:" = "/d", therefor "/" also equal to "/[current driveletter]/[path]/MSYS" see details by type "mount"
- to compile a source package usually we "cd"ing (change directory) into the root of source's folder then type "configure" and then "make"
- the recommended way to compile however is to create a "build folder" outside (better one) or inside source folder then from "build folder" type
- to cleanup compilation files use
make clean, for total cleanup use
make distclean(need re-configure)
- to install use
make installwhich by default goes to /local folder
- to change default install location use --prefix="[install folder]" to configure line
- we can pause operations in msys by drawing mouse into console (like when we select area), I often do this when my CPU rang overheated during compile and to continue right click on the console. This also equal to copying the content of selected area.
- to redirect compilation messages into file, we can use the usual ">logs.txt" way
- to force verbose compilation when it was suppressed use
- there is "cp" -> "copy", "rm" -> "del", "mv" -> "ren", or we can use
alias copy=cpif that bothersome
- like most console program we may switch into "DOS" mode by typing cmd, there all environment variables will automatically converted to windows style once we're done type exit.
- path auto-completion only works in unix style e.g /path/path/file
- when unix style path feed to non msys program it will be converted to windows path style albeit with "/" instead of "\" separator
- msys is semi-case-sensitive environment where path and file are case-insensitive and most of the rest including variable name are case-sensitive
- to define global variable e.g compiler flags use
- in windows arguments can be represented as %1 %2 %3... similarly in msys $1 $2 $3... and for %errorlevel% in msys this is most likely $?, too bad no %~[x][varname] expansion there
- unlike windows, most command options are begin with "--" or "-" instead of "/" e.g <code>configure --help
- if we get source snapshot tarball with no configure available use "autogen.sh"
- if source packages do not use autotools (configure), try look for makefile or makefile.gcc file then use
make -f [makefile]to compile. Other possibilities SConstruct (scons), CMakeLists.txt (cmake)
- to define compiler's flags while overriding global compiler's flags, feed the configure line e.g
- to change default libtool's dll naming we may modify soname_spec variable (usually inside libtool file after configure done)
- to build an orphaned library (a library required by only a library) as static lib, use
--enable-static --disable-sharedin configure line
- when throwing python in compilation inside msys, things will get very ugly: path will be mixed between "\\", "\" and "/" separator and most likely fail the process. The easy fix is to actually edit bundled python's ntpath.py and change with sep="/"
- when compiling 32bit binaries I suggest use mingw32 simply because either some packages may need adjustment for mingw-w64 or mingw-w64 is not too similar to mingw32
- according to mingw project, dwarf2 is the future and it's not recommended to mix between mingw32, mingw-w64, dwarf2 and sjlj even if it's possible, so be warned
- a library usually has .a(static lib) or .dll.a(impor lib) extension, although this is just naming convention gcc will prefer .dll.a (dynamic linking) over .a file by default. More precisely: libfoo.dll.a, foo.dll.a, libfoo.a and at last foo.lib.
- if we get undefined error during linking and we find the missing function in library xyz then we can:
re-configure by append LIBS=-lxyz to configure line or
edit suspected makefile and add -lxyz to LIBS declaration or
issue manual make command with the missing -lxyz
- if we still get undefined error maybe we're linking to incorrect static library? maybe we forgot to define something like -DSTATIC_LIBXYZ? or sort of declspec stuff in the suspected lib
- to generate smallest executable (for .exe only) use
LDFLAGS="-Wl,-s "but lto (gimple) isn't matured yet and you may encountered ICE