Windows7+: How to build a C++ Windows Console application that doesn't require any additional/external runtime libraries? - c++

This has probably been asked/answered dozens of times, but even after going/reading through many of these questions, i still can't figure out what to do...
Anyhow: I'm trying to write a standalone X86/32-bit C++ Windows console application using Visual Studio 2017 Community Edition (under Windows 10 x64) that runs some CMD.exe commands.
The problem: When trying to run the application on Windows 7, a dialog box pops up with a message saying that a required runtime library couldn't be found.
As i happen to be fairly new to developing/coding, you can probably understand how overwhelmed i am/was when going through Visual Studio's (project) options.
The goal to reach: I would like to know if there's a way (and how) to make my C++ console application work on Windows 7 and onwards, while ONLY using the operating system's built-in/default shipped libraries (if possible without requiring the .NET framework to run the program).
The application's purpose is really simple and is meant for learning the basics of Visual Studio development.
Hopefully someone can help me out. I know i'm supposed to uncheck any recent SDK's in the Visual Studio Installer, but at the same time it appears that the .NET framework seems to be a required component for writing/compiling CLI applications :S

I don't even know why you mention .net for C++. You only need the C++ runtime. That can be statically linked.

Well guys (i assume?), i've returned with some good news.
I'm also answering my own question since i have found a solution that gave me everything i asked/hoped for.
Code::Blocks IDE gave me both a very small program/exe of ~10kB, and it even worked without any additional/extra runtime libraries (i've tested this under a fresh/clean virtual OS # VMware Player).
Thank you all for the given support, you've been really helpful :-)

Related

Connecting to a linux system using a Windows IDE for a C/C++ project

I am new to Linux and therefore feel difficult to code and develop in Linux based environment (CentOS).
Although coding is still fine, I find debugging a quite challenging task because of the lack of breakpoints and the ease of navigating through various class, function and variable definitions that we can do in the blink of an eye using Windows/Mac IDE's.
This leads me to the question :
Can I use a windows IDE to connect to my Linux system and import my project repository and develop on it?
I did some research on using Visual Studio 2017 for this purpose and found a few articles, but most of them explain how I start up with a new project rather than importing/developing upon an existing project.
I also had a look at an article that mentioned about Visual GDB but it wasn't very clear to me, so any pointers on how I can use that would be great.
Any other IDE that I can use on windows for the same purpose? (Visual studio is just something that I looked into, but any other suggestions are also welcome.)
NOTE: My project has both C and C++ code (networking domain), so hence both the tags.

How to run C++ executable in Windows PE?

I have an executable I made using a CLI console application with Visual Basic 2010. I can run the program completely fine from my developer machine.
However, when I copy the executable over to another machine, re-boot to a pre-installation environment and run the executable again, nothing happens at all. There are no errors shown or anything.
My guess is the executable can't run without certain dependencies that aren't loaded at this environment, but I need it to work in a PE.
Any ideas on whats going on?
First of all, since the question is tagged "c++" and you mention C++/CLI several times, I assume that "Visual Basic 2010" is a typo for "Visual Studio 2010". But either way, whether you've written the application in Visual Basic (VB.NET) or C++/CLI, the problem is exactly the same.
My guess is the executable can't run without certain dependencies that aren't loaded at this environment, but I need it to work in a PE.
That's exactly correct. You've written an application that targets the .NET Framework. Somewhat like Java applications requiring a JVM, .NET applications require that the .NET Framework be installed in order to run (or a compatible alternative implementation, like Mono). Unfortunately, Windows PE does not support the .NET Framework.
Note that it is irrelevant whether you've written a WinForms, WPF, or Console application. Although they present their UI in very different ways, they all depend on the .NET Framework being installed.
You will need to (re-)write the application in a different programming language, one that generates native code without any dependencies on the .NET Framework. C and C++ are popular choices. If you choose to use C++, make sure that you create what Visual Studio calls a "Win32" project. This is one that targets the underlying operating system APIs directly (i.e. a native application) and does not have a dependency on the .NET Framework. Stay away from anything that has ".NET" or "CLR" in its description.
I don't really have a full comprehension of when an application is using .NET or not... I am just used to Linux C/C++ development. I hate Microsoft shit
It uses .NET whenever you use the .NET Framework libraries/classes in your code. I'm not really sure why this is so difficult to understand. The same problem could easily exist on Linux if you were using a third-party library that was not available in certain environments for whatever reason. This is not Microsoft's problem, it's an issue of using the wrong tools for the job. The .NET Framework is an object-oriented wrapper around the native APIs that makes it much easier for people to get up and running writing programs for Windows. But if you're "used to Linux C/C++ development", you should have little trouble writing a simple console application that targets the native APIs directly without using .NET.
If your hatred for "Microsoft shit" has turned into an allergy, you can avoid Visual Studio entirely and download MinGW, which is a Windows port of the GCC compiler you're probably used to. Combined with your favorite Windows port of Vi, you're working in an environment very similar to the one you're used to. And since GCC doesn't support C++/CLI or the .NET Framework, you won't have to worry about getting stuck picking the wrong option.
The .Net framework has been supported as an optional package install during your PE build process for the past couple versions of WinPE. I write code in C# that I run in WinPE everyday. I have yet to find a good way to debug in a manner where I can walk through break points, etc... though. My best option has just been a lot of logging and a global Exception catch around my main entry point that will write out a full stack dump. You can attach to your app as a remote process in a VM running WinPE, but if you need to catch something early in the execution you'll have a difficult time.

Should I cross-develop for Linux under Visual Studio

It seems that Visual Studio and the tools you can use it is far superior to Eclipse and other Linux-platforms.
So does it make sense to cross-develop for Linux under Visual Studio, as long as the code is much the same?
I assume that you can easily share files.
Of course it depends a lot of what you know and project setup, but for the later, importing to VS might be easier than importing into Eclipse.
This is actually possible, but only if you have the right infrastructure in place on both Windows and Linux (or some other *nix variety). I used to worke for an investment bank where almost all work was done on Windows with VC++ and then moved to Solaris and recompiled. This allowed us to use the far superior (over Solaris) Windows tools. And we are talking of building multi-tier, multi-threaded servers here.
However, in order to get this to work they had put in a massive effort (I would guess about 15 man-years) in terms of senior developer time. And it was kind of worth it because Solaris development tools are pants (but the Linux ones are actually quite good). It's not something you, as an individual developer are going to find particularly easy to do, unless you are writing generic command line utilities. In which case you can do it - I routinely recompile my Windows command-line projects on Linux.
The difficult part, in my opinion, is maintaining the separate build systems. If you start the project using Visual Studio you will be tempted to setup the project using the Visual Studio build system.
Don't do that.
Instead, I recommend trying CMake. Make the build system build using CMake, and then work from that starting point.
If I had to choose between Visual Studio and Emacs, I'd go with Emacs. The fact that Visual Studio seems superior to you is just because you got used to it and don't know how to do your usual workflow using other tools. Eclipse, after all, might not be the best choice for Windows developer to move to Linux. I'd also take a look at Qt Creator.

How to organize Windows and Android builds of my C++ game?

I would like to develop a Windows build of my Android game for testing and demo purposes. Most of my code is C++, using OpenGL to render, with a thin Android/Java layer that forwards touch events and loads resources.
My first thought was to make a Visual Studio project for my Windows version, as I'm familiar with it and the debugger is excellent.
Can I get similar C++ debugging functionality with Eclipse & CDT? It seems tidier to have all versions working from the same IDE, and it would be nice to become less dependant on proprietary software. Would I be able to add a Windows build configuration in CDT, switch over, and have the IDE launch & debug my Windows version instead? Or would I be entering a world of pain setting this up?
Are there any other approaches I haven't considered? All advice welcome!
CDT is a perfectly good Windows development environment. Just make sure that you have installed the Windows SDK.
If the concern is that Visual Studio puts a lot of the Windows-specific code in place for you, you might consider starting a new project in it. I'd avoid MFC. Just create a new Win32 project. Then, you could take that code and use it as the basis for your Eclipse project, folding in the platform-independent code from your original Android game.
You can easily come up with a cross-IDE solution using makefiles. I guess cmake could help you here.
You could try out MPC. It can generate VS solutions or Eclipse CDT projects(and some more). I've been using it at my previous job and it's really neat once you get the hang of it(which shouldn't be very hard). I'm not sure how well does it work in a
cross-compilation environment, as we were using it to build our project on PC for Linux/Windows.
There's no reason why you shouldn't be able to use Eclipse on WIndows as well.
As far as I know though (I haven't used Eclipse for C++ that much), Visual Studio still has the best debugger. (it can also be a good code health check to compile it with more than one compiler). So there may be reasons to go with VS as well.
If you do decide to go with VS for the Windows version, you may want to look into CMake for managing the build system, since it can generate Visual Studio solutions as well as makefiles and pretty much anything else you may need to build.

Good C++ Debugging/IDE Environment for Linux?

I have a friend who is trying to make the switch to Linux, but is hung up on the apparent lack of debugging/IDE environments for C++, especially as they relate to template programming. He has been using visual studio for years and is maybe a little spoiled by their awesome IDE. Does anyone have any good suggestions for an environment where he can, under Linux, develop and debug with all of the usual things (Breakpoints, line highlighting for compilation errors, step in/over/out/etc, etc) that he's accustomed to? Thanks!
How about Eclipse + CDT ?
Although many people think of it as a Java IDE, he could try NetBeans. I've used it on Windows for C and C++ development without a problem, and I know NetBeans is supported on Linux, so it would be worth a shot.
It looks like most of the features he wants are included in the C/C++ development toolkit, including integration with GDB, a profiler, and more.
Visual Studio is good, indeed.
On the free side:
Qt Creator is getting quite good too, it's worth a try. There are advantageous by-products coming from the Qt framework:
huge library - not only to build GUI applications but for other domains as well
portability on multiple platforms
A version 1.3 beta is available as a preview of the upcoming release but the current 1.2.1 is already all you need to manage projects.
Eclipse has already been mentioned, it's a very good environment offering many plug-ins (Mylyn, SVN, ...).
MonoDevelop somewhat supports C++ (more and more, I didn't check the latest version).
I've used Eclipse for C/C++ and it's pretty useful. It's also used at ACM ICPC World Finals http://cm.baylor.edu/welcome.icpc
I'd recommand Code::Blocks (but use a nighty build). It can be coupled with gdb to enable step by step debugging and all that stuff.
Not exactly an IDE but SublimeText 2/3 is available on Linux now. There may be a debugger plugin for it too, who knows.
Edit
Here's a gdb plugin for SublimeText
I havn't explored it personally, but Emacs has a C++ development addon that looks very much like a full IDE.
About 7 years ago I used KDevelop that was shipped with KDE. I found it quite good back than, and I hope it also improved with the time. I found it quite comparable to VC++ 6 at this time.
It also contains Qt support, if you are in need for some GUI toolkit.
Depends, Code::Blocks is good, Eclipse is very nice too, but you will need a very good computer. In my opinion the best choice iss gcc, gdb and ViM or Gedit.
My buddies from work use Eclipse + Scons, they also use Valgrind(spelling?) for tracking memory leaks and such.
Many of the IDE features you listed were debugger features. The ddd (Data Display Debugger) debugger is quite a nice GUI wrapper for gdb, allowing graphical representation of data structures, a non-crappy source listing window (ie. unlike the l command of gdb where you don't get context), and also allows you to use any and all native gdb commands directly if desired.
Have a look at CodeLite. It's available for Ubuntu and Fedora out of the box and even for Windows and Mac. So you can have the same IDE on different platforms.
We tried Eclipse and NetBeans but left them due to their huge CPU and memory usage. We have a development server and all the developers connect to it via RDC. Thats why these IDEs miserably failed in our model.
So, we looked for some native IDE. Found CodeBlocks to be very good and super fast. We sort of settled on it but later found CodeLite and liked it better than CodeBlocks.
I just seeing this question after 12+ years. AnyHow I just writing my answer. I personally use Quincy IDE for C and C++ development. it is very lite weight and debugging watch list is very much good and easy to use. I'm just attaching the link to the site. try it.
But you have to install it with wine.
Quincy <-- Click here