Compiling Visual C++ code in linux - windows

I have written a code in visual c++ , which is a sort of GUI used in virtual com PORT connection. However , i need to run that code in linux so that i can make it an open source. Since , visual c++ doesn't work in linux, I need to find out some alternatives.
So, please me what all alternatives I have
Thanks for your valuable time..!!

i need to run that code in linux so that i can make it an open source.
No, you can license code as open source without it running on linux.
If you simply want your code to run under linux you need to learn how to port from VC++ to Linux/GNU. It's not simply a matter of re compiling it.
See the following URL for advice and google search for more if required: http://www.johndcook.com/blog/2008/05/29/porting-visual-c-code-to-linuxgcc/

In my experience you can get a looooong way with
http://www.winehq.org/docs/winelib-guide/winelib-toolkit
winemaker (doing things as making all your includes case-sensitive correct on Linux)
winegcc (linking to the winelib runtime libs so you can have _WinMain and stuff like that just work)
Of course there are libraries that simply don't exist. Also, installing an SDK can be daunting; winetricks.sh is very helpful in that department. Also, you can consider 'XCOPY' deploying the SDK into your linux build tree and working with that;
This has successfully let me cross compile MSVC projects linked with 3rd party windows libraries in the past. Note minor incompatibilities due to having slightly different linkage semantics with gcc/GNU ld by default; expect this to affect areas like RTTI and exceptions thrown across DLL boundaries).
YMMV
Edit I want to confirm the fact that you can have perfectly valid opensource code for windows only, and you can build it using Visual Studio too. If you want to be nice to your (prospective) contributors, make sure you only depend on Visual Studio Express C++ (not MFC, e.g.) but hey, that's really up to you!

which is a sort of GUI used in virtual com PORT connection
This will be probably hardly portable (because of the BIG differences how virtual ports and GUI are handled in linux and windows - unless you used some cross-platform library already in Windows).
You can release your code as OpenSource for Windows only.

Related

What is the appropriate Unix-POSIX based tool chain to use in Windows

Let's say I have retrieved some C/C++ original and unmodified distribution libraries that were specifically designed for the Unix-POSIX based environments where the original developers who designed their code wrote them specifically for their environments - systems and these libraries originally are not portable to modern Windows systems.
What I would like to be able to do is to at the least build the needed static or dynamic libraries to be able to link them against my own Visual Studio projects.
I know that with Mingw(clang) you only need the MSVC run-time libraries as it doesn't have any need of the POSIX dll dependencies as it uses the Win32 libraries directly. However, it doesn't have all of the Unix environment features that Cygwin(gcc/g++) does and for any C/C++ code that relies on native POSIX functionality such as fork(), mmap(), etc. would have to be re-implemented into the Win32 equivalents for proper compilation, linking, and running of the application.
With Cygwin I'm more exposed to nearly all of the Unix-POSIX features with a little higher learning curve and to integrate these libraries that are built by Cygwin's compiler(s), they would rely on cygwin1.dll to be able to run on a Windows machine.
A Primary Example:
The current libraries that I'm trying to build to work with Visual Studio are GNU's: GMP, MPIR, MPFR, MPFRC++.
So far I have successfully been able to build MPIR in Visual Studio 2017 with the aid of Python and Windows version of Yasm. However, when trying to build MPFR it requires the dependency of GMP. So now I have to build GMP.
I could use Mingw to build GMP which may be in some ways a little easier, but by using Gygwin and building GMP through the Unix/Linux/POSIX environment I would be exposing myself to the functionality of Unix/POSIX systems.
Note - I'm primarily familiar with Windows environments and until recently have never worked with or on any Unix based OS. So there is a bit of a learning curve for me. I'm doing all the research and reading that I can on my own which is not a problem. It provides good experience with every bit of trial and error.
What I would like to know is when working on a Windows machine; what would be the preferable method between the two case scenarios to build POSIX designed libraries to be able to link properly into MSVC Window's based applications? Another words, I would like to efficiently convert POSIX specific libraries to be able to work on my current platform or machine. Notice that I did not say that I wanted to "rewrite" the libraries to make them portable to any arbitrary environment. In this specific case I only need them to run on my Windows environment. Or any other appropriate method. I will be using some C and some C++ libraries to be linked into my MSVC c++17 project(s). (I may also have some of the terminology wrong in some of my above statements or assumptions as I'm not familiar with Unix-POSIX environments).

IDE use a VM compiler?

