面白いかも。
リアルアンリアル 高速配信Webサーバシステムをオープンソース化
いろいろやってみよう
systems.h
#include <io.h> #include <windows.h> #define UNLOCK_FILE(dbf) { \ HANDLE h = (HANDLE)_get_osfhandle(dbf->desc); \ if (INVALID_HANDLE_VALUE != h) { \ UnlockFile(h, 0, 0, (DWORD)-1, (DWORD)-1); \ } \ } #define READLOCK_FILE(dbf) { \ HANDLE h = (HANDLE)_get_osfhandle(dbf->desc); \ if (INVALID_HANDLE_VALUE == h) { \ lock_val = -1; \ } else { \ OVERLAPPED over; \ ZeroMemory(&over, sizeof(over)); \ DWORD flags = LOCKFILE_FAIL_IMMEDIATELY; \ if (!LockFileEx(h, flags, 0, (DWORD)-1, (DWORD)-1, &over)) { \ lock_val = -1; \ } else { \ lock_val = 0; \ } \ } \ } #define WRITELOCK_FILE(dbf) { \ HANDLE h = (HANDLE)_get_osfhandle(dbf->desc); \ if (INVALID_HANDLE_VALUE == h) { \ lock_val = -1; \ } else { \ OVERLAPPED over; \ ZeroMemory(&over, sizeof(over)); \ DWORD flags = LOCKFILE_FAIL_IMMEDIATELY | LOCKFILE_EXCLUSIVE_LOCK; \ if (!LockFileEx(h, flags, 0, (DWORD)-1, (DWORD)-1, &over)) { \ lock_val = -1; \ } else { \ lock_val = 0; \ } \ } \ }
$ g++ -static -shared -o hello.dll hello.cc world.cc -Wl,--out-implib,libhello.a
$ g++ -c hello.cc $ g++ -c world.cc $ g++ -mdll -o hello.dll.tmp -Wl,--base-file,hello.dll.base hello.o world.o $ dlltool -l libhello.a --dllname hello.dll --base-file hello.dll.base --output-exp hello.dll.exp --def hello.def $ g++ -mdll -o hello.dll -Wl,hello.dll.exp -static hello.o world.o
$ x86_64-w64-mingw32-g++ Hello.cpp -static
コンソール
$ g++ --version g++.exe (GCC) 4.4.0 Copyright (C) 2009 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ ls -l Hello.cpp -rw-r--r-- 1 takumakei Administrators 97 Mar 11 13:00 Hello.cpp $ cat Hello.cpp #includeint main() { std::cout << "Hello world" << std::endl; return 0; } $ g++ -o Hello -O3 Hello.cpp -static-libgcc $ ls -l Hello.exe -rwxr-xr-x 1 takumakei Administrators 3862265 Mar 11 13:56 Hello.exe* $ strip Hello.exe $ ls -l Hello.exe -rwxr-xr-x 1 takumakei Administrators 496142 Mar 11 13:56 Hello.exe* $ ./Hello.exe Hello world
ウィンドウ
$ ls -l HelloW.cpp -rw-r--r-- 1 JP10007 Administrators 150 Mar 11 13:34 HelloW.cpp $ cat HelloW.cpp #includeint WINAPI WinMain(HINSTANCE, HINSTANCE, LPTSTR, int) { MessageBox(NULL, "Hello world", "HelloW", MB_OK); return 0; } $ g++ -o HelloW.exe -O3 HelloW.cpp -static-libgcc -mwindows $ ls -l HelloW.exe -rwxr-xr-x 1 JP10007 Administrators 334435 Mar 11 13:59 HelloW.exe* $ strip HelloW.exe $ ls -l HelloW.exe -rwxr-xr-x 1 JP10007 Administrators 75790 Mar 11 13:59 HelloW.exe*
a/Main.java
package a; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; public class Main { public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setText("HelloSWT"); shell.setSize(480, 320); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); } }
コンパイル
gcj -fjni -c -o swt.o swt.jar gcj -mwindows -o Hello --classpath=swt.jar --main=a.Main a/Main.java swt.o