Skip to content
Search

Microsoft Visual C++

lastmod 2026-02-16created 2015-06-3038 edits

Microsoft Visual C++ (MSVC for short) is an integrated development environment (IDE) product that Microsoft designed as a tool for the C, C++, and C++/CLI programming languages. It has tools for developing and debugging C++ (especially code written for the Microsoft Windows API, the DirectX API, and the .NET Framework).

Category

Commandline build

msbuild Project.sln

cl.exe

Example

You can compile as follows. (It outputs *.obj files.)

cl.exe \
    /wd"4819" \
    /I"C:/Users/user/Project/opencv-x64/build/include" \
    /D "NDEBUG" \
    /c \
   main.cpp

Note that command-line options are case-sensitive. /C and /c are different.

ERROR

C2360
initialization of 'value' is skipped by 'case' label
An error caused by a local variable declared inside a case statement. It occurs because the allocated region varies with the execution logic, so the size of the stack region cannot be known at compile time. It is solved by using {} when declaring and initializing inside a case statement.

lib.exe

link.exe

Example

You can create a DLL as follows.

link.exe \
    /OUT:"C:\Users\user\Project\americano\build\Release\pyamericano.dll" \
    /LIBPATH:"C:/Users/user/Project/americano/build" \
    /DLL \
    /MACHINE:X64 \
    /SUBSYSTEM:CONSOLE \
    "oleaut32.lib" "uuid.lib" "comdlg32.lib" "advapi32.lib" \
    src1.obj src2.obj

dumpbin.exe

The Microsoft COFF Binary File Dumper (DUMPBIN.EXE) displays information about COFF (Common Object File Format) binary files. You can use DUMPBIN to examine COFF object files, standard libraries of COFF objects, executable files, and DLLs (dynamic-link libraries).

ToggleHeaderCodeFile

I’ve been doing a lot of managed C++ programming lately and I had forgotten what a pain it is switching back and forth between the header file and source file. Back in the days of Visual Studio 6 I had a macro that switched between the CPP and H file, so I went googling, but the macro I found didn’t work very well in VS2008. Like any good coder, I decided to write it myself instead.

If you haven’t written a macro before, here are the steps.

  1. In Visual Studio, go to Tools | Macros | Macros IDE. A new window should open and in the Project Explorer, the MyMacros project should be open.
  2. Right click on the MyMacros project and select Add | Add Module. Name it CppUtilities. The CppUtilities should open in the editor window.
  3. Add the code from below into the module and save the project.
‘=====================================================================
‘ If the currently open document is a CPP or an H file, attempts to
‘ switch between the CPP and the H file.
‘=====================================================================
Public Sub SwitchBetweenSourceAndHeader()
  Dim currentDocument As String
  Dim targetDocument As String

  currentDocument = ActiveDocument.FullName

  If currentDocument.EndsWith(“.cpp”, StringComparison.InvariantCultureIgnoreCase) Then
    targetDocument = Left(currentDocument, Len(currentDocument) - 3) + “h”
    OpenDocument(targetDocument)
  ElseIf currentDocument.EndsWith(“.h”, StringComparison.InvariantCultureIgnoreCase) Then
    targetDocument = Left(currentDocument, Len(currentDocument) - 1) + “cpp”
    OpenDocument(targetDocument)
  End If

End Sub

‘=====================================================================
‘ Given a document name, attempts to activate it if it is already open,
‘ otherwise attempts to open it.
‘=====================================================================
Private Sub OpenDocument(ByRef documentName As String)
  Dim document As EnvDTE.Document
  Dim activatedTarget As Boolean
  activatedTarget = False

  For Each document In Application.Documents
    If document.FullName = documentName And document.Windows.Count > 0 Then
      document.Activate()
      activatedTarget = True
      Exit For
    End If
  Next
  If Not activatedTarget Then
    Application.Documents.Open(documentName, “Text”)
  End If
End Sub

If you switch back to Visual Studio and open the Macro Explorer, you should see the new module CppUtilities and the new macro SwitchBetweenSourceAndHeader in the tree. You could run the macro from here, but it is much easier to bind it to a keystroke.

  1. Click on Tools | Options then go to the Environment | Keyboard tab.
  2. In the Show commands containing: box, type CppUtilities. This should filter the list down to one entry, Macros.MyMacros.CppUtilitities.SwitchBetweenSourceAndHeader.
  3. Click on the Press shortcut keys: text box and then press the keystroke you would like to use to run the macro. If the keystroke is already used, it will show you below in the Shortcut currently used by: dropdown. When you find one that is unused, click the Assign button to use it. I use Ctrl+Shift+Alt+Bkspce.
  4. Click OK then open a CPP or H file and give it a try.

Debugging

Release mode debugging

How to include debugging information in Release is as follows.

  • Property Page -> Configuration Properties -> C++ -> General -> Debug Information Format (/Zi)
  • Property Page -> Configuration Properties -> C++ -> Optimization -> Optimization (/Od)
  • Property Page -> Configuration Properties -> Linker -> Debugging -> Generate Debug Info (/DEBUG)

Export symbols

Export STL

Favorite site

Command-line helper

Distribute

References


  1. How_to_export_an_instantiation_of_a_Standard_Template_Library_class_and_a_class_that_contains_a_data_member_that_is_an_STL_object.pdf ↩

  2. /MACHINE:[X86|X64|IA64] ↩

  3. How_to_Distribute_C_run-time_Libraries_with_Your_Application_-_CodeProject.pdf ↩

author Zer0 sitemap