Compile Linux application for Windows (C) - windows

can I compile a linux application, with Linux-only available libraries, for Windows ?
I know the author of nginx web server uses some Wine tools to get his Linux-based project working on win32, natively, but how does he do that ?
Is MinGW support to create Windows binaries linked with Linux-specific libraries/headers ?
PS: I do not want to use cygwin due to big lost about performance...

Using something like mingw32 environment, you would have to find or build yourself all libraries on which the project you want to build depends (and all libraries on which those libraries depend).
You might end up having to implement some functionality which is missing on that platform. One of the reasons cygwin is slow is the hoops it has to jump through to simulate unix-y things that are missing on windows.

As long as the project uses the standard libraries on Linux and do not depend on anything specific to the Linux platform, the Mingw port of GCC can compile it on Windows.
If you are familiar with Linux tools and you don't Cygwin, you might want to take a look at MSYS:
MSYS is a collection of GNU utilities such as bash, make, gawk and grep to allow building of applications and programs which depend on traditionally UNIX tools to be present. It is intended to supplement MinGW and the deficiencies of the cmd shell.

Related

Is it possible to create a MingW / MSYS based Windows toolchain to compile Glibc dependent applications for Linux?

I was following instructions here and here to build a toolchain which would work on Windows and compile applications for Linux and different hardware platforms. At first I tried to create cross-compiler for i686-linux to test it on a generic Debian 8 system.
Binutils and GCC compiled fine, but I got stuck at Glibc. It told me:
*** The GNU C library is currently not available for this platform.
I see that Sysprogs toolchains are using Newlib instead of Glibc but I haven't found any explanations except that Newlib is a good choice for embedded devices.
Does it mean that Newlib is actually the only choice for Windows -> Linux and that there is no way to compile software which depends on Glibc? Maybe there are "cheats", like copying pre-built Glibc from the target platform or some other workaround?
In theory, I don't even need Glibc built on Windows, I need just some "Glibc compatible stub" built for the target architecture to link (only dynamically, of course) against while compiling for the target platform and OS. Or am I totally wrong here and GCC cannot link to a different C library than GCC itself was linked to?
Or should I forget it and accept the fact that it is impossible (and, most probably, never will be possible) to achieve full Glibc and Linux kernel compatible C/C++ cross-compiling from Windows to GNU/Linux?
I will accept the answer which explains how GCC and Glibc are related and whether it is possible or not to link against Glibc different from C library used when GCC itself was built, and provide some insight about why it is / is not possible.
my guess is you're using --target when building glibc when you really need to use --host (which is different from how newlib is configured -- best to not ask why).
that said, the glibc build system requires a case-sensitive file system as it creates files like foo.oS and foo.os which are very different things. on a system like Windows, that means the build will be corrupted and fail since foo.oS and foo.os refer to the same file. there are patches out there to hack around this, but really you'd be better off booting a VM and doing the toolchain build inside of that.
NB: i'm not saying you need the VM to do all your development. you just need the VM to build the cross-compiler which you'd then run under Windows. this would be a canadian cross build.
rather than do all this yourself by hand, please check out crosstool-ng. it handles/patches/fixes a lot of common errors people make when trying to create cross-compilers.

Development environment for erlang on Windows

I have an erlang project that includes NIFs with OS specific functions that work with raw sockets. I want to port this project on Windows which means changing the functions in NIFs to work on Windows.
What is the preferred IDE for erlang programming on Windows?
What do I have to set up in order to be able to compile this project?
I'd advice to just down load cygwin with its gcc and try to compile your nif as you would on linux. There are some instructions on github on how to setup an Windows environment to compile Erlang/OTP, but this is probably overkill for your NIF.
As an IDE I would use whatever you are using on Linux, i.e. hopefully Emacs :)
Erlang can be set up as an external tool in msvc.

Compile Ada program for Linux using Windows

