Quantcast

Maximum PC

It is currently Wed Oct 22, 2014 3:30 pm

All times are UTC - 8 hours




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: How do you actually compile a C++ program?
PostPosted: Mon Apr 06, 2009 11:35 pm 
Northwood
Northwood
User avatar

Joined: Tue Apr 10, 2007 3:08 pm
Posts: 2429
So I'm following this guide for learning C++, but right from the get-go, I have to just ponder how incapable I am of doing something correctly. I used Notepad++ to write a simple "hello world" program like it said to, but it offered no help with choosing a compiler. I found OpenWatcom and Microsoft Visual C++ 2008, but in neither of them could I find a "compile" button, and Watcom wouldn't even open a .txt, .cpp, or .h.

Any help? I've got cookies. :D


Top
  Profile  
 
 Post subject:
PostPosted: Mon Apr 06, 2009 11:40 pm 
Million Club - 5 Plus*
Million Club - 5 Plus*
User avatar

Joined: Sun Sep 12, 2004 6:37 pm
Posts: 4745
Location: In the monkey's litterbox
Open VC++ and create a new Win32 project, step through and choose an empty application with no Precompiled header.

Copy your source files into the solution and work there. (there's a run button, the green triangle)


Top
  Profile  
 
 Post subject:
PostPosted: Thu May 14, 2009 2:45 pm 
8086
8086

Joined: Wed May 13, 2009 10:19 am
Posts: 6
ctrl + f7


Top
  Profile  
 
 Post subject:
PostPosted: Thu May 14, 2009 5:51 pm 
SON OF A GUN
SON OF A GUN
User avatar

Joined: Mon Nov 01, 2004 5:41 am
Posts: 11605
Visual studio calls it "build". It does the same thing.


Top
  Profile  
 
 Post subject:
PostPosted: Thu May 14, 2009 5:52 pm 
SON OF A GUN
SON OF A GUN
User avatar

Joined: Mon Nov 01, 2004 5:41 am
Posts: 11605
GreenBulge wrote:
ctrl + f7
In what? Pretty sure that building/running in visual studio is F5.

Ctrl+shift+B I think just builds the solution.


Top
  Profile  
 
 Post subject:
PostPosted: Thu May 14, 2009 8:05 pm 
Million Club - 5 Plus*
Million Club - 5 Plus*
User avatar

Joined: Sun Sep 12, 2004 6:37 pm
Posts: 4745
Location: In the monkey's litterbox
CrashTECH wrote:
GreenBulge wrote:
ctrl + f7
In what? Pretty sure that building/running in visual studio is F5.

Ctrl+shift+B I think just builds the solution.


It depends on the keybinding setup iirc.


Top
  Profile  
 
 Post subject:
PostPosted: Fri May 15, 2009 4:06 am 
SON OF A GUN
SON OF A GUN
User avatar

Joined: Mon Nov 01, 2004 5:41 am
Posts: 11605
smartcat99s wrote:
CrashTECH wrote:
GreenBulge wrote:
ctrl + f7
In what? Pretty sure that building/running in visual studio is F5.

Ctrl+shift+B I think just builds the solution.


It depends on the keybinding setup iirc.
True, but I think that is the default for it.


Top
  Profile  
 
 Post subject:
PostPosted: Wed Jun 17, 2009 7:01 am 
Super Mario Banhammer
Super Mario Banhammer

Joined: Fri Aug 25, 2006 11:20 am
Posts: 595
@nmanguy

Your question is answered in the very first chapter of the source you are reading.

From your source: "...from the command line, where <filename> is the name of your source code file (for example, test.cpp). Other compilers may do things slightly differently.



--------------------------------------------------------------------------------
NOTE: If you compile the source code from the operating system's command line, you should type the following:
For the Borland C++ compiler: bcc <filename>

For the Borland C++ for Windows compiler: bcc <filename>

For the Borland Turbo C++ compiler: tc <filename>

For the Microsoft compilers: cl <filename>



--------------------------------------------------------------------------------

After your source code is compiled, an object file is produced. This file is often named with the extension .OBJ. This is still not an executable program, however. To turn this into an executable program, you must run your linker.

Creating an Executable File with the Linker
C++ programs are typically created by linking together one or more OBJ files with one or more libraries. A library is a collection of linkable files that were supplied with your compiler, that you purchased separately, or that you created and compiled. All C++ compilers come with a library of useful functions (or procedures) and classes that you can include in your program. A function is a block of code that performs a service, such as adding two numbers or printing to the screen. A class is a collection of data and related functions; we'll be talking about classes a lot, starting on Day 5, "Functions."

The steps to create an executable file are

1. Create a source code file, with a .CPP extension.

2. Compile the source code into a file with the .OBJ extension.

3. Link your OBJ file with any needed libraries to produce an executable program.
..."

Basically you have a program called a compiler. In an IDE the compiler is hidden from view but you are allowed access to it from the build menu.
You have a second program known as a linker. The linker's job is to take your compiled source code and give it access to the various api's and libraries that it will need to be functional.

When you use your compiler you are shrinking the code down to an intermediate languge that is itself executable but has no access to libraries etc. the resulting object file is interpreted code (p-code) but is not yet machine usable (c-code). The linker links one or more object files to various api and header libraries that provide access to the processor instruction set. These processor instructions then become usable by your program once the linker has been invoked and successfully linked.

Once you invoke and successfully link object files your code is now machine readable and executable and becomes a working program.


To directly answer your question if you are using Microsoft VC++ then from a Visual Studio 2008 command prompt type cl /clr <source file name.cpp> This will cause the program to compile and link. The IDE also has a build or run button and that will do the same thing

HTH


Top
  Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 8 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

© 2014 Future US, Inc. All rights reserved.