What tools do you use to profile (native)C++ on Windows? - c++

How do Window's programmers profile their native C++ code?
On Unix/Linux you have gprof [thanks Evan] & valgrind (I personally used this one, although it's not a real profiler), and recently I'm on Mac and Solaris, which means I moved to dTrace. Now when I've had the need to profile on Windows in the past, like at my previous job, I used Intel's vtune, which is great, however it's commercial, and I don't have a license for private use, so I'm left wondering what's the standard (free is better) tool windows programmers commonly use?
Thanks in advance

You should give Xperf a try - it's a new system wide performance tool that can drill down to a particular application and what exactly it's doing inside itself as well as what's it's asking of the OS.
It's freely available on the Windows SDK for Windows Server 2008 and .NET Framework 3.5 ISO:
Install the SDK by downloading the ISO image, or using the Web based
installer.
Find the xperf MSI in the SDK's "bin" directory. It will be named
xperf_x86.msi, xperf_x64.msi, or
xperf_ia64.msi, depending on the
architecture for which you install the
SDK.
You can then install the xperf tools from the MSI directly, or copy
the xperf MSI file to another location
and install it from there. For
example, you could keep the MSI files
on a USB key.
Source: Pigs Can Fly blog on MSDN.com
Just verified that the xperf msi will not install except on windows Vista or Windows 2007.
-Adam

I got AMD Code Analyst. It's free, and you don't need an AMD CPU ;)
It's a little basic compared to something like Intel's VTune, but the price is right.

This link talks about Linux, but I use the same technique in MSVC and in C#.

Related

Has Windows an integrated built-in C/C++ compiler package?

I would like to be able to compile C and C++ code under the Windows environment without using an IDE, just by using the Windows Command prompt (cmd.exe).
I come from Linux, where you are be able to install the gcc package with just a command in the terminal:
$ sudo apt install gcc
I wonder if there is a C/C++ compiler collection in a package inside the Windows install folders, just like the ones in Linux, I just need to install.
What also gives me a reason to ask this question is:
Since the kernel of Windows and the Windows API are written in C, and many of the high-level applications of the actual Windows 10 release are written in C++, it would be reasonable to also directly provide a suitable compiler suite. This is my thought modell, does not need to match reality.
Thanks for your help.
Since the kernel of Windows and the Windows API are written in C
Microsoft doesn't ship a compiler, or the required Windows SDK headers/libs (also includes a bunch of other useful development tools) for Windows in the installation.
Microsoft Visual C++ (part of Visual Studio) would be the equivalent "built in" choice although I am not sure if Microsoft ever specify exactly which version they use for a given Windows build and it is common to have lots of software built with different compilers/versions (including the various non-Microsoft ones).
As well as the full Visual Studio package with the IDE and other tools. Microsoft provide some components separately, such as the Build Tools for Visual Studio 2019.
I am sure this is for many reasons like most users not being interested in compiling their own software, and Microsoft still sells Visual Studio separately to larger organisations (historically to most serious users, but "Community" edition is now pretty nonrestrictive for individuals and small business).
Strangely enough it doesn't come with a C compiler, we need to install one, Mingw-w64 is allways my choice, you will need to add the path in environment variables (step 12), if you want to use it anywhere. You can then use the gcc command where it's more convenient like in Linux, don't forget to open a new cmd after the changes for them to take effect.
Unfortunately, Windows doesn't have the command line tools for installing/removing stuff and the great repository infrastructure we know and love from Linux.
You will need two things:
The command-line build tools. These can be found on the Visual Studio Downloads page under Tools for Visual Studio -> Build Tools for Visual Studio. This will include the compiler (cl.exe) and linker (link.exe) for the MSVC build toolchain.
The Windows SDK. The latest version of the SDK can currently be found here. This page has a tendency to move around, but googling for Windows SDK usually gives you the right page immediately. The SDK contains all the headers and libraries required to build Windows applications and make use of the Windows native API. The Windows SDK contains a lot of stuff which you may or may not need. You will almost certainly want to install the Windows SDK for Desktop C++ x86 Apps and Windows SDK for Desktop C++ amd64 Apps components. Most of the other stuff should be optional, but some of it is nonetheless highly useful.
You may want to download additional packages such as the Windows Debugger (which is an entirely different application than the Visual Studio debugger) or the Driver SDK, depending on what kind of things you want to develop.
Note that even if you don't intend to use the IDE in the end, installing the full Community Edition of Visual Studio is a far more convenient way to get a working build environment, so unless you have a really good reason not to, just go with the full package and choose to never open the IDE.
The built in compilers available on Windows 10 are for VisualBasic, C#, JScript.
To improve speed & performance of apps, "ngen.exe creates native images, which are files containing compiled processor-specific machine code, and installs them into the native image cache on the local computer. The runtime can use native images from the cache instead of using the just-in-time (JIT) compiler to compile the original assembly".
For low level programmers, ilasm.exe (IL Assembler) ships with Windows, which also facilitates "tool and compiler" development; so you could even create your own language or build a better compiler for a current one, or "debug your code at low level and understand how .NET deals with your high level code", or "write your own compiler for a new .NET language."
For web programmers, AspNetCompiler precompiles server-side ASP.NET web-applications, therefore helps application performance because end users do not encounter a delay on the first request to the application.
All Compilers & assemblers come as builtin with Windows without IDE and can be run from "the Windows Command prompt (cmd.exe)", so no extra downloads necessary; located in folder: C:\Windows\Microsoft.NET\Framework\vx.x.xxxxx\ .
Note: C# is based on JScript.
Compilers:
vbc.exe
csc.exe
jsc.exe
ilasm.exe
ngen.exe
aspnet_compiler.exe
Addendum:
If you still are looking for a C compiler to handle some C source codes you already have spent your life on, then (without downloading) you can make/write a C compiler, in a high level language, then optimize it with a low level language.
This guide will "introduce you to the high-level architecture, theory, and .NET Framework APIs that are required to build your own .NET compiler" in C#.
You can to use gcc for windows. For e.g. mingw, tdm-gcc, mingw-68, Cygwin etc. Each of them allows you to work on c/c++. But if you are not sure about the installation process, and don't want to do all the work by yourself, the easiest solution is to download something like dev-c++ or code-blocks.
cygwin: https://cygwin.com/
mingw-64: http://mingw-w64.org/doku.php
Downloadable file can be found here (for mingw, dev-c++): https://sourceforge.net/
You can also install Microsoft compiler. I usually do it by installing the whole visual studio.

