Home  All Courses Robotics C++ AP Java  AP Physics Electronics Astronomy Summer Session Sandia Cameras About
                                                       

Pragma Directives

Introduction

 

Each implementation of C and C++ supports some features unique to its host machine or operating system. Some programs, for instance, need to exercise precise control over the memory areas where data is placed or to control the way certain functions receive parameters. The #pragma directives offer a way for each compiler to offer machine- and operating-system-specific features while retaining overall compatibility with the C and C++ languages. Pragmas are machine- or operating-system-specific by definition, and are usually different for every compiler.

 

Pragmas can be used in conditional statements, to provide new preprocessor functionality, or to provide implementation-defined information to the compiler. The C and C++ compilers recognize a variety of pragmas.

 

The pragma used here is the comment - it uses the following syntax

 

      #pragma comment(comment-type, commentstring)

This code places a comment record into an object file or executable file. The comment-type is one of five predefined identifiers that specify the type of comment record. The optional commentstring is a string literal that provides additional information for some comment types. Because commentstring is a string literal, it obeys all the rules for string literals with respect to escape characters, embedded quotation marks ("), and concatenation.

The keyword lib places a library-search record in the object file. This comment type must be accompanied by a commentstring parameter containing the name (and possibly the path) of the library that you want the linker to search. Since the library name precedes the default library-search records in the object file, the linker searches for this library just as if you had named it on the command line. You can place multiple library-search records in the same source file; each record appears in the object file in the same order in which it is encountered in the source file.

Setup

Open a Win32 Application (not the console application used for strictly OpenGL

Place the following 2 lines at the beginning of all code - if not there already

 

#pragma comment(lib,"glu32.lib")

#pragma comment(lib,"opengl32.lib")