Cross compiling from Windows to Linux

Cross compiling from Windows to Linux

Post by Daniel Lu » Fri, 18 May 2001 19:57:57



We are using a cvs like system in our company wich runs under windows only,
we are now developing programs for linux and would like to cross compile
under windows to linux.
I already took a look at cygwin, but could not see any switches for cross
compilation to linux.
Are there any other compilers which can run under windows/dos and that can
cross compile to linux or does any one know what the switches are for
cygwin?

Daniel Tram Lux

 
 
 

Cross compiling from Windows to Linux

Post by jacob navi » Fri, 18 May 2001 20:09:06


As far as I know, this is impossible.
1) Windows is not Unix, and if you write
    int c = fork();
   it will not run under windows...  There is quite a run time gap here!

2) The object format is ELF under Linux, PE under windows. This *could* be
done by a cross-compiler, but you would have to get all linux libraries
under windows, to be able to link the program. This is not difficult
(storage is now cheaper), but there is no software now that does this;
you would have to port all the binutils to windows first.

The easiest way is to install both OSes, and reboot for each compilation. Or
to install a virtual machine that allows you to run both OSes at the same
time.


Quote:> We are using a cvs like system in our company wich runs under windows
only,
> we are now developing programs for linux and would like to cross compile
> under windows to linux.
> I already took a look at cygwin, but could not see any switches for cross
> compilation to linux.
> Are there any other compilers which can run under windows/dos and that can
> cross compile to linux or does any one know what the switches are for
> cygwin?

> Daniel Tram Lux


 
 
 

Cross compiling from Windows to Linux

Post by Chri » Fri, 18 May 2001 20:32:55



> We are using a cvs like system in our company wich runs under windows only,
> we are now developing programs for linux and would like to cross compile
> under windows to linux.

This would be difficult and painful, I expect.

Why not write a little bit of code which checks out the
source from your existing revision control system and
copies it over to a Linux machine for building? It sounds
like you intend to do editing on Win32; if you are using
Developer Studio, it might even be possible to automate
all of this by creating compile commands which call make
or GCC on the remote machine.

--
Chris Lightfoot -- chris at ex dash parrot dot com -- www.ex-parrot.com/~chris/
 ``Hello,'' he lied. (Don Carpenter, quoting a Hollywood agent)

 
 
 

Cross compiling from Windows to Linux

Post by Daniel Lu » Fri, 18 May 2001 21:02:28



> As far as I know, this is impossible.
> 1) Windows is not Unix, and if you write
>     int c = fork();
>    it will not run under windows...  There is quite a run time gap here!

> 2) The object format is ELF under Linux, PE under windows. This *could* be
> done by a cross-compiler, but you would have to get all linux libraries
> under windows, to be able to link the program. This is not difficult
> (storage is now cheaper), but there is no software now that does this;
> you would have to port all the binutils to windows first.

> The easiest way is to install both OSes, and reboot for each compilation.
> Or to install a virtual machine that allows you to run both OSes at the
> same time.



>> We are using a cvs like system in our company wich runs under windows
> only,
>> we are now developing programs for linux and would like to cross compile
>> under windows to linux.
>> I already took a look at cygwin, but could not see any switches for cross
>> compilation to linux.
>> Are there any other compilers which can run under windows/dos and that
>> can cross compile to linux or does any one know what the switches are for
>> cygwin?

>> Daniel Tram Lux

I do not intend to run the compiled program under windows, I only want to
compile under windows.  
All the binutils are already ported in the form of cygwin.
It is exactly the cross compiler that you mentioned that I am looking for.
I do not need both OS'es on one machine as the linux program will run on a
dedicated linux machine.
 
 
 

Cross compiling from Windows to Linux

Post by Daniel Lu » Fri, 18 May 2001 21:38:28


the cvs like tool we use is called pvcs if this helps.
would it be possible to start the compilation by using samba
or the likes?
I do have some knowledge on how to do it the other way round
(cvs on a linux machine and checking out to a windows machine
using ssh and wincvs) The thing is, that the windows system is backed up
regularly and hosts all our source code.

