Visual Studio 8 Introduction

  • June 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Visual Studio 8 Introduction as PDF for free.

More details

  • Words: 2,549
  • Pages: 40
Microsoft Visual Studio Introduction Jonas Spillmann, Rüdiger Schmedding Computer Graphics Universität Freiburg

Overview „ „ „ „ „ „ „

What is Visual Studio? Source code, projects and solutions Project configuration Compiling and linking Debugger Tips and Tricks for programming with MS VisualStudio Using the MSDN

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Microsoft Visual Studio „

Is an IDE (Integrated Develop Environment) This indicates that coding, compiling, linking and debugging is done with the same development platform.

„

In contrast to this are Unix command line tools Coding with XEmacs, compiling with gcc, debugging with ddd.

„

VisualStudio supports various programming languages Visual Basic, C/C++, Java, C# / .NET

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Overview „ „ „ „ „ „ „

What is Visual Studio? Source code, projects and solutions Project configuration Compiling and linking Debugger Tips and Tricks for programming with MS VisualStudio Using the MSDN

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Source code and projects .cpp .cpp .cpp ____ ____ .cpp

.h .h

____ ____ ____ ____ ____ ____

____ ____ ____ ____ ____ ____ ____ ____ ____ ____

.vcproj

.exe

.lib

0100 0011 101…

0100 0011 101…

Various source code files are bundled into one project The project (.vcproj) manages configurations for compiling, linking and debugging Æ analogous to a makefile The output of a project is „ an executable (.exe) „ or a library (.lib)

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Projects and solutions .vcproj

.vcproj

.vcproj

Multiple projects are bundled to a solution Larger software projects consist of several modules (libraries, executables, DLLs)

.sln

.exe

.exe

0100 0011 101…

0100 0011 101…

One solution can have several different outputs (e.g. executables, libraries) (Example: command line tool and windows application)

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Adding of source code files

Add New Item… -> Create new source or header file Add Existing Item… -> Add an existing file University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Solution Explorer / Class View

„

Solution Explorer shows hierarchy of projects and solutions. Moving of files using Drag & Drop. Open files with double click

„

Alternatively, use the class view:

„

„

„

„

Shows all classes, fields and methods of a project Handy for navigation between classes and projects

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

1. Task – Create solution „

Create new solution ‚MeshViewer‘: New Æ Project Æ Visual C++ Projects Æ General Æ Empty Project „

„

„ „

Choose „Create new solution“

Add all source files from the folder MeshViewer_Sourcen to the folder ‚MeshViewer‘. Add source files to the project. Open and edit source files.

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Overview „ „ „ „ „ „ „

What is Visual Studio? Source code, projects and solutions Project configuration Compiling and linking Debugger Tips and Tricks for programming with MS VisualStudio Using the MSDN

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Configuration „

A configuration is a set of program parameters: „ „ „

„ „ „

gcc-command line arguments under Unix -> makefile Analogon: User preferences in modern operating systems. Two configuration per default: „ „

„ „

Name and folder of the output files Optimization level of compilage …

Debug: Parameters for the debug version of the software Release: Parameters for the release version of the software

As well possible to create new customized configurations Switch between configuration with the combo box above University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Example configurations „

Configuration „Debug“: „ „ „

„

Name of executable: Halflife_Debug.exe Optimization level: Low Uses external library: Havoc_Physics_Debug.lib

Configuration „Release“: „ „ „

Name of executable: Halflife.exe Optimization level: High Uses external library: Havoc_Physics.lib

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Configuration panel Right click on Project -> Properties… Configuration General „ Output Directory: Directory, where the output files (.exe, .lib) are stored. „ Configuration Type: Type of output „

„

„

„

Application (.exe) Normal, executable program. Library (.lib) Static library. DLL (.dll) Dynamic linked library.

Common Language Runtime Support must be „No CLRS“

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Configuration panel Right click on Projekt -> Properties… Configuration Debugging These parameters apply ONLY if the program is launched from Visual Studio. „ Command Arguments: Program parameters (conforms to command line parameters). „ Working Directory: In which directory the program is being executed.

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Configuration panel Configuration C/C++ „ Additional Include Directories: These directories are scanned upon the command #include „myheader.h“ „

