views:

1095

answers:

7

I been looking into Cygwin/Mingw/lcc and I liked to be able to compile perl native C extensions on my windows(preferably under cygwin) and then run them on Solaris and HP unix without any further fuss, is this possible?

This all stems from my original perl cross-platform question here.

A: 

No, this isn't possible at the binary level. There are so many differences at binary level between the various OSes and CPUs.

But what you can do is make the your C extensions source compatible so that it can compile to different platforms. C was designed as a "portable assembly language". As long as you stick with routines that are cross-platform, then they will usually work the same. You'll still need to test because there could be bugs that exists on particular platform.

Tommy Hui
A: 

This can't be done ... but is it that much of a hassle to recompile the code under Solaris or HP?

Jess
+3  A: 

Cross-compiler are very hard to setup and get working correctly.

Consider that (the people at) NetBSD have to put in a huge amount of work to get cross-compiling to work, and they're running the same OS, just different architectures.

You'd have to, at least, copy all the headers from the other OSs to Windows, and get a cross-compiler, linker etc for the target OS/architecture.

Also that may well not be possible - perl and shared libraries may be compiled with a native/non-gcc compiler which won't be available on Windows at all.

Douglas Leeder
Thanks, this is most enlightening answer so far, I realize it's not trivial, but it seems there are various fronts where this is been attempted, and I am hoping to hear more about them and maybe links to detailed explanations on how some were setup and using what compilers etc.
Ville M
+1  A: 

Compile on Windows then use Wine to run them on any *nix. It works well most of the time.

SumoRunner
Interesting, is there something you could point to on how to bundle the app with wine into 1 distributable binary to solaris/hpux? I can't install wine into common areas of my target box.
Ville M
No, I just tell the guys on the other end they have to have wine installed. Check out the wine installer. It's very probable that you could install it in any users home dir. Then you could construct an installer with both.
SumoRunner
+1  A: 

I agree with Douglas, that getting a cross compiler up and working is very hard to do. This is generally, your choice of last resort. If you are boot strapping, or making a binary for an embedded device, then often cross-compiling is your only option. You should be comfortable compiling your own gcc under Cygwin before considering cross compiling. To cross compile, you need to build a gcc to run under windows, but which will create binaries for your execution platform. Sample instructions for doing this can be found here.

Perhaps you are wanting to cross compile because you don't have root and/or can't compile on your target platform. For example, I had a hosting provider which ran Redhat Linux. I could run Perl CGI scripts, and associated modules, but I could not compile on the target machine, and an libraries I built had to exist in my own directory.

To solve this, I could have attempted to cross compile for my target platform, but instead, I decided to setup a similar host inside a VM on Windows. From within Cygwin, you can create a script which ssh's into your VM, copies your source, and does a full configure/build. The last step was to deploy the binary artifact onto my hosted system.

I've successfully had both Solaris 10 and Open Solaris running within a VM on Windows. Unfortunately, you might have a harder time running HPUX under a VM.

brianegge
+1  A: 

Why don't you have a read up on "Grand Unified Builder" (http://lilypond.org/gub/ and http://valentin.villenave.info/The-LilyPond-Report-11 (section #4))

I don't know how it works, but GUB allows the Lilypond developers to compile for about 11 platforms on a linux box.

masher
Excellent Find.
1.01pm
+1  A: 

(This is a very old question, but missing some useful info -- I've personally done this for Solaris (SPARC & x86), AIX, HP-UX and Linux (x86, x64).)

  • Getting C++ cross-compiled is much harder than straight C.

  • HP-UX 32-bit PA-RISC not is supported because it uses SOM format instead of ELF and binutils doesn't (and likely won't ever) support SOM. In other words, you can only cross-compile 64-bit PA-RISC. (Requires PA-RISC 2.0 chip.)

  • I would go with mingw instead of cygwin, if you can. Cygwin introduces a lot of file permission headaches and cygwin1.dll dependencies that can be troublesome.

  • Start with the crosstools script, but be prepared to spend a lot of time on this.

  • Try with the very latest gcc/binutuils first, but if you can't overcome problems try dropping back to older packages. E.g. for Power3 (AIX) gcc 4.x series cross compiler generates bad code, 3.x is fine.

  • When copying native libs and headers make sure you are copying from the oldest machine you're likely to run on. Copying a new libc means your code won't run on any machine with an older libc.

  • When copying native libs and headers you probably want 'tar -h' to turn symlinks into actual files, also watch that on Solaris some requisite crt object files are buried in a cc directory, not under /usr/lib

Nathan Kidd