How to compile C++ application for Unix/Linux in Windows - c++

I have an application written in C++ using wxWidgets. How can I compile it for Linux and Unix os like Debian, FreeBSD, CentOS, in Windows?
Thanks!

Not entirely sure if I understood the question, but I think you are asking if you can compile an application for linux using a compiler in the windows environment.
My short answer: No, but.
The but: You may be able to use Cygwin in windows, however I think there is an easier way. If you are uncomfortable with setting up your computer to have multiple partitions and installing linux on at least one of these partitions, you can use VirtualBox, VMWare, or similar virtualization software to "install" linux on your windows machine. From there you can set up build environments and such. As for how, I would leave your windows build as is, but then in create a Makefile for Linux (or use CMake to replace both your windows-specific builder (the vsproj if using visual studio, etc) and linux-specific builder (make)) so that your source will compile both on windows and linux without having to modify the actual code or project.

i would recommend to use CMake as build system

Related

Convert Unix Executable to Windows Executable

I compiled and ran a C++ program using Eclipse on my MacBook Pro. I now need to convert the Unix executable to a windows executable. How do I go about this? Specifally, how do I get this code to run on a Windows machine from the command prompt?
The only way you can get the unix executable to run on a Windows system is using a virtual machine (Something like VMWare or VirtualBox). This isn't REALLY running it on Windows, of course, it's setting up a UNIX system on Windows and running it on that UNIX system.
The executables (and the needed runtime environment) are vastly different between the two systems, you can't just run executables from one on the other.
Your only other option is to setup Eclipse on your Windows system and compile the application there.
You cannot "convert" an executable, you need to recompile for your target system. If you are using a GCC toolchain that is set up for Eclipse and there is no Mac specific code, it should be as easy as moving the project over, setting it up in Eclipse, and recompiling it. If that is too much of a hassle, you can consider setting up a Makefile and using MingW or Cygwin, or even Visual Studio if you'd like. If there is Mac specific code, then you need to look up the appropriate Windows documentation, or use something cross-platform like GTK+ or Qt.

C++ MinGW how to compile for Linx from Windows

I currently have MinGW for Windows and would like to develop for Linux(I have read that I need Headers), where would I get Linux headers and set up to compile both Windows and Linux programs with MinGW code::blocks.
Note: I have researched but could not find anything from Windows to Linux only Linux to Windows.
I do not exactly see what you mean by "develop", but if you want to work in an environment that produces binaries for some Linux system, you can not really "develop" because you cannot really run / debug them on Windows (when using cross-compilation).
On the other hand, if you want to develop code that compiles on Linux, you are already there. Since you are developing using MinGW, you are pretty much guaranteed that your code will compile under Linux with corresponding version of GCC. To produce a binary for the Linux distribution of choice, you can use VM, speed should not matter since you are not probably going to do it often.

In what IDE / compiler can I develop C++ code that will be deployed on FreeBSD server.

