How to compile your first program under Microsoft Visual Studio

advertisement
CSCI N305
C Language Programming
Welcome to CSCI N305!
Compiling Your First Program Using
Microsoft Visual Studio 2008
1
Objectives for the Lab
Learn the difference between client-side and
server-side programming
 Learn how to open an empty solution and
project under Visual Studio .Net
 Compile and run a simple program

2
Client-side vs Server-side compiling

Environment setup
 Install MS VS .Net 2008 from iuware.iu.edu

Client-side compiling runs locally on your computer
 Requires installation of a compiler on your system
 Consumes local CPU and hard disk space
 No network (internet) connectivity required

Service-side compiling runs remotely on a server
 Requires remote access software such as SSH available from
iuware.iu.edu
 Server is typically more powerful CPU and has more storage.
 Typically used for larger projects
 Easier to implement team development environment
 Normally uses a command line interface rather than graphical
 Network (internet) connectivity required
 Used for business applications that require production infrastructure
(production monitoring, nightly backups, etc.)
3
Start Microsoft Visual Studio 2008

Start → All Programs → Microsoft Visual
Studio 2008 → Microsoft Visual Studio
2008
4
Starting for the first time
 The
first time you run
MSVS, you might get
a window like this.
 Set Visual C++
Development Setting
as your default
environmental settings.
 Use General
Development Settings
if you have no
preference.
5
Initial MSVS Window

Here is an
image of the
initial
window.
6
Opening a New Project

Open a project using File → New Project → Visual C++
→ Win32 → Win32 Console Application → enter your
project name and browse to select a location (where your
project will be saved) → OK.
7
Project Settings

Choose Next > at this dialog.
Project Settings (continued)

Be sure to check Empty project and Finish.
9
Add a New Item

Right-click
on Source
Files and
Add a New
Item.
10
Create a .c File

Choose Visual C++ Code, C++ File, enter a file name with
.c as the file extension.
11
Enter Code into Your File

Enter a standard C program into the .c file.
12
Save and Compile Your Program

Save → Build → Build Solution
13
Save and Compile Your Program

A successful build:
14
Save and Compile Your Program

An unsuccessful build, read the error message and
correct the errors and build again:
15
Run the Program

After a successful build, Debug →Start
Without Debugging to run the program:
16
Run the Program

Examine the output:
17
Congratulations!





You created a new Microsoft Visual Studio 2008
Project.
Selected Visual C++ Win32 Console Application.
Created your own .c file, entering code just like in
class.
Ran your program to produce output.
You did all of this using an easy editor without
logging onto the internet.
18
Open an Existing Program
If your project is named projectOne:
 Find the projectOne folder at the location where
you saved your project.
 In the projectOne folder, double click on the file
projectOne.vcproj, or projectOne.sln.
 Double click on the .c file (e.g. main.c) will only
open up the code file. It will not let you compile or
run the program using Visual Studio 2008.
19
Submit a Program
You only need to submit the .c file.
20
Download