I'm starting to work on my master thesis at the moment and I have a (maybe) specific question...
I want to stay on windows OS and run a Linux VM via VirtualBox combined with Vagrant. No Problem. I like the feature to reset the VM via vagrant easily.
The next target is using features like auto-completing or similar while developing in C++. This would help me to work with unknown includes/libraries.
Is it possible to access the filesystem/compiler of the VM while using an IDE (like clion) installed on windows? Without explicit loading of the gui und running the IDE on it? Kinda like working with cygwin? I don't want to use cygwin because it doesn't support c++11 standard (or is there a way???)
Maybe you know an alternative way. I would be glad for all hints solving my problem.
I don't know much about cygwin, though I would be surprised if they cannot get recent versions of gcc. But for certain, you can use MSYS2 to get very recent versions of gcc and many other linux packages, which will support C++11.
It's a matter of opinion how best to do cross-platform development, but an alternative worth mentioning is to use cmake for your project. When you want to code in windows, it can make MSVC 2015 project files for you -- when you want to compile in linux, it can find the dependencies and generate a makefile for you to use. IIUC, cmake is the most widely used cross-platform build system right now, besides gnu make itself. (I'm pretty sure it's more popular than "autotools" nowadays, and its definitely more popular than scons.) The advantage is that you avoid the need to maintain multiple platform-specific project files that essentially say the same thing with different formatting.

Which programming languages that can generate self contained windows .exes?