Programming for Windows Phone 8 (and beyond) on GNU/ Linux

Since the VideoLAN programmers do write Windows 8/RT/Phone apps using Linux based operating systems and GCC I was wondering, whether there is some progress in regard to how to program for Windows in a Linux environment, where Windows is used only for testing. How easy/ hard is it, to program a Windows RT (modern UI whatever)/ Windows Phone 8 application on Linux?
I imagine a situation, where you use tools such as Git, Emacs/ VIM, GCC, Mono etc. to do the job. How about submitting the app without Visual Studio?
I ask, because Microsoft open-sourced so much stuff now, using Linux based OS for development could (should?) become feasible while developing apps for their systems. Does anybody have some behind the scenes information on this? It is very hard to find some relevant info.
Note I edited this question to be more "straight to the point"
Links:
This is the VLC Kickstarter page: https://www.kickstarter.com/projects/1061646928/vlc-for-the-new-windows-8-user-experience-metro
I'm a software engineer at Microsoft so I think I could give you some insights on this.
From a testing perspective, you should definitely have a Windows machine to test against. You can install Windows 8 as a VM using Virtual Box or something similar. You could also remote into a Windows machine if you have access to one.
Visual Studio can't be installed in Linux, as you know, but there are other C#/ASP.NET/etc. IDE's that you can use natively on Linux. Look into Wine for Linux: http://www.winehq.org/about/. It may help you somewhat.
As an aside, developing applications for Windows will be getting easier in the coming months. As was announce at MS Build, Microsoft is moving towards a universal app store that will make your app run on all Windows devices: PC, tablet, phone, and Xbox. This doesn't help with developing apps on Linux, but if you're a Windows developer, you might want to keep your eyes open about the new universal-style apps.

USB Programming with Qt