Precompiled Headers: Use this option only for large header files, which speeds up compiling. Otherwise set to „Not Using Precompiled Headers“.

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Configuration panel Configuration Linker „ Additional Library Directories: These directories are scanned for libraries (e.g. third-party distributions, e.g. libjpeg). See below. „ Additional Dependencies: Libraries that are needed for linkage (often third-party libraries) „ SubSystem: „Console“ for console applications, „Windows“ for programs that use the standard Windows GUI. Is automatically set when creating a project by New Æ New Project. University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Configuration panel „

„

„

Most configurations are automatically set by Visual Studio, depending on the type of project being created, and the configuration (Debug/Release) being chosen. An overview on the set configuration parameters is given by „Command line“. Hint: In case of comiling errors (e.g. „Cannot find specified file…“) or linking errors (e.g. „unresolved symbol…“), check always for the configuration parameters!

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Project dependencies „ „

„

„

„

Project Æ Project Dependencies… Which project depends on the output (.lib) of which projects? Influences the order of compilage (Build Order) of the projects. In this case, the output of the projects does not need to be set explicitly To be supervised in the „Command line“ of the project properties

DefCol

Studio

OpenGLGUI

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Overview „ „ „ „ „ „ „

What is Visual Studio? Source code, projects and solutions Project configuration Compiling and linking Debugger Tips and Tricks for programming with MS VisualStudio Using the MSDN

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Compiling / linking „

Build Æ Compile „ „

„

Build Æ Build Solution „ „

„

Compiles all changed files in all projects. Links all projects and builds the output file (.exe).

Build -> Rebuild Solution „ „

„

Compile the current (active) source file. Caution: Headers (.h) cannot be compiled directly!

Similar to above, but recompiles all files. The temporary object files (.obj) are deleted.

Build -> Clean „

All temporary files are deleted.

Hint: VisualStudio sometimes has troubles to detect which files are changed Æ results in linking errors. A „Rebuild all“ helps in those cases. University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Compiling errors „ „

„ „

„

Compiling errors are shown in the window „Task List“. Doubleclick on a line Æ jump to the affected line in the source code. More information about the error Æ select line and type F1 Hint: Most errors are caused by previous errors. Thus do not try to correct all compiling errors at once, but only the first three, and then recompile. Hint: Warnings do not need to be corrected. However, they often indicate logical errors (bugs) in the software.

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Linkage, output „ „

„

„

Linking errors are as well shown in the „Task List“ window. Most frequent linking error: A static library (.lib) has been forgotten in the project configuration. The result of compilage and linkage is summarized in the window „Output“ Alternatively, check directly in the explorer whether the necessary files have been created.

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Execute the program „

„

The program can be launched directly from Visual Studio. The command line arguments are provided in the configuration panel. Two modes of execution: „

„

„

Debug Æ Start (or F5): The debugger is launched together with the program, and allows to debug the software. Only possible in Debug-configuration. Debug Æ Start without Debugging (Ctrl+F5): The program is being executed normally.

If launched in Debug-mode, the loaded DLLs are shown in the Output-window.

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

2. Task – Configuration „

Configurate the project such that „ „ „

„ „

„

„

An executable is generated The program uses the extern library glaux.lib Set the ‚data‘ (that contains kleinbottle.obj) directory as working directory

Common Language Runtime Support must be „No CLRS“ Do a Rebuild solution for both configurations (Debug / Release). Remember: Every configuration (Debug / Release / …) has to configured separately Execute program.

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Overview „ „ „ „ „ „ „

What is Visual Studio? Source code, projects and solutions Project configuration Compiling and linking Debugger Tips and Tricks for programming with MS VisualStudio Using the MSDN

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Debugger „ „ „ „

„

„