I want to make an easy to deploy Windows application and was was wondering which programming systems can create totally self contained Windows .exe files?
As a plus, if the same can be done with MacOSX and Linux from the same source this would be a bonus. I took a look at Realbasic but they have since abandoned the single .exe concept.
update: i am looking for something that can run from Windows XP up to Windows 7, no matter what version of .NET is installed. Is this even possible?
Delphi compiles to one executable, and generates native windows executables. So no dependencies to any kind of framework. If you use Free Pascal (fpc) and the Lazarus IDE, you could even develop for Linux and Apple from the same source.
If your using external dll's this would become a bit more tricky, but you could pack them up in your resource file and still maintain the one exe property.
Update 2020: since #Vassilis & #Marco van der Voort commented on this, I would like to update my old andswer and add that go is a very good way to make self-contained executables. Even crossplatform compilation is realy simple.
You can certainly do this with C/C++. Technically the runtime libraries are required, but they should already be installed on any windows, mac or linux system.
With .NET you can compile to an EXE, but of course the .NET framework is required. For newer versions of windows it should be installed by default, but on older versions (XP or older?) it may or may not be there. And of course you couldn't expect mono to be there by default on linux or mac either.
For Windows the following languages are viable:
C (MS, gcc)
C++ (MS, g++, Digital Mars)
D (Digital Mars)
Delphi (Embarcadero??? how do you spell that? just trips off the tongue doesn't it?)
Fortran (Intel, Salford Software)
Visual Basic 6 (MS)
Lua (you'll need a special tool to do it, but it is doable)
C#, VB.Net, F#, J#, etc (assuming that you don't mind using .Net technology)
You can use Tcl/tk. The technology you should research is a "starpack", which combines a runtime executable (a starkit) with a platform-specific runtime (a "tclkit") to create a single-file executable. It's remarkable in the fact that it's not just compiled code, but an entire self-contained virtual filesystem that can include images, sound, data, etc.
This same technology works for many platforms from the same code base. The only thing that is different is the platform-specific runtime. You can even "cross compile" in that you can copy the runtime for multiple platforms onto your dev box and then build starpacks for each platform without having to actually be on each platform.
Tcl can do this, especially through producing starpacks. They can be produced for all platforms from the same code. Note that this also includes all the necessary runtime libraries (except for things like the C library, but you don't want to make that static under normal circumstances).
JavaFX 2.2 supports that. It allows creation of self-contained applications targeting Windows, Mac OS, and Linux.
Please follow this link for more information: http://docs.oracle.com/javafx/2/deployment/self-contained-packaging.htm.
I would recommend taking a look at AutoIt. It is an easy-to-use scripting language that will compile into an exe, so there are no runtimes needed. This would be for windows only though.
http://www.autoitscript.com/autoit3/index.shtml
From the website:
AutoIt v3 is a freeware BASIC-like
scripting language designed for
automating the Windows GUI and general
scripting. ... AutoIt is also very small,
self-contained and will run on all
versions of Windows out-of-the-box
with no annoying "runtimes" required!
c/c++
purebasic
delphi
vb6
i hope this help :)
Here's a good source for a number of basic-like programming languages that build small stand-alone EXEs. Some are cross-platform for Windows and Linux:
www.basic.mindteq.com
You can use Liberty Basic which is easy and cheap, you can easily make stand alone programs for windows but not possible to transfer to MacOS or Linux.
You can do this for Windows with .NET languages using ILMerge
ILMerge is a utility for merging multiple .NET assemblies into a single .NET assembly. It works on executables and DLLs alike and comes with several options for controlling the processing and format of the output. See the accompanying documentation for details.
However:
Currently, ILMerge works only on Windows-based platforms. It does not yet support Rotor or Mono.
QBasic can :-)
I wrote a few command line tools using it!

Need some pointers/hints in writing a Windows Application

I want to create applications in windows that has complete portability (within windows OSes of course). I have tried using one application written in Visual C++ but I had a real tough time in making it run in other windows OS (like it required .net framework libraries to be installed). This put me on the back foot because I had to copy a set of DLLs from one machine to another and most of the time something works some does not.
And I am TOTAL amateur in writing windows based applications since my technological forte is mostly Java. Where to kick off? (like which tools/IDEs to begin with since I am seriously into writing my own utilities/tools).
I am open to clarification should you guys feel my question is vague/blunt.
Thanks.
Visual C++ should be easily able to do what you want. It sounds like you created a C++/.NET project, which will generate a dependency on the .net libraries. You need to choose a different project type when the wizard starts up.
If you have a paid version of Visual C++, you might try clicking on "MFC Application". A lot of people are down on MFC these days, but it's still a quick way to get a C++ Windows app off the ground. Make sure you choose the option to statically link the MFC libraries, or you'll have another dependency.
MFC isn't included in the free version of Visual C++, so you'll need to go old-school and work directly with the Windows API or find another package such as QT or Wx to link with.
You can use .NET, and if you stay in 2.0, use standard components, it should work fine. You may need to make a few changes to work anywhere, buy very possible.
http://www.mono-project.com/Main_Page
You could either use Visual Studio or the free IDE. Sharp develope or Mono Develope.
If you really want it to work on every version of windows your best bet may be to go the route of full cross-compatibility. Grab the Boost, QT, and possibly ACE libraries and stay away from making OS calls directly. There's a free version of Visual Studio which is probably what you want for an IDE for personal development, if you're doing commercial stuff then get the full version.
Why not use Java. The JVM is on more systems then .NET and now your app will work on any OS not just windows. Plus java is easier for a beginner then C/C++ and less chance that your program will cause BSODs.

Adding support of Windows to POSIX project... How painful? Is it worth the effort?

I'm trying/thinking of making CppCMS - C++ Web Framework project little bit more cross platform.
Today I can easily support Linux, OpenSolaris, FreeBSD and even Cygwin. But when it comes to Native Windows it becomes really painful:
The overview of the situation:
I'm POSIX/Linux developer and I'm barely familiar with Native Windows development tools like Visual Studio and Win32 API. However I do some work for this platform so I understand the limitations and the fact that Windows is totally different world.
This is web project that uses APIs that popular in Unix world, like: CGI, FastCGI and SCGI that implemented in most UNIX web servers; but I understand that I would not be able to use it with IIS because it does not support FastCGI over TCP/IP (only Windows pipes).
So even when it would work it would probably run only with Windows port of Apache.
I relay heavily on POSIX API:
Pref-forking allows be keep high survivability in case of crashing (not supported under windows) so this feature would be missing.
I use some file-locking facilities (but I can probably give them up without forking)
I have intensive use of native pthreads, even I can replace them with Boost.Thread
I probably would never be able to support Visual Studio (maybe 2010 with C++0x support), because I relay on C++0x decltype/auto feature or typeof/__typeof__ extension that is supported by most compilers I worked with: gcc, intel, sun studio. (To be honest: I can work without them but it makes the life much easier to framework user.
I relay heavily on autotools and I can't replace them with CMake, bjam or friends, because when it comes to support of internationalization, cross copiling, package management, they just does not give me a solution.
There are many annoying points like missing gmtime_r, or localtime_r under windows and many others that just require from me to rewrite them or replace them with 3rd part libraries.
There are still many "UNIX like" libraries that ported to Win32 like: iconv, gcrypt and some others that are barely ported like libdbi that have many limitations on windows.
Bottom line:
There is lots of non-trivial work to do, and even when it would be complete, it would probably work only with MingW tools and not "native" tools that Windows programmers are
familiar with.
So, my questions are:
Does such MingW port worth an effort? Would this help to build bigger community?
Does anybody have experience on how painful porting big projects from POSIX environment to
Win32 API is?
Would it be useful for Windows developers at all?
Edit:
It is also important for me to understand, how many of windows developers prefer to use
Open source development tools, MingW over Microsoft development solutions like VS.
Edit #2: Clearification about "native" windows solusions and IIS.
In fact, running framework with IIS is really hard problem. I explain:
The project relates to standard web server API as FastCGI or SCGI that allows to accept many requests over sinlge socket. Thus, on application side, I accept new request proceed it and returns the answer. Sometimes several threads process several requests.
Thus, implementing one or two standard protocols I open communication with any existing server: Apache, lighttpd, nginx, cherokee... or any other servers; with small exception of IIS
IIS has implementation of FastCGI, but... It supports only 1 connection per local process only that controlled by web server...
So... there is absolutely no standard way to connect my application to IIS.
Please note, I implement standard Web server API, I do not implement Neither IIS proprietary ISAPI nor Apache proprietary API, even the second is more important as for targeting UNIX world.
So, just Windows IIS Web world is just not really ready for cooperation for such project, so if anybody would use it under Windows it would use it with more open web servers.
You should base your decision on user demand. Have users ever requested using the framework on Windows? If so, did they explain why they wanted to use Windows (e.g. what additional constraints they had, what webserver they wanted to use, etc.)?
Typically, Windows users do expect that things work the Windows way. That means Visual Studio support, IIS support, MSI installer, and so on. If something still feels like being Unix, I would rather use Unix proper, instead of fighting with a half-working port.
As a windows client app developer it sort of hurts me that the development environment division currently is essentially Win32 and everything else and that they are mostly incompatible. That's why I'm preparing to move to MinGW for my personal windows app projects and to try to make them cross-platform.
I would suggest gradually moving to more cross-platform libraries like, as you suggested, refactoring pthreads to boost::thread, or going from fork() to multi-process with IPC, probably also using boost's facilities. Date/time stuff can be dealt with Boost libs as well. As for database support, there are
Microsoft compiler support is not that important I think, as MinGW provides a decent build environment with all the IDEs that support it, Eclipse CDT and Dev-C++ being among the most popular. But if you are going to make your project msvc-compatible, make sure users will be able to use Express editions of Visual Studio 2010 (as soon as thay come out) - that way no one will have to fork out for a Visual Studio 2010 (upgrade) just to use your project and there will be no problem for you to require the latest in Microsoft technology.
Most likely you won't avoid some amount of ifdefs for a code base of your project's size, but surely the effort might be worth it, if not only for gaining valuable experience and expanding the community with a few new happy and grateful members.
Your saying that you can support Cygwin quite easily reminds me that I've seen commercial Windows software that simply bundled in cygwin1.dll to support some originally-Unix code. If adding cygwin1.dll to your installer is all it takes, try it out.
I think you only have to look at the questions asked on SO to work out that MinGW users on Windows (of which I am one) are in a minority in the development community - the vast majority of Windows developers are using MS tools. Anyway, the compiler is only half (or less) of the issue - if your architecture depends on forking lots of processes, using MinGW is not going to help you. My advice is, if you really want to do cross platform development:
look at how Apache do it
consider using the Apache libraries as your base
don't use very new or compiler-specific language features
use multi-threading rather than multi-process
Does such MingW port worth an effort? Would this help to build bigger community?
I am still working myself on this issue with my own large POSIX project and my conclusion is that if you need to later interface with Microsoft products, then its worth while, however then I would only use MingW if project is medium small, if it is very large, then I would go all the way with MSDN Microsoft development tools - Huge amount of help will be available there - however it will cost
Does anybody have experience on how painful porting big projects from POSIX environment to Win32 API is?
sofar my own conversion of my POSIX project have been constantly put on hold, because of the amount of time each issue takes to handle is enormous - not finished converting yet - If I ever will be
Would it be useful for Windows developers at all?
Sure working inside the Microsoft IDE using tools from MSDN will definately decrease development time, however it will increase your dependence on Microsoft libraries - something you need to decide from beginning if that is an issue
**
Actually you could just add the necessary cygwin dlls to your projects make and then you would beable to run it in windows
I managed to make my POSIX project run when I added following dlls
cygboost_filesystem.dll
cygboost_system-mt-1_53.dll
cygboost_thread.dll
cyggcc_s-1.dll
cygstdc++-6.dll
cygwin1.dll
Probably your project will have different dependencies, however if you think conversion is not worth it, then perhaps this is a solution for you
You could also add your libs as static, then you would end up with only having to provide the last cygwin1.dll

Resources