How can i make a portable C++ program for Windows with GUI, independent from .NET or other Libs? - c++

I want to make a C++ program with Graphical User Interface, to be running on Windows platforms.
I want it to be independent from any libraries like .NET.
The reason I want this is because I want this program to be able to run everywhere, in every version of Windows (XP, VISTA, 7 - 32 & 64bit) without the user to be bound to have already installed a library like .NET.
Also, I want it to be portable: the whole program to consist from only one exe file.
So to summarize:
How can I make an one-exe-file GUI C++ program, able to run on all versions of Windows, without the need of pre-installed libraries on Windows from the user that uses it?
I have already MS Visual C++ 2010 Express and Eclipse with Cygwin's G++ compiler installed on my system.
Notice: I don't mind to use any libraries for windows GUI design if there is a way to embed them inside the executable file of the program.

You can either use a library that can be statically linked (MFC, WTL) or use Win32 API directly.

WxWidgets have static linking capability, never tried it myself.

If you want portabiliy, and yet don't want to depend on 3rd party libraries... well you'll have to provide portability yourself! Don't do it! As adviced by OneOfOne, use Qt and be impressed how simple yet powerful it is. Good luck!

You can also use Qt5, works great on windows and when you figure out that windows isn't the only OS out there, you can easily port it to everything else.
License issues : Proprietary Source code + LGPL Source code

Related

c++ gui window cross platform

I would like to make c++ that will work both on Linux and windows as I understand if I use the win32 template in visual studio then it will only work on windows is there something built into c++ like java's jframe that I can use. Also I would like to use any external library at this time.
Here are some cross platform alternatives QT, wxWidgets, Ultimate++. I have used QT, it is intuitive with a huge collection of tools to use in your code. The others are also popular but I have never used them.
I make used of wxWidgets due to it's cross platform and even cross architecture, native look on the OS where it appear. Binary application yields by wxWidgets is small enough thus make it possible to linking statically as portable application. Qt produce huge binary if linked statically (and may be violate qt licensing scheme).
Another reason are licensing flexibly, well documentation and supported by huge community arround the world. wx is considered as mature framework since it first release about 20yrs ago. It's use standard C++ syntax and preprocessor that will make you easily switch from plain C or C++. Complete library are available ranging from appeal window GUI, string, network, stream, webview, xml, and wx is playing very well with 3rd party library as such database SOCI, Asio, etc ....
You may try start to code with wxWidgets easily using Eclipse-IDE and wxFormBuilder as GUI designer. Plese check my experience for ease setup it's IDE+Toolchain. This wx installer can be used do develop, test and run wx application on Linux desktop, and then deploy the binary on Raspberry Pi is available for another board target beside Linux x86_64.
http://yasriady.blogspot.co.id/2016/01/raspberry-pi-toolchain.html
There is a cross-platform application & UI development framework called Qt. I think it meets your requirements. Click here for more info.
There is a long list of both active and dead cross-platform C++ UI libraries here: https://philippegroarke.com/posts/2018/c++_ui_solutions/

How to use a windows .lib on linux using WINE

I have been using Qt (uses c++ code + Qt libraries) on the windows platform and am in the process of porting my project onto the Linux platform.
Using Qt this has been a very simple process and my project works on the Linux platform with barely any changes required.
However, we need to use a 3rd party windows compiled .lib with an associated header file. Clearly this file cannot work under Linux, but I have been reading posts that suggest I could use Wine to do this.
So in general my project will work as a normal Linux (Ubuntu) project, but I would like to include this .lib file using Wine. I have not been able to find a definitive answer "how to do this". I am not sure if you use Wine to translate the .lib into a .so file or if you have to statically link it in with some "Wine-like" convention...
Can anyone help point me in the right direction?
Thanks :)
AFAIK, you can't make hybrid applications with Wine (i.e. link C++ Linux executable with some Linux static libraries and Windows static libraries).
One of the solution I suggest is to encapsulate you Windows library in a Windows program that act as some network service, then you make your Linux application talk to your Windows library through the network.
However, it adds complexity to your software, requires you know how to do some network programing (however, these days it is quite easy to do) and is not suitable to every kind of library, especially if your library has some kind of GUI.
Have you tried compiling under Windows and running the entire program under Wine?
I'm not sure you can splice Wine and Linux programs.
I cannot imagine that a hybrid approach would work. In any case, running part of your program as a native application and the other part inside WINE will not give you much advantage over the complete program running in WINE. In either case, WINE is needed.
The main disadvantage of running the complete program in WINE is the look and feel of the GUI which might look a little alien to the system. However, using a proper setup for WINE will minimize the problem. And as a side note, most Linux users are used to different GUI concepts due to the different desktop environments available. Personally I have a lot of GNOME applications running in my KDE desktop.
I would personally try running your program in WINE. It makes development much easier. A circuit simulation tool that is quite famous with electrical engineers uses this approach. It is called LTSpice. While only Windows binaries are available, the developers test it with WINE to ensure that it runs on Linux. Admitted, it is a tool offered for free but the community accepts this approach.

