Portable process killer with GLib

Since Windows API (and MinGW) doesn’t have fork() / exec() calls, I love GLib’s g_spawn_sync() and its friends to spawn child process in portable (and Unix like) way.
However, GLib provides nothing like kill() to terminate processes. So I have to find a way to kill a process by myself. As a portable process identifier, g_spawn_sync() gives GPid. This is defined in GLIB_PREFIX/lib/glib-2.0/include/glibconfig.h as:
– Unix: typedef int GPid;
– Win32: typedef void * GPid;
The one for Unix is equal to pid, and the one for Win32 is equal to HANDLE (defined in winnt.h, as “typedef void *HANDLE;”).
So, a process launched by g_spawn_sync() may be killed by:
kill(GPid p, 15);
TerminateProcess(GPid p, UINT return_code);
MSDN document says “The state of global data maintained by dynamic-link libraries (DLLs) may be compromised if TerminateProcess is used rather than ExitProcess.”
Source code of a Gimp plugin gives a good example, but I haven’t tested it yet. Hope this works…

Boost その後

Crosscompiling Boost C++ library with MinGW libraries (on MacOS X): updated.
I have:
– MinGW toolkit (gcc and binutils) and libraries in /Users/yasu/mingw/
– GTK and related libraries including ZLIB and BZ2LIB in /Users/yasu/mingw/GTK/
– bjam for MacOS X, installed by MacPorts
I need:
– boost-regex
– boost-iostreams
– boost-filesystem
And here’s how I got them:
% cd boost_1_35_0
% vi tools/build/v2
using gcc : 4.2 : i386-pc-mingw32-g++-4.2.1 : <compileflags>-I/Users/yasu/mingw/GTK/include <linkflags>-L/Users/yasu/mingw/GTK/lib ;
% bjam -sTOOLS=gcc -sGXX=g++ –with-regex –with-filesystem –with-iostreams install –prefix=/Users/yasu/mingw –build-type=complete
Mmm, bjam syntax is something cool, but difficult for me…
And just one more thing, we need to run runlib prior to use the libraries. For example:
% i386-pc-mingw32-ranlib libboost_regex-mgw42.a

Boost を cross compile

bjam は、build する環境に入っているもので OK.
使う cross g++ なところにはパスを通しておく。
で、boost を展開したディレクトリの下の、tools/build/v2/user-config.jam に
using gcc : 4.2 : i386-pc-mingw32-g++-4.2.1 ;
と書いてみた。んでもって、
% bjam -sTOOLS=”gcc” –prefix=”/Users/yasu/mingw” –sGXX=”i386-pc-mingw32-g++-4.2.1″ install
でとりあえずコンパイルできた。
% file ~/mingw/lib/libboost_graph-mgw42-mt-1_35.dylib
/Users/yasu/mingw/lib/libboost_graph-mgw42-mt-1_35.dylib: MS-DOS executable PE for MS Windows (DLL) (console) Intel 80386 32-bit
とかなっており、Windows の DLL の拡張子が .dylib になっていたりして、なかなか不思議な感じだが、ま、そういうものでしょう。
作ったバイナリが動くかは、まだ試してない。