Operating System - HP-UX
1829590 Members
7346 Online
109992 Solutions
New Discussion

Re: using CC to produce windows executables

 
Colin Rowat
Occasional Advisor

using CC to produce windows executables

Dear list members,

I am using cc under HP-UX 11.11.04 without a problem. I would like, however, to produce executables for windows machines. Is this possible? man cc didn't reveal to me a way of doing this but I do have a sense that I've seen a switch to do this somewhere - perhaps a different compiler?

(As my c code links to libraries only on the unix machine, I don't want to compile in windows.)

Thoughts very much appreciated.

Thank you,

Colin
12 REPLIES 12
Brian Bergstrand
Honored Contributor

Re: using CC to produce windows executables

No, this is not possbile. First off, and most important, UX doesn't contain the windows dll's to link with, and secondly I don't belive HP's compiler is a cross-compiler -- i.e. it only builds PA-RISC binaries.

What you can do is download gcc for windows and then (if you're code is POSIX compliant and you've promised your first child to Bill Gates) you should be able to move your UX code to windows and compile it with GCC.

HTH.
Brian Bergstrand
Honored Contributor

Re: using CC to produce windows executables

Oops, forgot about Itanium. So HP's compiler probably can target that. Of course, that doesn't do anything for IA-32 windows binaries.
Colin Rowat
Occasional Advisor

Re: using CC to produce windows executables

Thanks Brian - that does help.

On the gcc route, can compiling under windows link in the unix libraries? My guess is that I couldn't go straight from .c to .exe with gcc.

Would you know if I can produce intermediate files with cc under unix, and then port the result to windows for gcc? (Oh yes - and then worry about POSIX compliance and that first child.)

Thanks!

Colin
Paulo A G Fessel
Trusted Contributor

Re: using CC to produce windows executables

Check Cygwin:

http://www.cygwin.com

It's a Linux-like environment, complete with all GNU utilities and even X-Server and KDE that runs in Windows servers. Then, if you have the source of the libraries you use you'll be able to compile them on Cygwin. Having your libraries compiled for Windows, you'll be able to compile your applications there.

You'll be able to compile most UNIX code with it, provided that you send the cygwin.dll togheter with your binaries.

HTH
Paulo Fessel
L'employé propose, le boss dispose.
Shannon Petry
Honored Contributor

Re: using CC to produce windows executables

There are 2 other ways to think about doing this.

1. Java

2. as mentioned gcc, specifically with cygwin


Java of course means re-creating your wheel, but supports any platform.

Using cygwin means that you use the unix emulation features of cygwin, and can run non gui applications with little to no code changes.

Gui's are the killer here. M$ uses it's own set of controls and calls, and X uses another.

Best of luck!

Sincerely,
Shannon
Microsoft. When do you want a virus today?
Colin Rowat
Occasional Advisor

Re: using CC to produce windows executables

Thanks Paulo! That helps.

The libraries are NAG libraries: they're owned by the University at which I work. I therefore am not sure whether I would be legally entitled to port them to a CYGWIN environment on a desktop. (A lesser concern is whether they, and CYGWIM would swamp my poor little PC.)
Brian Bergstrand
Honored Contributor

Re: using CC to produce windows executables

No, Windows doesn't include any unix libs, but it is supposedly POSIX compliant (NT variants only), so IF your code uses only POSIX/ANSI libs, then you should be able to build on windows by linking in the Windows provided POSIX lib.

As for porting object files from UX to Windows, that won't work either. Object files are binary code for a specific processor and they are linked to system libraries. The UX linker ties those toghether to build a final executable. Windows does not provide the UX linker, and the windows linker doesn't understand PA-RISC object code.

So you will have to build from scratch with windows only libs. to make a windows executable.

POSIX makes promises about source code compatibility, binaries are never mentioned.

HTH.
Colin Rowat
Occasional Advisor

Re: using CC to produce windows executables

Thanks Shannon!

This is happening pretty quickly - which I appreciate. I think, though, that my posting in response to Paulo on CYGWIN may also apply to your suggestion? On the bright side, there's no GUI in my code: just a .data file as input and command line switches.

On Java, I'm using the NAG C libraries. Can I link to C libraries with a Java compiler? Perhaps more importantly, I've never programmed in Java before: the structures are similar enough that it wouldn't be a lot of work?

To all posters - thank you very much. This is wonderfully helpful.

Colin
Colin Rowat
Occasional Advisor

Re: using CC to produce windows executables

Thanks again Brian.

If I understand correctly, the upshot of your most recent posting is that I can do the compiling with gcc on windows if:

1. I move the NAG C libraries over; and
2. they are POSIX/ANSI.

I can ask my sysadmin about the first and explore the second on my own (a check reference here would help me, if there's one).

Thanks also for ruling out the object file route - and for remembering the word that I'd forgotten.

Best,

Colin
Shannon Petry
Honored Contributor

Re: using CC to produce windows executables

Using Java you can not link to C-libs.

But... Java contains very similar routines. When developing Java, Sun kept most names the same in Java when compared to C routines that programmers are familiar with.

You may want to get a book or 2 on Java programming and the API, and get a feel for it. It's C like in how you do things so while different, most C programmers dont have trouble with the language at all.

The issue is how you deal with the libraries you have to work with. Are they really necessary? Can you port them to Java or are they already ported to Java? Does Java have the routines already built in?

If your stuck with someone elses library, looking at Java may be futile. But if you cant port them to Cygwin for the PC, then that's futile too. Check with the owner of the libs, and see what they say.

Regards,
Shannon
Microsoft. When do you want a virus today?
Paddy_1
Valued Contributor

Re: using CC to produce windows executables

You can also have a look at UWin which is pretty simple to use :

http://www.research.att.com/sw/tools/uwin/
The sufficiency of my merit is to know that my merit is NOT sufficient
Colin Rowat
Occasional Advisor

Re: using CC to produce windows executables

Dear Shannon and Paddy,

Thank you for your postings. I think that I might have been a bit slow to understand the role of Cygwin, Uwin and the like: their point is not that I might be able to compile an executable to run under windows, but that I run a unix-like environment in my windows machine. If I can't find another way around this, that may be what I do.

Thank you all again for your help.

Best,

Colin