Build in wine with my program

I have developed an application designed for commercial use. Application is based on Qt. But I have to use Themida, the anti-cracking software. So I need to compile this software for Linux/MacOS as well, but there is not any obfuscation software like themida. I have an idea.. Is it possible to embed wine to application? As google picasa for example... If yes then how to do that? Are there any examples...
Is it possible to embed wine to application?
You can't "embed" it, because it is a huge collection of dlls. Another problem is that wine is LGPL, so "embedding it" (static link with LGPL) is "no go" for proprietary/closed-source app.
I think you should be able to link with it dynamically.
2 years ago it was possible to make application link with winelib and get access to wine facilities this way. Haven't tried that myself.
It will be probably easier to simply compile application for windows, and then ensure it works under wine - less hassle. However, if I were you, I'd attempt to find different protection scheme - any scheme that doesn't rely on windows-specific technology. Relying on wine to make your app work isn't a very good idea (IMO).
You do not "embed" Wine. Wine is a set of libraries installed on linux that act as a middle-tier between a windows program and the linux system.
Simply compile your app on Windows, preferably wrap it into an installer with all your dependent .dll's like "themida" and possibly the Qt .dll's.
Then install wine on your linux system, try to install your app and cross fingers ;)

Can a single eclipse C++ project link different libraries differently for different platforms?

I have a C++ eclipse project that I would like to easily compile In Windows and OSX.
The project is currently using an automatically generated makefile.
The libraries that I need vary depending on the platform.
In osx I'm using the CoreMidi, CoreAudio, and CoreFoundation frameworks.
In Windows I'm using the winmm.lib and multithreaded libraries.
What's the simplest way to link different libraries/frameworks depending on the current platform?
I'm currently using the gcc toolchain on OSX. Should I start using the cross compile toolchain?
Should I have two projects. One for working in windows, and one for osx, checking them both in to version control?
Should I write a custom makefile instead of using the automatically generated option that has different g++ arguments depending on the platform?
I personally had the same goal for a project and came to the conclusion the Qt framework was the best thing for me. It handles multiple languages, unicode strings, XML, network communications, native looking user interfaces, console applications: it can do an AWFUL lot.
However, as Paul pointed out, you really have to plan it from the start.
Qt does a good job of abstracting the platform away (in a module called QtCore) allowing you to write vanilla C++ code, or you can chose to include some Qt C++ language extensions which a Qt helper application called the moc (meta object compiler) creates vanilla C++ from, which can then be compiled by most common C++ compilers.
It also has a nifty cross-platform makefile generator called qmake which works on project files to create normal make files for the platform its running on.
Off the top of my head at least Windows XP & 7, OSX 10.4, 10.5, 10.6 are supported currently. But note that OSX Lion is (as of writing) not officially supported but I suspect it will be in the next release.
Based on your description, I am not sure you can easily make it cross-platform. Even without using third-party library, you have to provide separate code for osx and windows. Most of time, they design the system as cross-platform first. It's really hard to make an existing project on single-platform to cross-one. If you have the cross-platform requirement, you'd better design in that way first and rewrite from scratch.
Even though Eclipse can run fine on both OS X and Windows, it is not designed to be used in this way.
The best way to do it is to use separate IDE projects for each platform. This this is the easiest way to have unique compilation settings for multiple platforms.
Yes, you can use two eclipse projects. Alternatively, it's not unusual to have a X-Code project for OSX, and a Visual Studio Project for MS Windows.

porting wxwidgets opengl application to not library dependent application

I want to port wxwidgets opengl application that will be not library dependent.I want at least that it can be compiled without additonal libraries. I am thinking to port it to MFC or maybe WIN32.What is the most easiest?Maybe you have some other suggestion?
MFC is by far the easiest. It's also the only realistic option if you don't want to use libraries that aren't installed with Visual Studio.
You do realize, that MFC is just another library and works much like wxWidgets. The only difference is, that MFC ships with Visual C++. However if you were to compile with GCC (MinGW), then you'd have to obtain MFC somehow.
Also the whole boilerplate code for event handling and the like is rather prone to write. I say: Stick with wxWidgets, it's cross plattform, well supported and if you're scared by installing and using libraries, then you should not do programming.
Although one answer is already checked, taking the question the way it was worded, the answer is wrong. MFC is just an other dependency, although shipped with Visual Studio. You still need to ensure that the correct version is installed on the users system. The only real way to solve this problem is to go Win32 with WGL. Then you depend on nothing but OS libraries. (You probably still need to install the vcredist package though...)