• Aucun résultat trouvé

Environment options

Dans le document for OS/2® (Page 134-138)

Include file and library directories

When working with environment options, bear in mind that Borland C++

recognizes two types of library files: implicit and user-specified (also known as explicit library files). These are defined and discussed on page 126.

-Ipath

-Lpath

-npath

Causes the compiler to search path (the drive specifier or path name of a subdirectory) for include files (in addition to searching the standard places). A drive specifier is a single letter, either uppercase or lowercase, followed by a colon (:). A directory is any valid directory or directory path. You can use more than one -I (which is an uppercase I) directory option.

Forces the linker to get the COx.OBJ start-up object file and the Borland C++ library files (Cx.LIB, CxMT.LIB, and OS2.LIB) from the named directory. By default, the linker looks for them in the current directory.

Places any .OBJ or .ASM files created by the compiler in the directory or drive named by path.

Borland C++ can search multiple directories for include and library files.

This means that the syntax for the library directories (-L) and include directories (-I) command-line options, like that of the #define option (-0), allows multiple listings of a given option.

Here is the syntax for these options:

Library directories: -Ldirname[;dirname; ... ] Include directories: -Idirname[;dirname; ... ]

Chapter 6, Command-line compiler 125

File-search algorithms :

Note

Your code written under any version of Turbo C or Turbo C++ should work without problems in Borland C++.

The parameter dirname used with -L and -I can be any directory or directory path.

You can enter these multiple directories on the command line in the following ways:

• You can" gang" multiple entries with a single -L or -I option, separating ganged entries with a semicolon, like this:

Bee

-Ldirnamel;dirname2;dirname3 -linel;ine2;ine3 myfile.e

• You can place more than one of each option on the command line, like this:

Bee

-Ldirnamel -Ldirname2 -Ldirname3 -linel -line2 -line3 myfile.c

• You can mix ganged and multiple listings, like this:

BCC -Ldirnamel;dirname2 -Ldirname3 -linel;ine2 -line3 myfile.e If you list multiple -L or -I options on the command line, the result is cumulative: The compiler searches all the directories listed, in order from left to right.

The IDE also supports multiple library directories through the" ganged entry" syntax.

The Borland C++ include-file search algorithms search for the header files listed in your source code in the following way:

• If you put an #include <somefile.h> statement in your source code, Borland C++ searches for somefile.h only in the specified include directories.

• If, on the other hand, you put an #include "somefile.h" statement in your code, Borland C++ searches for somefile.h first in the current directory; if it does not find the header file there, it then searches in the include directories specified in the command line.

The library file search algorithms are similar to those for include files:

• Implicit libraries: Borland C++ searches for implicit libraries only in the specified library directories; this is similar to the search algorithm for

#include <somefile.h>. Implicit library files are the ones Borland C++

automatically links in, such as Cx.LIB, OS2.LIB, and the start-up object file (COx.OBJ).

• Explicit libraries: Where Borland C++ searches for explicit

(user-specified) libraries depends in part on how you list the library file name.

Explicit library files are ones you list on the command line or in a project file; these are file names with a .LIB extension.

An annotated example

• If you list an explicit library file name with no drive or directory (like this: my lib . lib), Borland C++ searches for that library in the current directory first. Then (if the first search was unsuccessful), it looks in the specified library directories. This is similar to the search algorithm for

#include "somefile.h" .

• If you list a user-specified library with drive and/or directory

information (like this: c :mystuff\mylib1.lib), Borland C++ searches only in the location you explicitly listed as part of the library path name and not in the specified library directories.

Here is an example of how to compose a Borland C++ command line for an application that uses special header and library files.

1. Your current drive is C:, and your current directory is C: \ BCOS2, where your source code resides. Your A drive's current directory is A: \ ASTRa LIB.

2. Your include files (.h or "header" files) are located in C: \ BCOS2\INCLUDE.

3. Your startup files (C02.0BJ, C02D.OBJ, and so forth) are in C: \BCOS2\LIB.

4. Your standard Borland C++ library files (C2.LIB, C2MT.LIB, ... , OS2.LIB, and so forth) are in C:\BCOS2\LIB.

5. Your custom library files for star systems (which you created and manage with TLIB) are in C:\BCOS2\STARLIB. One of these libraries is PARX.LIB.

6. Your third-party-generated library files for quasars are in the A drive in

\ASTROLIB. One of these libraries is WARP.LIB.

Under this configuration, you enter the following command:

BCC -Llib;starlib -linclude orion.c urnaj.c parx.lib a:\astrolib\warp.lib Borland C++ compiles ORION.C andUMAJ.C to .OBJ files, searching C:\BCOS2\INCLUDE for any header files in your source code. It then links ORION.OBJ and UMAJ.OBJ with the start-up code (C02.0BD, the standard libraries (C2.LIB and OS2.LIB), and the user-specified libraries (PARX.LIB and WARP.LIB), producing an executable file named ORION.EXE.

It searches for the startup code in C:\BCOS2\LIB (then stops because it's there); it searches for the standard libraries in C:\BCOS2\LIB (and stops because they're there).

When it searches for the user-specified library P ARX.LIB, the compiler first looks in the current directory, C:\BCOS2. Not finding the library there, the

Chapter 6, Command-line compiler 127

compiler then searches the library directories in order: first C: \ BCOS2 \ LIB, then C:\BCOS2\STARLIB (where it locates PARX.LIB).

Because an explicit path is given for the library WARP.LIB (A: \ ASTROLIB \ WARP. LIB), the compiler only looks there.

A p p E N

o x

Dans le document for OS/2® (Page 134-138)