We do indeed intend to do editing on Win32 as I am the only
one in the company with knowledge of linux (it was hard enough
convincing the management of using linux in the first place) and
there are some programmers which are naturally very attached to
their Win32 editing tools.



>> We are using a cvs like system in our company wich runs under windows
>> only, we are now developing programs for linux and would like to cross
>> compile under windows to linux.

> This would be difficult and painful, I expect.

> Why not write a little bit of code which checks out the
> source from your existing revision control system and
> copies it over to a Linux machine for building? It sounds
> like you intend to do editing on Win32; if you are using
> Developer Studio, it might even be possible to automate
> all of this by creating compile commands which call make
> or GCC on the remote machine.

 
 
 

Cross compiling from Windows to Linux

Post by Chri » Fri, 18 May 2001 21:42:16



> the cvs like tool we use is called pvcs if this helps.
> would it be possible to start the compilation by using samba
> or the likes?
> I do have some knowledge on how to do it the other way round
> (cvs on a linux machine and checking out to a windows machine
> using ssh and wincvs) The thing is, that the windows system is backed up
> regularly and hosts all our source code.

> We do indeed intend to do editing on Win32 as I am the only
> one in the company with knowledge of linux (it was hard enough
> convincing the management of using linux in the first place) and
> there are some programmers which are naturally very attached to
> their Win32 editing tools.

I don't know anything about pcvs in particular, although
there is a web page at

        http://www.pvcs.synergex.com/pvcs-plt.htm

which suggests that linux support for it exists. Perhaps
that would be a good route to go down?

--
Chris Lightfoot -- chris at ex dash parrot dot com -- www.ex-parrot.com/~chris/
 The University of California Department of Statistics...
 where mean is normal, and deviation standard

 
 
 

Cross compiling from Windows to Linux

Post by Daniel Lu » Fri, 18 May 2001 22:27:40


That sounds like a possible solution...Do it like water,
follow the way of least resistance ;-)


>> the cvs like tool we use is called pvcs if this helps.
>> would it be possible to start the compilation by using samba
>> or the likes?
>> I do have some knowledge on how to do it the other way round
>> (cvs on a linux machine and checking out to a windows machine
>> using ssh and wincvs) The thing is, that the windows system is backed up
>> regularly and hosts all our source code.

>> We do indeed intend to do editing on Win32 as I am the only
>> one in the company with knowledge of linux (it was hard enough
>> convincing the management of using linux in the first place) and
>> there are some programmers which are naturally very attached to
>> their Win32 editing tools.

> I don't know anything about pcvs in particular, although
> there is a web page at

> http://www.pvcs.synergex.com/pvcs-plt.htm

> which suggests that linux support for it exists. Perhaps
> that would be a good route to go down?

 
 
 

Cross compiling from Windows to Linux

Post by Mumit Kh » Fri, 18 May 2001 23:48:08




Quote:>We are using a cvs like system in our company wich runs under windows only,
>we are now developing programs for linux and would like to cross compile
>under windows to linux.
>I already took a look at cygwin, but could not see any switches for cross
>compilation to linux.
>Are there any other compilers which can run under windows/dos and that can
>cross compile to linux or does any one know what the switches are for
>cygwin?

You'll have to first build a cross-development toolchain of course, hosted
on i686-pc-cygwin targetted for i686-pc-linux-gnu for example.

See
http://www.nanotech.wisc.edu/~khan/software/gnu-win32/cygwin-to-linux...

Regards,
Mumit

 
 
 

Cross compiling from Windows to Linux

Post by Bill Medlan » Sat, 19 May 2001 00:54:05


How about something like this?

Share a directory on your windows machine
Use Samba so that the Linux box can see it
Get the code out using PVCS on the Windows box to the shared directory
cp -r to <wherever> on the linux box to cut down network traffic etc.
find <wherever> -type f -exec dos2unix {} \; (gcc won't like DOS
end-of-line formats)
build on the linux box.

Bill

-snip

 
 
 

Cross compiling from Windows to Linux

Post by David Konerdi » Sat, 19 May 2001 00:15:51



> the cvs like tool we use is called pvcs if this helps.
> would it be possible to start the compilation by using samba
> or the likes?
> I do have some knowledge on how to do it the other way round
> (cvs on a linux machine and checking out to a windows machine
> using ssh and wincvs) The thing is, that the windows system is backed up
> regularly and hosts all our source code.