Controls the debugged program. Allows to step manually through the flow of execution. Allows to check the values of variables. This is made possible by so-called Debug instructions in the program. That‘s why a debug version of the software is always slower Æ Final software must be always built in the Release-configuration. Linux-users use external debuggers. Visual Studio offers this as well (but less frequently used)

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Breakpoints „

„

„

„

An execution pointer (yellow) indicates the next line of execution. A breakpoint (red point) is a stop signal for the execution pointer. The program flow pauses. The user can now check the variable values and step manually through the code. Set breakpoints by typing F9 or right mouse Æ „New breakpoint“

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Execution pointer control „

„

„

„ „ „ „

Step Into: Step into the function the execution pointer points at. Step Over: Execute the whole function without stepping into the function. Step Out: Jump out of the current function. I.e. execute all commands in the current function until and including „return“ Run To Cursor: Execute all commands to the cursor. Shows the execution pointer. Quits the program. Pauses the running program. Less frequently used. University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Breakpoint-windows „

„

„

„

„

Debug Æ Windows Æ Breakpoints to show the breakpoint window. Breakpoints can be temporarily disabled (Checkbox). In this case, the execution pointer does not stop at the breakpoint. Double click on the breakpoint Æ jump to the breakpoint location in the source code. Right mouse on Breakpoint Æ Properties Æ Condition allows for conditional breakpoints. Only if the condition evaluates to true, the execution pointer stops at the breakpoint. Condition: C-Syntax!

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Variable watch 1 „

In the debugger, it is possible to check the values of variables. Two windows: „

„

„

„

„

Autos (shows the recently used variables) Local (shows all local variables)

Structure fields can be inspected with the ‚+‘ Button. If the value of a variable has changed, it appears in red color. enums are automatically displayed by their name (s. right side ‚Rigid‘)

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Variable watch 2 „

„

Particularly useful: Watch windows (Debug Æ Windows Æ Watch) They allow to evaluate user-defined expressions „ „

„

„

„

Member-functions (first row) Expressions with constants (second row) Calculations with local variables (third row) Overloaded operators are not supported (fourth row)

The value of variables can be manually changed by the user, by entering a new value on the right side. University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

3. Task – Debugging „ „

„

„ „ „

Build the program in debug mode. Set some breakpoints in the code and execute the program. Use Step In, Step Over and Step Out to navigate through the code. Set a conditional breakpoint. Show and change some variable values. Play with expressions in the watch-window.

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Overview „ „ „ „ „ „ „

What is Visual Studio? Source code, projects and solutions Project configuration Compiling and linking Debugger Tips and Tricks for programming with MS VisualStudio Using the MSDN

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Hints and tricks „

„

„

Visual Studio is a complex software with hundreds of other features. On the following slides, there are a couple of practical hints. Becoming a power user is, however, not possible in few days.

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Navigation in the source code „

Right click on a variable or function name in the source code Æ „

„

„

„

Go To Definition jumps to the function body in the source code. Go To Declaration jumps to the declaration of the function in the header file.

To navigate back, use the navigation buttons. The class browser allows to jump directly to a class method within the source file.

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Overview „ „ „ „ „ „ „

What is Visual Studio? Source code, projects and solutions Project configuration Compiling and linking Debugger Tips and Tricks for programming with MS VisualStudio Using the MSDN

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

MSDN „

„

„

„

The MSDN help is one of the most powerful tools in Visual Studio Click onto an expression in the code and press F1 to display help about the expression. Particularly useful: The STL documentation with hundreds of good examples. For Windows-developers: Full documentation of the system API.

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

4. Task – MSDN „ „

Navigate through the source code with the right mouse. Look up some functions in the MSDN.

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Microsoft Visual Studio Have fun with Visual Studio!

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Other debug windows „

The call stack shows the current calling sequence of functions. It is possible to navigate through the call stack by double clicking on the rows in the window.

University of Freiburg - Institute of Computer Science - Computer Graphics Laboratory

Related Documents

Visual Studio
November 2019 24
Visual Studio
November 2019 19
Visual Studio
November 2019 13
Visual Studio
November 2019 14
Visual Studio
November 2019 16