Is there anyway I can do USB programming in Qt? I am using Qt Creator 2.6 which is based on Qt version 5.0.0 and it is the latest Qt Creator which works with the Microsoft Visual Studio 2010 compiler.
I have the toy called "Dreamcheeky Thunder Missile Launcher" and I need to program this USB based device.
I have tried LibUSB but it messed up everything. It even renamed the device port and I had to undo everything using USBDview software. But I guess I installed it incorrectly. I followed these instructions. It is instructions for 64 bit, but I got 32 bit and since the instructions seems not to have big difference (instead the download file) I followed it. This is what I downloaded - libusb-win32-bin-1.2.6.0.zip
Whatever the API you recommend it doesn't matter, even libusb, but please be kind enough to tell me how to install it properly.
My OS is windows 7 ultimate 32 bit.
ollo's answer is out of date. TL;DR is use libusb.info. A bit of explanation:
Originally there was libusb-0.1. Later they updated the API to libusb-1.0, but since libusb-0.1 had been around so long many projects didn't bother switching (kind of like Python 2/3). libusb-0.1 was not available for Windows, but libusb-1.0 is now available for all major platforms.
libusb-win32 is a port of libusb-0.1 to Windows. You shouldn't use it for new code.
libusb.org is the old website for libusb. The latest release is from 2012 and there are no Windows downloads.
libusb.info is the current website for libusb. It contains libusb-1.0 downloads for all platforms and you should use this for new code.
To further confuse things, the sourceforge libusb-win32 mailing list is still used for libusb.info's development.
There's another good instruction for libusb here: http://www.dreamincode.net/forums/topic/148707-introduction-to-using-libusb-10/
libusb:
libusb
libusb-win32 (windows port - use this on windows!)
If you stay on windows you can use
WinUSB:
WinUSB API
Example
Installation
For windows you can use both, but if your program has to be cross-platform you should use libusb.

Which install system to pick when deploying to Windows and Linux?

My company is thinking of dumping InstallShield and move to something else, mainly because of the poor experience it had with it, mostly on Linux.
Our product is a C++ application (binaries, shared libraries) targeted at Windows and Linux (Red Hat).
The installer itself isn't required to do anything special, just dump some binaries and shared libraries and sometime execute an external process. Things like version upgrading through the installer isn't necessary, this is handled after the installer finishes.
I thought of suggesting using NSIS on Windows and RPM on Linux.
What are the recommended installer systems to use when deploying to Windows/Linux? Something that is cross platform to prevent maintaining two installers is a definite plus.
For Windows I would definitively use NSIS. It's very lightweight, easy to code and very simple to understand. Using msis would just be a killer - it generates guid for every file so you can get upgrades for free and stuff but truth being said, you never end up using any of these.
Regarding Linux I would go for RPM and Deb. They're probably the two biggest packaging system so you'll be targeting most of the Linux users. I've never tried RPM but creating a Deb package is fairly straightforward.
See also:
What to use for creating a quick and light setup file?
Packaging to use to deploy cross-platform?
And even:
Creating installers for complex cross-platform programs
There's a tool called BitRock Installer which can create installers for Windows, Linux and OS X.
However, I think that if you target RedHat it would be better to provide native packages for that platform (that is .rpm).
For C++ projects, I'd go with cmake/cpack, if you are also willing to change your build system. Great support, strongly cross-platform. cpack has various generators, NSIS is one..
Take a look at InstallJammer. It will handle both platforms from the same build project, and you can have the installer register the package with the RPM database as well if that's your requirement.
You may want to consider our tool BitRock InstallBuilder , it can generate installers for Windows and Linux from a single project file and also RPMs. Is your application based on Qt? Our clients include the makers of Qt, Nokia (previously Trolltech) and they use it to package their Qt Creator product. We encourage to give InstallBuilder a try and contact our support with any questions or suggestions you may have.

Distribute C++ application as .exe or .msi?

I am looking for a program that can take the program I made in Visual C++ 2008 and distribute it in a mature installer for Windows. I want an application that is FREE (or trial).
The setup and deployment folder is not there when a select File-->Add-->New Project
You can try NSIS (Nullsoft Scriptable Install System), which is free, but can be confusing because it's lots of scripts. That said, it can do anything you might want to do.
Install Creator from ClickTeam is very simple to use and is my preferred application but it does cost money.
WiX has a fairly steep learning curve, but it gives you full access to all features of Windows Installer, with no limitations. It's originally an Microsoft project, and is what Microsoft uses internally for many of its products. It's free and open source under the Common Public License (which permits its use in closed-source products without requiring you to license your own code under it).
For a setup .exe I like Inno Setup, which will let you do desktop icons, amongst other things. Basically you create an Inno Setup installer file which you can pass into the setup compiler which means you can also build it from the command-line. They provide both a GUI and a command-line compiler. The bundled documentation is also very complete.
For MSI you can try the Windows Installer XML (WiX) toolset., which is similar to Inno Setup in that you can compile from the command-line, but a certain amount of Windows Installer / MSI knowledge is expected.
Use setup project in Visual Studio
Check the following programs:
Inno Setup
NSIS
Don't forget to include Microsoft Visual C++ Redistributable Package
Take a look at InstallJammer. Free, open source and easy enough to make a simple installer in minutes while also supporting complex, scripted installers if you find you need them.