MY code will be deployed on FreeBSD. Would I be able to code using VS2010 in Win7? can this be done on Linux using gcc? or do I need to have freebsd installed on my laptop.
I plan on buying a new ultrabook and not sure FreeBSD will support the drivers or wireless. What the best practice here? VMs?
Thanks mods.
You can just write code in Visual Studio, however you will not be able to compile and run it in Windows, unless you are only using standard libraries.
To compile and test your code you need a FreeBSD somewhere.
I have never used FreeBSD on a laptop, so I can't say if dualbooting it with Windows is a good idea.
The best thing would be if you had access to a test server with the same configuration as your production server (i.e. same FreeBSD version, same packages, etc.). Then you could write code in VS, check it into a repository, SSH to the server, update a local copy of the source there and build.
If that is not an option, I recommend setting up a virtual environment. Download VirtualBox, obtain FreeBSD and install it on the VM. Set up port forwarding for SSH and then the process is pretty much the same as with a separate server. You may have to make some additional tweaks depending on the nature of the work you'll be doing.
Here is a setup I have used in cases where I am not using any OS specific library.
On your Windows 7 machine develop your application as usual without using MFC/ATL etc. If you are linking to external libraries/APIs you will have to use one which is portable across Windows and Linux (e.g. Boost libraries). Do not use pre-compiled headers (stdfax.h) or any other option which is Windows specific.
Get VirtualBox and install your favorite OS (FreeBSD in this case) and your favorite tool chain (gcc clang)
Share the disk/folder you are developing your app in the Windows file system so that it is visible in VirtualBox. In Ubuntu they end up in the /media/sf_Folder.
Compile in FreeBSD in VirtualBox. You will need to have an alternative make system setup in parallel in addition to the stuff Visual Studio creates. Make sure you do not have any conflicts in the way the directories used by the build system (to store object files etc.) between FreeBSD and Windows. You can try out this http://code.google.com/p/make-it-so/ to convert your VS solutions to gcc makefiles.
This way you can continue to use your favorite IDE and also rebuild on your target *ix OS on the same machine.
gcc + gvim + ( ( ctags with omnicppcomplete ) or ( clang with clang_complete ) and STL + Boost.

DLL Dependencies with Mingw on Windows

I'm working on a program which uses autotools for its build system and compiles fine on linux. To build for windows I'm trying to get a mingw cross-compiler working for windows. Now when I compile on linux and move to windows of course I am missing some dll's that are not installed by default on windows. This leads to missing dll errors. I cannot statically link my program due to restrictions in the LGPL.
So my question is what is the correct way to cross compile in this situation? I feel like I need to wrap my exe in a installer which automatically resolves and installs the dll dependencies for windows but I haven't been able to locate something explaining how to do this. Basically I'm thinking of yum/apt-get for windows. How do I manage dll dependencies on windows? I'm a linux guy, not a windows guy, so please bear with me.
Probably the easiest thing would be if you could move your development to a Windows machine. But short of that, you could install Windows-Mingw on your Linux machine using Wine. (IIRC winetricks has even a target for this) That way you get a "feel" for the issues on windows. An alternative could be Windows in a virtual machine, but Wine should be ok for a development environment.
I also strongly suggest that you install Microsoft Visual C++. The express versions will do fine. There are a number of tools coming with MSVC++ that can make your life a lot easier, like dll-dependency checker etc. An additional excellent source of information are the Sysinternals tools from Mark Russinovich and his blog.

Costs and benefits of Linux-like Windows development environment

I'm taking an Introduction to C++ this semester, so I need to set up development environments in both my Windows and Ubuntu partitions (I switch between them). I was planning to use GCC in both environments for consistency and because I plan to do my serious C++ developing in Linux with GCC.
It appears that installing MSYS and MinGW is the best way to use GCC and replicate my Linux dev environment. However, just setting up MSYS and MinGW in Windows appears to be a long and arduous process, and I'm imagining that I will have limitations or compatibility problems in the future.
Do the benefits of setting up a MSYS Linux-like development environment on Windows outweigh the costs?
Will I be able to use all the libraries that I could if I were using Visual C++?
I think you're going about this the wrong way - I would actually suggest you use Visual Studio on the Windows environment, rather than going out of your way to setup GCC. It's a benefit, not a drawback, to run your code on multiple compilers from multiple vendors.
Both GCC and Visual Studio are highly conformant (at least recent versions). You won't have any trouble with standard libraries and going between them, and if you do have trouble, it's probably an issue in your code.
I've always installed cygwin on Windows. To me, Windows is completely unusable without it. I've never really run into problems with DLLs mentioned above. However, I've also rarely used the GCC compiler, so I don't know how it compares to Visual Studio for general programming. For anything with a Windows GUI or Dot Net based, I would definitely stick with Visual Studio.
If you stick with the automated installer, MinGW installation is not painful at all. Unfortunately, that currently gives you GCC 3.4.5, rather than the newer 4.4.0 release that they also provide sans installer.
In reality, for course work, 3.4.5 will be just fine, I imagine.
Use gcc on Ubuntu and Visual Studio on Windows to get exposure to both. This is an intro course so Windows, Linux, Visual Studio, gcc are just the tools you need to master C++ and data structures. Mastering the tools will come over time and they will change.
I personally develop for windows using a pure Linux environment using mingw-gcc on Linux to cross-compile for windows.
I put a tutorial on how to set it up for OpenSSL/Qt4 # http://www.limitlessfx.com
Do you do this to get .exes or just to be able to work on both OSes?
If you feel more comfortable with GCC than VC, setting up Mingw/Cygwin is possible but doesn't give you any new functionality (beside .exes). Instead, I suggest you turn one of your partitions into a virtual machine - this way you can have both OSes open at once! (My personal choice is Windows inside Linux, YMMV.)
The benefit of developing on Linux is ready availability of tons of development tools and libraries. Also, big builds are noticably faster.
Since you said "I plan to do my serious C++ developing in Linux with GCC", VC++ may not be what you really want. Many libraries just don't compile well in VC++. Try some yourself. Instead, consider running Linux on Windows. There are several ways to do this:
Use PuTTY to connect to a Linux machine, and use Xming to see the UI windows. I would only do this over a LAN.
Consider coLinux. You can run Linux under Windows and just shut-off Linux when you are done.
Consider other virtualization options like VMWare to run Linux. Pretty much the same as coLinux, but it might be easier to setup.
You may even want to install Linux directly on your machine. You can always use tools like Wine or VMWare to run Windows if you need it.