Boston Linux & Unix (BLU) Home | Calendar | Mail Lists | List Archives | Desktop SIG | Hardware Hacking SIG
Wiki | Flickr | PicasaWeb | Video | Maps & Directions | Installfests | Keysignings
Linux Cafe | Meeting Notes | Blog | Linux Links | Bling | About BLU

BLU Discuss list archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

32-bit and 64-bit (was something else...)



And to really blow your mind about cross-compiling 32-bit from 64-bit...



khermans at khermans-laptop:~/projects$ aptitude search mingw
i   mingw32                         - Minimalist GNU win32 (cross) compiler
i   mingw32-binutils                - Minimalist GNU win32 (cross) binutils
i   mingw32-runtime                 - Minimalist GNU win32 (cross) runtime
khermans at khermans-laptop:~/projects$ wine --version
wine-0.9.30
khermans at khermans-laptop:~/projects$ emacs -nw hello.c
khermans at khermans-laptop:~/projects$ cat hello.c
/*
* Author: Kristian Hermansen <kristian.hermansen-Re5JQEeQqe8AvxtiuMwx3w at public.gmane.org>
* For demonstration purposes of cross-compilation...
*/

/* general includes */
#include <stdio.h>

/* platform-secific includes  */
#ifdef _WIN32
#include <windows.h>
#else
#include <unistd.h>
#endif

int main() {
  int wait = 5;
  printf("hello!\n");
#ifdef _WIN32
  Sleep(wait*1000);
#else
sleep(wait);
#endif
  printf("goodbye!\n");
  return 0;
}
khermans at khermans-laptop:~/projects$ gcc -std=c99 -Wall -o hello hello.c
khermans at khermans-laptop:~/projects$ file hello
hello: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), for 
GNU/Linux 2.6.0, dynamically linked (uses shared libs), not stripped
khermans at khermans-laptop:~/projects$ time ./hello
hello!
goodbye!

real    0m5.005s
user    0m0.000s
sys     0m0.004s
khermans at khermans-laptop:~/projects$ i586-mingw32msvc-gcc -std=c99
-Wall -o hello.exe hello.c
khermans at khermans-laptop:~/projects$ file hello.exe
hello.exe: MS-DOS executable PE  for MS Windows (console) Intel 80386 32-bit
khermans at khermans-laptop:~/projects$ time wine hello.exe
hello!
goodbye!

real    0m5.295s
user    0m0.004s
sys     0m0.012s
khermans at khermans-laptop:~/projects$ ls -lsh
total 212K
12K -rwxr-xr-x 1 khermans khermans 9.1K 2007-04-08 12:54 hello
4.0K -rw-r--r-- 1 khermans khermans  418 2007-04-08 12:53 hello.c
196K -rwxr-xr-x 1 khermans khermans 194K 2007-04-08 12:54 hello.exe




I have posted this once before a while ago, but seems appropriate to 
show it again...
-- 
Kristian Hermansen

-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.







BLU is a member of BostonUserGroups
BLU is a member of BostonUserGroups
We also thank MIT for the use of their facilities.

Valid HTML 4.01! Valid CSS!



Boston Linux & Unix / webmaster@blu.org