If I want to compile a program that is written in Ada, I have to use GNAT, of course.
As my Computer has Windows as its sole operating system, I cannot use GNAT, normally. Right? Thus I got Cygwin which enables me to use GNAT on Windows.
But the result is an executable that runs under Windows - not Linux. So how can I compile the Ada code for Linux although I only have Windows? (Please don't think about the reasons ...)
Is this possible with Cygwin? Do I have to install a virtual machine with Linux? Or is there another (easier) solution to this issue?
I have to use GNAT, of course.
Not true; there are other Ada compilers. (GNAT is the only one I know of that's free.)
Running GNAT under Cygwin gives you Cygwin executables, which are Windows executables that depend on cygwin1.dll. They will not work on Linux. See the "What ... isn't it?" section on the Cygwin home page.
There is a GNAT for Windows. The GNAT Pro version has a list of supported platforms here; it includes Linux and Windows, but it doesn't show a Windows-to-Linux cross compiler.
Since GNAT is free software (GNAT Pro isn't is a little more complicated; I won't get into that) there could well be a Windows-to-Linux GNAT cross-compiler -- or, if you're really ambitious, you could build one yourself (or hire someone to do it for you).
But installing GNAT on a Linux system is the easiest approach. It doesn't have to be a virtual machine. If you have the hardware, you can install some Linux system by itself, or you can set up a dual-boot system on your Windows box. Ubuntu has a Windows installer, Wubi, that installs an Ubuntu image as a Windows file; it doesn't let you run Windows and Ubuntu concurrently, but it lets you dual-boot without having to repartition.
There are other options; these are just the ones I'm familiar with.
Is this possible with Cygwin?
It's probably possible.
Do I have to install a virtual machine with Linux? Or is there another (easier) solution to this issue?
Installing a Linux on a virtual machine is likely to be the simplest solution to your problem.
Since GNAT is free software (GNAT Pro isn't; I won't get into that) there could well be a Windows-to-Linux GNAT cross-compiler -- or, if you're really ambitious, you could build one yourself (or hire someone to do it for you).
Actually GNAT Pro is Free Software, free as in freedom, not as in beer.
And I think that it would be simplest to install Linux in virtual machine and compile with it.
AdaCore has a gnat compiler for the Windows operating system freely available at: http://libre.adacore.com/libre/download/ and choose "Free Software..." and click "Build Your Download Package" and go from there. As Keith Thompson suggests, you can setup a dual-boot solution if you actually need a Linux compatible executable. Remember any program compiled on Windows results in a Windows-only executable unless you have a compiler that allows for cross-compilation.
It became possible for them who use Windows 10 64 bit with new "Linux Subsystem" feature. You may install gnat on it and use it to compile ELF binaries, as well as windows binaries.

Is it possible to use the SANE backend on windows platforms?

I have to develop a scanning application for the Canon 9000F, but I'm having troubles with WIA and TWAIN. I've read on the SANE project's home page that this specific scanner works pretty well with their technology, so I would be interested if it is possible to use the SANE backend on Windows platforms.
I found some information on this website: http://www.zago.net/sane/windows/sane_on_windows.html
SANE on Windows:
The port has been integrated in the CVS tree on september 23rd, 2003.
It will be available in SANE release 1.0.13.
Windows is also listed as platform on the SANE's wikipedia page:
Operating system: Microsoft Windows, Linux, UNIX, OS/2
In spite of this very interesting thread: sane runs in windows without cygwin I think that your only really viable option for using SANE on Windows is to use Cygwin or MinGW with MSYS. From the README.windows file:
SANE on Windows
Prerequisites
To be able to compile sane-backends, you need to have either Cygwin or
Mingw compilers and a suitable POSIX compatible environment.
You can get the Cygwin POSIX compatible environment for Windows
Windows and the Cygwin gcc compiler at http://www.cygwin.com
You can get the MSYS POSIX compatible environment for Windows and the
MinGW gcc compiler at http://www.mingw.org/wiki/MSYS
The scanner must be detected by Windows and not be disabled. Check
with the hardware manager.
Once you have either of those, you can untar and build SANE from the source code (check the readme for the required libraries) and it may or may not work with your Canon 9000F Scanner.
As you say, the chances are good that it will work as it is listed as supported under the pixma backend.
The difficult part was handled by TWAIN which is no longer an option as Windows moves forward. The SANE backends need to be built under Cygwin. Won't build with Mingw - no POSIX functionality.

Visual C++ Development Targeting Linux

I've been a Visual C++ user for quite some time now, and in the following weeks, I will be joining a (C++) Linux-only project. It should be noted that I have absolutely zero development experience on Linux.
Currently, Visual C++ 9 along with the Visual Assist X add-in make Windows-based development rather enjoyable. Having looked at various C++ IDEs on Linux left me a little disappointed with the coding experience, however.
I'd love to be able to use my current tool set (see above) for Linux development, so I have a couple of questions:
Can the VS editor convert between CR+LF <-> LF in a reliable manner?
Is it possible to set up a system where if I press "Build" in the IDE all of my work gets transferred to another box (e.g., a virtual machine) running Linux that compiles my project?
How would debugging work? Is it possible to remote-debug an application running in Linux via something like gdb? If so, would the "advanced" features of MS's debugger (e.g., tracepoints, break-if-cond, etc.) be lost?
Is this even a sane thing to think of? Does anyone use a Windows environment for Linux development? If not, I guess I should just suck it up and move to a Linux environment all together...?
Any input is appreciated, as I feel a little lost right now.
It's probable you'll eventually want to suck it up and work on Linux. microsoft, for obvious reasons, builds their tools to be very Windows-centric and Windows-specific; there are even a few ways in which Visual C++ isn't quite standard C++.
That said, though, you can work with VC++ to some extent.
There are easy tools on linux that will translate to UNIX line endings from Windows. (called something creative like 'dos2unix')
You can set up a remote file system, like with ExpanDrive for Windows, to let you keep your files there.
You can run ssh or rsh from Windows to run makes on the remote Linux box.
I've done windows/linux/freebsd cross-platform development with Windows as my primary OS... so it is possible.
Use VS as editor.
Access Linux Dev node via SSH with
putty.
Use revision control system
(subversion/git/bazaar/mercurial/cvs)
to check changes into repo & check
changes out on Linux.
Use a multi-platform build process. I
use SCons. It is python based
and works beautifully - though it is
a little slow with the default
settings.
Launch build process from shell using
putty.
Use additional shells as needed to
attach gdb & debug.
Now to answer your questions:
Yes. There is a VS setting to say use unix line endings. Many revision control systems can also be configured to correct this for you.
Maybe, but that's not how I did it.
Yes, you can remotely debug using GDB. GDB has many (all?) the features available with VS's debuger but you have to learn the GDB commands. I don't know of a way to use VS's debugger to debug processes compiled with GCC - though this is a frequent request.
I'd recommend that you dive in and try to learn the Linux way of doing things. What are the other people on your team using? If you use the same tool-set as other people, you'll be much better of when asking for help. If you're sitting on a Windows box cross-compiling using Cygwin, you're more or less on your own.
I work on a Linux team currently but use Visual Studio + Visual AssistX as my IDE. VS+VAX is the best environment for developing code in my opinion. Nothing like it exists anywhere else that I've found.
What you want to do is:
Install Cygwin openssh and configure it for shelling into your linux machine without a password.
Expose your development tree on your linux machine as a samba share and mount the share on your Windows machine.
Create a Visual Studio "makefile" project referencing the files on your linux machine.
Override the make command to ssh into your linux machine and execute the build.
Write a sed script on your linux machine that converts gcc/g++ output errors into visual studio format. I use something similar to this: sed -e 's/(.):([0-9]): (.*)/z:\path\to\code\\1(\2): \3/' \
I would really recommend you to give Linux a shot natively, not through a virtual machine. If you run it under a virtual machine you will probably end up doing 85% of your activities under Windows and this will prevent you from actually learning anything under linux.
Install linux in its own partition and work on it fulltime. Do this ASAP before the project start and get familiarized with the basics on how to use it first.
Regarding IDE's to use, find out what build system the project will use and what libraries you will be using. KDevelop is a great IDE although it might be a bit too cluttered. I really like Qt-Creator.
You might wanna give Eclipse a shot too.
As of what distribution to use, I would recommend you Archlinux if you feel like really learning something out of this and learning about linux along with learning to do development under linux. If you dont really want to learn too much about linux and go straight into developing then go with Kubuntu.
As for what Desktop Manager to use I would go with KDE.
There is no Visual Studio on Linux. Period. Try KDevelop or Code::Blocks. They should make development fun on Linux.
As for the compiler/executables you'd have to use the GNU GCC toolchain. There is no MS cl compiler on Linux either.
The debugger to use is gdb, again part of the GCC toolchain.
One more thing, try to pick a shell (like bash) and read up on it. It'll save quite some time in future.
I wrote a ftp script to move files from my pc to the linux box,
then set it up as a tool, so i can at least write the code on the pc, and have
easy access to source safe. I hit a tool button, and the files get transferred to
the linux box, where i use the utilities there to do the work
& 3.:
I use cygwin + Eclipse on Windows for developing and compiling.
With this combination I can also debug via gdbserver on the target machine (VM with x86 Linux or ARM "real" target).
Unfortunately you have to do some tiny but important settings (library paths in gdb etc...) but as soon as it works......
Sorry, no solution for debugging from within VS on a linux box...and I think there will none in the near future...
What you will find is that there are dialectic variations in the compiler and the libraries are different enough that it's unlikely to work well.
You're probably better off with a gcc based tool chain like MinGW if you don't want to switch your environment to Windows right off. MinGW uses native Win32 ports of standard open-source libraries such as getopt, and it is fairly easy to port software between Linux and MinGW32 (as long as you're not using Linux or Windows specific APIs).
However, porting software from MinGW to Visual C++ is quite a bit harder. On the few occasions that I've done this sort of thing I find that porting between Linux and MinGW is much easier than porting between MinGW and Visual C++.
As far as I'm aware I've never seen a MinGW plugin for Visual Studio, although one could theoretically write such a thing as Visual Studio will let you use third party compilers. Additionally, you will have to work with whatever build system the rest of the team uses, which is pretty much guaranteed not to be MSBuild.
So, I'd guess that it's fairly unlikely to work well. Still, as Hunt & Thomas would say getting used to a different way of doing things will make you a better programmer. While vi (or emacs if you're that way inclined), ctags and gdb work quite differently to Visual studio they're still quite a powerful development environment. With MinGW32 and Cygwin or MSYS you can use these without having to make a wholesale switch across to Linux.

Resources