> We do indeed intend to do editing on Win32 as I am the only
> one in the company with knowledge of linux (it was hard enough
> convincing the management of using linux in the first place) and
> there are some programmers which are naturally very attached to
> their Win32 editing tools.

Yes, you could remotely mount the NT filesystem on the Linux box using
the smbfs file system.  Alternatively, you could (as you suggested earlier)
use Cygwin to build a Linux cross-compiler.  This has been done before (do
some web searches on linux and cygwin, and read on the cygwin home page).
But you'll be better off using the remotely mounted filesystem.

Dave

 
 
 

Cross compiling from Windows to Linux

Post by Sergei Organo » Sat, 19 May 2001 01:00:44


The fact that unlike Windows Linux is multi-user may help.

I'd suggest the following. Dedicate at least one computer to run Linux. On
this computer make accounts for every Windows user that needs to develop for
Linux. Run Samba server on the computer and export either home directories or
some subdirs in home directories through Samba. Let Windows users edit sources
from within Windows on Samba shares of the Linux machine and then run native
Linux compiler remotely (through telnet/rsh/ssh). Please be warned that you
may have troubles with CR/LF and LF conventions for end-of-line in DOS and
UNIX. Try to configure Samba so that the same files on Samba share were seen
from Windows as DOS text and from Linux as Unix text, -- I recall it's
possible.

Besides, this will make transition to native Linux tools more easy in the
future. For example, you can arrange Windows users to run X servers on their
computers and run XEmacs from Linux machine to do all the work. This way they
have their MSWord/Excell handy and simultaneously can do real work in more
user-friendly environment ;-) This is not actually a joke -- most Windows
programming tools are not designed to be useful for anything but Windows
programming, I'm afraid. This way Windows is used just to draw nice pictures,
i.e., the only thing that it does relatively well.

Also, I'd suggest to switch from PVCS to CVS. Put CVS repository on Linux
machine and access it both from Windows and Linux machines. Arrange to backup
CVS repository from the Linux machine. I've used PVCS before and IMHO CVS is
much better from programmer point of view though it requires some paradigm
shift for those who is used to PVCS in the sense that CVS makes things that
were difficult with PVCS surprisingly easy :-) BTW, there are GUIs for
Windows to work with CVS.

Anyway, try it yourself before adopting something as solution.

Hope it helps.

BR,
Sergei.


> the cvs like tool we use is called pvcs if this helps.
> would it be possible to start the compilation by using samba
> or the likes?
> I do have some knowledge on how to do it the other way round
> (cvs on a linux machine and checking out to a windows machine
> using ssh and wincvs) The thing is, that the windows system is backed up
> regularly and hosts all our source code.

> We do indeed intend to do editing on Win32 as I am the only
> one in the company with knowledge of linux (it was hard enough
> convincing the management of using linux in the first place) and
> there are some programmers which are naturally very attached to
> their Win32 editing tools.

[...]
 
 
 

Cross compiling from Windows to Linux

Post by Chri » Sat, 19 May 2001 01:34:45



> find <wherever> -type f -exec dos2unix {} \; (gcc won't like DOS
> end-of-line formats)

Nope, that's fine:

$ perl -e 'print "#include <stdio.h>\r\nint main() {\r\n    printf(\"Hello, world\\n\");\r\n}\r\n";' > hd.c
$ od -a !$
od -a hd.c
0000000   #   i   n   c   l   u   d   e  sp   <   s   t   d   i   o   .
0000020   h   >  cr  nl   i   n   t  sp   m   a   i   n   (   )  sp   {
0000040  cr  nl  sp  sp  sp  sp   p   r   i   n   t   f   (   "   H   e
0000060   l   l   o   ,  sp   w   o   r   l   d   \   n   "   )   ;  cr
0000100  nl   }  cr  nl
0000104
$ cc hd.c -o hd
$ ./hd
Hello, world
$ ^D

--
Chris Lightfoot -- chris at ex dash parrot dot com -- www.ex-parrot.com/~chris/
 A cynic is a man who, upon smelling flowers, looks around for a coffin.
 (Mencken)

 
 
 

Cross compiling from Windows to Linux

Post by Bill Medlan » Sat, 19 May 2001 05:23:12




> > find <wherever> -type f -exec dos2unix {} \; (gcc won't like DOS
> > end-of-line formats)

> Nope, that's fine:

> $ perl -e 'print "#include <stdio.h>\r\nint main() {\r\n  

printf(\"Hello, world\\n\");\r\n}\r\n";' > hd.c
Quote:> $ od -a !$
> od -a hd.c
> 0000000   #   i   n   c   l   u   d   e  sp   <   s   t   d   i   o   .
> 0000020   h   >  cr  nl   i   n   t  sp   m   a   i   n   (   )  sp   {
> 0000040  cr  nl  sp  sp  sp  sp   p   r   i   n   t   f   (   "   H   e
> 0000060   l   l   o   ,  sp   w   o   r   l   d   \   n   "   )   ;  cr
> 0000100  nl   }  cr  nl
> 0000104
> $ cc hd.c -o hd
> $ ./hd
> Hello, world
> $ ^D

> --
> Chris Lightfoot -- chris at ex dash parrot dot com --

www.ex-parrot.com/~chris/
Quote:>  A cynic is a man who, upon smelling flowers, looks around for a coffin.
>  (Mencken)

Sorry; I guess I need to be more specific.
If you have a \ at the "end" of a preprocessor line and it is followed by a
dos end-of-line (\r\n) then it is my experience that the preprocessor phase
of gcc on my Linux box will not recognise it as a request to continue onto
the next line.  That fits in with other comments I have seen during the
past few weeks on this or similar newsgroups.

Bill

 
 
 

Cross compiling from Windows to Linux

Post by Bill Medlan » Sat, 19 May 2001 05:27:16




Quote:

> The fact that unlike Windows Linux is multi-user may help.

-snip
> may have troubles with CR/LF and LF conventions for end-of-line in DOS
and
> UNIX. Try to configure Samba so that the same files on Samba share were
seen
> from Windows as DOS text and from Linux as Unix text, -- I recall it's
> possible.

I'd appreciate the details!  (My reading of FAQ 1 at samba.org suggests
that it isn't).

snip-

 
 
 

Cross compiling from Windows to Linux

Post by Jim Cochra » Sat, 19 May 2001 05:33:58


I think some MS development tools, such as Visual C++'s editor, do fine
with UNIX-style text files (no '\r's), so keeping the source in UNIX format
may be a better solution, unless it's hard to convince the MS tools to not
add the \r.





>> > find <wherever> -type f -exec dos2unix {} \; (gcc won't like DOS
>> > end-of-line formats)

>> Nope, that's fine:

>> $ perl -e 'print "#include <stdio.h>\r\nint main() {\r\n  
>printf(\"Hello, world\\n\");\r\n}\r\n";' > hd.c
>> $ od -a !$
>> od -a hd.c
>> 0000000   #   i   n   c   l   u   d   e  sp   <   s   t   d   i   o   .
>> 0000020   h   >  cr  nl   i   n   t  sp   m   a   i   n   (   )  sp   {
>> 0000040  cr  nl  sp  sp  sp  sp   p   r   i   n   t   f   (   "   H   e
>> 0000060   l   l   o   ,  sp   w   o   r   l   d   \   n   "   )   ;  cr
>> 0000100  nl   }  cr  nl
>> 0000104
>> $ cc hd.c -o hd
>> $ ./hd
>> Hello, world
>> $ ^D

>> --
>> Chris Lightfoot -- chris at ex dash parrot dot com --
>www.ex-parrot.com/~chris/
>>  A cynic is a man who, upon smelling flowers, looks around for a coffin.
>>  (Mencken)

>Sorry; I guess I need to be more specific.
>If you have a \ at the "end" of a preprocessor line and it is followed by a
>dos end-of-line (\r\n) then it is my experience that the preprocessor phase
>of gcc on my Linux box will not recognise it as a request to continue onto
>the next line.  That fits in with other comments I have seen during the
>past few weeks on this or similar newsgroups.

>Bill

--
Jim Cochrane