Search Here

Sunday, March 1, 2015

Running Win32 specific perl code in Linux

Hello Readers,

My wife and my son decided to give me a short "me" time. They are out of town for this whole month. I have planned to watch lots of movies and do some more experiments with perl + FFI.

As usual, I will update the experiment results here. Stay tuned.

WINE - Wine is an open source project. It aims to provide a Windows compatibility layer in Linux. So we can run the windows applications with in linux without going through Virtualization or any other tough route.

I must admit that I never really had any success of running useful windows application in my Fedora Linux via WINE. It appears that WINE can properly emulate core APIs but not fully the .NET kind of APIs, Also many guys out there using WINE for running Windows games in Linux Box. Games usually use the raw and core APIs of the OS.

I have a server grade computer with dual boot. One OS is obviously Fedora Linux 21 and other is Windows 7. I hate to login to Windows and my default login is set to Fedora Linux. Most of the time, I will finish my work in Linux OS itself and @Work I force to use Windows 7  laptop anyway. So I will defer my windows releated tasks to @Work laptop.

This week end, I was doing some experiments with perl and I had a situation to Win32 module. I can not do it Linux anyway because Win32 module, As name suggest needs windows OS to run. Win32 module exports a set of Windows OS APIs in to perl world.

In my other dual boot windows os, I have Active State perl v5.21 with all the perl development modules installed. But I don't like to shutdown and boot into Windows OS because of many days I did not login, It will complain about missing patches and older Virus Scanner. (Virus scanner!! another piece of crap, It will slow down the computer like anything and in Linux, We ask what is Virus? :))

Hmm... I have one more choice. In the Linux OS, I have KVM based windows XP virtual machine. I thought to start the Windows XP virtual machine and continue my perl experiments. After I logged into Windows XP virtual machine, I realize that, I do not have my perl development environment setup in it.

Like some people can not sleep in any beds and need their own bed and pillow, I need my development setup else my brain won't let me work. It keep points advantage of my development environment.

By the way, My perl development environment is,

Windows OS: Active Perl 5.20 +Eclipse IDE + EPIC Plugin + PPM for package management + gcc compiler + dmake

Linux OS: System default perl+ Eclipse IDE + EPIC plugin + CPAN for package management + gcc compiler + gmake

So, Windows XP Virtual Machine also not useful for now. I am too lazy to re setup my development environment in the Windows XP Virtual Machine.

Since I have the Dual Boot, I have also mounted my Windows drives (C:, E:) into my Linux via following entries in /etc/fstab file.


1
2
/dev/sda3 /mnt/WinD ntfs-3g rw,nosuid,nodev,relatime,user_id=0,group_id=0,default_permissions,allow_other 0 0
/dev/sda2 /mnt/WinC ntfs-3g rw,nosuid,nodev,relatime,user_id=0,group_id=0,default_permissions,allow_other 0 0

This allows me to access all Windows OS installed applications in /mnt/WinC. I finally thought to give a try with WINE.

Mission: Run Active Perl 5.20 which is installed in Windows OS in Linux using WINE.

First we need a WINE installed, I have installed long long back (May be since 2003, I have WINE in the Linux system without much usage because I am not a good computer games fan).


1
2
wine --version
wine-1.7.36 (Staging)

Next need to access the Active Perl installation in Windows OS. Using /etc/fstab file, Windows hard disk partition (NTFS) also mounted in Linux under /mnt folder.

Finally run the Active State perl,


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
$ cd /mnt/WinC/Perl/bin/
$ wine perl -v
fixme:winediag:start_process Wine Staging is a testing version containing experimental patches.
fixme:winediag:start_process Please report bugs at http://bugs.wine-staging.com (instead of winehq.org).
fixme:ole:CoInitializeSecurity ((nil),-1,(nil),(nil),1,2,(nil),0,(nil)) - stub!
err:ole:CoGetClassObject class {0000034b-0000-0000-c000-000000000046} not registered
err:ole:CoGetClassObject no class object {0000034b-0000-0000-c000-000000000046} could be created for context 0x1
fixme:ole:RemUnknown_QueryInterface No interface for iid {00000019-0000-0000-c000-000000000046}

This is perl 5, version 20, subversion 1 (v5.20.1) built for MSWin32-x86-multi-thread-64int
(with 1 registered patch, see perl -V for more detail)

Copyright 1987-2014, Larry Wall

Binary build 2000 [298557] provided by ActiveState http://www.ActiveState.com
Built Oct 15 2014 22:10:49

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl".  If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.
$ fixme:crypt:ProvStore_release Unimplemented flags 1
fixme:crypt:MemStore_release Unimplemented flags 1
fixme:msvcrt:__clean_type_info_names_internal (0x36e3f8) stub
fixme:msvcrt:__clean_type_info_names_internal (0x10046a20) stub


Hurrah, perl runs smoothly. But WINE spits more debug messages, Its quite distractive. Put off the WINE debug messages with WINEDEBUG environment variable.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
$ export WINEDEBUG=-all
$ wine perl -v

This is perl 5, version 20, subversion 1 (v5.20.1) built for MSWin32-x86-multi-thread-64int
(with 1 registered patch, see perl -V for more detail)

Copyright 1987-2014, Larry Wall

Binary build 2000 [298557] provided by ActiveState http://www.ActiveState.com
Built Oct 15 2014 22:10:49

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl".  If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.

Sweet :) Now, Perl runs as if I am running in Windows. But my main motive is to use the Win32 module, I still need to see WINE + Windows Perl can load the Win32 module.

Before that, I need to setup few environment variables for Windows Perl. Though WINE passes all the environment variables to running application due to OS difference few environment variables like PATH can not passed from Linux to Windows process running in WINE.

Special WINE environement variables needs to be exported via WINE Registry editor. It can be invoked via 'regedit' command OR if you are using KDE / GNOME desktop, You can get it in the start menu.



You can see that I have set the PATH variables with perl specific values. Z: is created by WINE, It is the Linux "/" folder.

Lets run Win32 code,


1
2
3
$ wine perl -e 'use Win32; print Win32::GetOSDisplayName()'

Windows XP Professional Service Pack 3


Awesome. Looks like WINE is emulating Windows XP.

This made me think, why perl can run peroperly under WINE?. Other commercial applications like Adobe Photoshop fails to run under WINE.

This is because Perl is super portable and it is mostly using libC (C runtime) core APIs (and modules will use other APIs, Depends on the Module) and perl as a language do not have may dynamic libs to link with. Basically, Perl is a low dependency language unlike MS Languages (.NETs).

No wonder perl is running in Over 100+ OS !!!!

After a decade, I made use of WINE and I will continue to use with Windows specific perl expriments.

Just now, Got a call from wife and son, Accusing me that, Even they are not in home, I finish blog in late sunday night and its obvious that they are not responsible for me to work in late nights!! True.



Hey, I am also doing experiments with GNotification APIs. Let me update in upcoming blog posts.


Bye Bye folks.

1 comment: