United States    
COMPAQ
Compaq C

Compaq C
Migration Guide for OpenVMS VAX Systems


Previous Contents

1.4.2 Resolving Link-Time Conflicts with Multiple C RTLs

This section describes the use of interoperability tools to resolve link-time conflicts when using multiple C RTLs.

When migrating to the Compaq C RTL, multiple C RTLs will likely be needed to link an application. One C RTL might be explicitly linked against. A second C RTL might not be explicitly linked against, but brought into the link by means of a shareable image. For example, when developing a Motif program using Compaq C, the application must be linked against the Compaq C RTL and against the Motif images. Motif currently brings the VAX C RTL into the link.

Problems encountered when linking with multiple C RTLs are due to the OpenVMS linker resolving symbol references in the image being linked by searching the transitive closure of shareable images and libraries. That is, when linking with a shareable image, the linker searches that shareable image and all shareable images referenced in that shareable image. So when linking with VAXCRTL.EXE and with an image linked with VAXCRTLG.EXE, the linker will find two instances of all the C RTL symbols (one in VAXCRTL and one in VAXCRTLG), and report a conflict.

The object libraries do not conflict with routine names, but do conflict with the global symbols. Because VAX C implements global symbols as global overlaid psects, the linker attempts to connect all the instances of a C-generated psect with the same name. For example, a reference to stdin in the user program is connected with the psect of the same name in VAXCRTL.OLB. However, a shareable image that was linked with VAXCRTL.OLB also has a psect of the same name; this results in an error because the linker cannot connect those two definitions of the psect stdin .

Three interoperability tools are provided with the Compaq C compiler and in a separate Compaq C/C++ RTL Run-Time Components kit (see Section 1.4.3.1) to resolve link-time conflicts:

These tools work by hiding the conflicting symbols from one of the C RTLs being linked. Which tool is required depends on what C RTLs are used by the main application and the shareable image.

Table 1-2 shows typical C RTL conflicts and the interoperability tool required to resolve it. In the table, VAXCRTL.EXE refers to either VAXCRTL.EXE or VAXCRTLG.EXE.

Table 1-2 Linking Conflicts
Linker Message Type of Conflict Tool Needed
LINK-E-MULSHRPSC VAXCRTL.OLB/VAXCRTL.EXE VAXC$LCL.OPT
LINK-E-SHRPSCLNG VAXCRTL.OLB/DECCRTL.OLB VAXC$LCL.OPT
LINK-E-MULSHRPSC,
LINK-E-SHRPSCLNG
DECCRTL.OLB/VAXCRTL.EXE VAXC$LCL.OPT
None. DECCRTL.OLB/DECC$SHR.EXE DECC$EMPTY
LINK-W-MULDEF VAXCRTL.EXE/VAXCRTLG.EXE VAXC$EMPTY
LINK-W-MULDEF VAXC2DECC.EXE/VAXCRTL.EXE VAXC$EMPTY

1.4.2.1 Using VAXC$LCL.OPT

VAXC$LCL.OPT is required when building any shareable image linked with the VAX C RTL object library or Compaq C RTL object library.

If the shareable image is built without using VAXC$LCL.OPT, the C RTL global symbols are visible in the shareable image and cause linker conflicts when users of the image link against it. For example:


%LINK-E-MULSHRPSC, psect C$$TRNS_VALUES defined in 
        shareable image IMAGE1.EXE; is multiply defined in 
        shareable image SYS$LIBRARY:VAXCRTL.EXE;1 
-LINK-E-NOIMGFIL, image file not created 

In this example, the shareable image IMAGE1 uses VAXCRTL.OLB, and the image being linked uses VAXCRTL.EXE. For a successful link, relink the shareable image using VAXC$LCL.OPT:


$ LINK/SHARE IMAGE1.OBJ, IMAGE1.OPT/OPTIONS, SYS$LIBRARY:VAXCRTL/LIBRARY, - _$ SYS$LIBRARY:VAXC$LCL.OPT/OPTIONS
 

The following message also indicates a conflict involving the VAX C RTL object library:


%LINK-E-SHRPSCLNG, Psect STDIN has length of 8 
        in module C$EXTERNDATA file SYS$LIBRARY:DECCRTL.OLB;2 
        which exceeds length of 4 in shareable image IMAGE1.EXE; 
-LINK-E-NOIMGFIL, image file not created 

In this example, the shareable image IMAGE1 uses VAXCRTL.OLB, and the image being linked uses DECCRTL.OLB. For a successful link, relink the shareable image using VAXC$LCL.OPT.

If the shareable image cannot be relinked (as in the case of a third-party shareable image), then the interoperability tool can be applied to the main image. If the main image is being linked against DECCRTL.OLB, then apply VAXC$LCL.OPT to the link of the main image.

If the main image is being linked against VAXCRTL.EXE, the only solution is to get the shareable image fixed, because applying any of the interoperability tools to the link of the main image will result in an unsuccessful link.

1.4.2.2 Using VAXC$EMPTY.EXE

Use VAXC$EMPTY.EXE to link a main application with both VAXC2DECC.EXE (or VAXCG2DECC.EXE) and a shareable image linked with VAXCRTL.EXE (or VAXCRTLG.EXE). Using VAXC$EMPTY.EXE hides all the global symbols in the VAXCRTL*.EXE shareable image to prevent conflicts with VAXC2DECC.EXE or VAXCG2DECC.EXE.

Also use VAXC$EMPTY.EXE to link an application with both VAXCRTL.EXE and a shareable image linked with VAXCRTLG.EXE (or vice versa).

When there is a conflict between C RTL shareable images, the linker produces large numbers of messages similar to the following:


%LINK-W-MULDEF, symbol ACOS multiply defined 
        in module VAXCRTL file SYS$COMMON:[SYSLIB]VAXCRTL.EXE;18 

In this example, the shareable image is linked with VAXCRTL.EXE, and the main program is linked with VAXC2DECC.EXE.

The solution is to define the VAXCRTL logical to point to VAXC$EMPTY.EXE before linking the main program:


$ DEFINE/USER VAXCRTL SYS$LIBRARY:VAXC$EMPTY.EXE
$ LINK/EXEC=MAIN_IMAGE MAIN_PROG,OBJ1,OBJ2,...,SYS$INPUT:/OPTIONS
IMAGE1/SHARE
VAXCRTL/SHARE
[Ctrl/Z]

Note the following about this solution:

Follow the same process when linking against VAXCRTLG.EXE by defining the VAXCRTLG logical to point to VAXC$EMPTY.EXE.

1.4.2.3 Using DECC$EMPTY.EXE

The DECC$EMPTY.EXE interoperability tool allows a program to use the Compaq C object library even when the program links with a shareable image that was linked with DECC$SHR.EXE.

If DECC$EMPTY.EXE is not used during the link, all Compaq C RTL references from the main program will be resolved in DECC$SHR.EXE, not in the object library. There is no linker message that indicates this fact.

For example, if IMAGE1 is linked against DECC$SHR, and the following link is performed, then the main image will not contain any Compaq C RTL object modules. All C RTL references from the main progam are resolved in DECC$SHR:


$ LINK/EXEC=MAIN_IMAGE MAIN_PROG,OBJ1,...,SYS$INPUT:/OPTIONS
IMAGE1/SHARE
SYS$LIBRARY:DECCRTL/LIBRARY
[Ctrl/Z]

By defining the DECC$SHR logical to point to DECC$EMPTY.EXE immediately before the link, all references to C RTL symbols from the main program are resolved in the Compaq C RTL object library. For example:


$ DEFINE/USER DECC$SHR SYS$LIBRARY:DECC$EMPTY.EXE
$ LINK/EXEC=MAIN_IMAGE MAIN_PROG,OBJ1,...,SYS$INPUT:/OPTIONS
IMAGE1/SHARE
SYS$LIBRARY:DECCRTL/LIBRARY

Note the following about this solution:

1.4.3 Distributing Programs to Other Systems---Version Dependency

Read this section if you distribute to other OpenVMS VAX systems Compaq or user-written Compaq C or Compaq C++ programs, or applications that link either to the VAX C RTL or to a shareable image linked with the VAX C RTL. An example of the latter is a COBOL program that calls the Common Data Dictionary (CDD); CDDSHR is linked against the VAX C RTL.

There are two approaches to solving the problem of distributing such programs to other OpenVMS VAX systems without installing a C or C++ compiler product:

1.4.3.1 Using the Compaq C/C++ Run-Time Components Kit

The Compaq C/C++ Run-Time Components (CRT) kit provides the interoperability tools VAXC$LCL.OPT, VAXC$EMPTY.EXE, DECC$EMPTY.EXE, and other shareable images, message images, and object libraries needed by C and C++ programs compiled with the Compaq C and Compaq C++ compiler products for OpenVMS VAX systems at link and run time. Installing this kit on target OpenVMS VAX systems allows Compaq and user-written C and C++ programs developed on other OpenVMS VAX systems to be run without installing a C or C++ compiler product.

Any images that reference these run-time components will fail to execute if copied to systems where these images have not been provided. This means that if you develop an application with the CRT kit, you must install the CRT kit on every target system where the application will run (unless your application can be distributed using the method described in Section 1.4.3.2, in which case you can choose either method).

For more information on the CRT kit, see the Compaq C/C++ Run-Time Components for OpenVMS VAX Version 6.0-1 Release Notes.

1.4.3.2 Supplying an Alternative Version of SYS$LIBRARY

This method is a distribution option for applications that link to VAXCRTL.EXE or to other shareable images that link to VAXCRTL.EXE.

Application developers who want to continue to compile and link programs that are portable to systems where no CRT kit is installed, need to have an alternative version of SYS$LIBRARY containing the older versions of CRT component files. To provide this alternative version, copy all files in SYS$LIBRARY into another directory before you install the CRT kit. After the CRT kit installation, applications that need to link with pre-CRT versions of the shareable images can be supported without change by temporarily defining the logical name SYS$LIBRARY to point to this alternative SYS$LIBRARY before compiling and linking. With this method, the end user of the application sees no change from the previous, unmodified use of SYS$LIBRARY. The temporary definition of SYS$LIBRARY is not needed at run time.

See Chapter 2 of the Compaq C/C++ Run-Time Components for OpenVMS VAX Reference and Installation Guide for a more complete discussion of this topic.

The following is an example of saving SYS$LIBRARY. The ANALYZE/IMAGE and SEARCH commands show how to check your program for dependency on the CRT kit. In this example, HELLOWORLD is not dependent:


$ CRE/DIR SYS$COMMON:[V55_SYSLIB]
$ COPY SYS$COMMON:[SYSLIB]*.* SYS$COMMON:[V55_SYSLIB]
$ ! 
$ ! Install Compaq C/C++ Run-time Components Kit 
$ ! 
$ DEFINE SYS$LIBRARY SYS$COMMON:[V55_SYSLIB]
$ CC HELLOWORLD
$ LINK HELLOWORLD, SYS$INPUT:/OPTIONS
SYS$LIBRARY:VAXCRTL/SHARE
[Ctrl/Z]
 
$ ANALYZE/IMAGE/OUTPUT=HELLOWORLD HELLOWORLD
%ANALYZE-I-ERRORS, SYS$SYSROOT:[SYSMGR]HELLOWORLD.EXE;2   0 errors 
$ SEARCH HELLOWORLD.ANL DECC$SHR,CMA$TIS_SHR
%SEARCH-I-NOMATCHES, no strings matched 
$ 

Here is the same example without the DEFINE SYS$LIBRARY. If SEARCH finds either CMA$TIS_SHR or DECC$SHR, as it does in this example, then you need the CRT kit installed on the machine where you run your application:


$ DEASSIGN SYS$LIBRARY
$ LINK HELLOWORLD, SYS$INPUT:/OPTIONS
SYS$LIBRARY:VAXCRTL/SHARE
[Ctrl/Z]
 
$ ANALYZE/IMAGE/OUTPUT=HELLOWORLD HELLOWORLD
%ANALYZE-I-ERRORS, SYS$SYSROOT:[SYSMGR]HELLOWORLD.EXE;3   0 errors 
$ SEARCH HELLOWORLD.ANL DECC$SHR,CMA$TIS_SHR             
                        global section name: "CMA$TIS_SHR_001" 
                2)  "CMA$TIS_SHR" 
$ 


Chapter 2
Migrating to the Compaq C Compiler

Chapter 1 describes how to migrate your VAX C applications from the VAX C Run-Time Library (RTL) to the Compaq C RTL for their run-time operations.

This chapter describes techniques for helping VAX C developers migrate to the Compaq C compiler. It discusses some of the Compaq C language features available to help you port your applications from VAX C to Compaq C, and points out changes in the compiler's default behavior.

2.1 General Porting Approach

Use the Compaq C compiler, the Compaq C RTL, the /STANDARD=VAXC qualifier, and message control (/WARNINGS qualifier and #pragma message preprocessor directive) to ease into the Compaq C environment. After you achieve a comfort level compiling in VAX C mode, you can then begin to compile with /STANDARD=RELAXED_ANSI to migrate to the more portable, more ANSI-compliant dialect. See Section 2.4 for more details on this approach.

2.2 Coexistence of VAX C & Compaq C

The VAX C compiler, header files, and RTL are still available and can coexist with the Compaq C compiler on your system.

The CC command is used to invoke either the VAX C or Compaq C compiler. If your system has a VAX C compiler already installed on it, when installing Compaq C your system manager specified which compiler the CC command is to invoke by default. To invoke the compiler that is not the default, use the CC command with the appropriate qualifier:

CC/DECC for the Compaq C compiler

CC/VAXC for the VAX C compiler

To display the default C compiler, enter the following command:


$ SHOW LOGICAL DECC$CC_DEFAULT

To ensure portability to other OpenVMS VAX systems, use CC/DECC explicitly in any command procedures, regardless of what the default is for your system.

2.3 Compiler Mode and Message Control

Compaq C has two complementary qualifiers that control which dialect of C is to be recognized by the compiler, and what messages are generated:

2.3.1 Choosing the Compilation Mode---The /STANDARD Qualifier

The Compaq C compiler for OpenVMS systems provides several dialects of C. You choose the dialect, or mode, by using the /STANDARD qualifier on the CC command. The /STANDARD qualifier causes the compiler to issue only those warnings appropriate for the dialect of C being compiled. For example, in VAX C compatibility mode (/STANDARD=VAXC), the compiler does not issue warnings against VAX C extensions; in ANSI C mode, the compiler does issue such warnings.

See Table 2-1 for a description of the Compaq C compiler modes.

Table 2-1 Compaq C Compiler Modes
Qualifier Description
/STANDARD=ANSI89 Strict ANSI C mode: Only the ANSI language dialect is recognized.

You can use /STANDARD=ANSI89 with /[NO]WARNINGS to control issuance of informational or warning messages. However, the compiler does not recognize many VAX C or common C extensions when in strict ANSI C mode (for example, VAX C keywords not beginning with two underscores). Therefore, many of the messages normally associated with flagging VAX C and common C extensions are not produced.

/NOSTANDARD or
/STANDARD=RELAXED_ANSI89
( default mode)
Relaxed ANSI C mode: This is the default mode on OpenVMS VAX systems. In relaxed ANSI C mode, the compiler follows the ANSI C Standard, but also accepts additional Compaq keywords and predefined macros that do not begin with an underscore.
/STANDARD=VAXC VAX C compatibility mode: This mode of compilation allows the same language as the ANSI C language, but also supports VAX C extensions that are incompatible with the ANSI C Standard and that change the language semantics. This mode provides a high degree of compatibility for programs that depend on old VAX C behavior. This mode is not a complete emulation of VAX C.
/STANDARD=COMMON Common usage C mode: This mode provides a high degree of compatibility with the pcc compiler on ULTRIX systems. This mode is close to a subset of /STANDARD=VAXC mode.
/STANDARD=MIA MIA conformance mode: This is strict ANSI C with some differences required by the Multivendor Integration Architecture (MIA) standard:
  • G_floating becomes the default floating-point format for double variables.
  • In structures, 0-length bit fields cause the next bit field to start on an integer boundary, rather than on a character boundary.

Compaq C modules compiled in different modes can be linked and executed together.

2.3.2 Using Compiler Message Control---/WARNINGS, #pragma message

Because CC/DECC/STANDARD=VAXC finds problems that VAX C ignores, it issues more warning-level messages than VAX C does. Consequently, you can use the /WARNINGS qualifier as a tool to help migrate to /STANDARD=RELAXED_ANSI. You can also use the #pragma message preprocessor directive to fine tune compilation to avoid unwanted messages.

Sections 2.3.2.1 and 2.3.2.2 provide reference information about these message-control features.

Section 2.4 describes how to use /STANDARD, /WARNINGS, and #pragma message to port your code from VAX C to Compaq C.

2.3.2.1 The /WARNINGS Qualifier

The /WARNINGS qualifier has the following format:

/[NO]WARNINGS[=(option[,...])]

This qualifier controls the issuance of compiler diagnostic messages or groups of messages. The /NOWARNINGS qualifier suppresses the warning and informational messages.

Table 2-2 shows the /WARNING qualifier options.

Table 2-2 /WARNINGS Qualifier Options
Option Usage
DISABLE=( message-list) Suppresses the issuance of the message identifiers or message group names listed.

Only messages of severity Warning (W) or Information (I) can be disabled. If the message has severity of Error (E) or Fatal (F), it is issued regardless of any attempt to disable it.

ENABLE=( message-list) Enables issuance of the message identifiers or message group names listed.
NOINFORMATIONALS Suppresses informational messages.

The message-list can be any one of the following:

For a list of all Compaq C compiler message identifiers, enter the following command:


$ HELP CC/DECC MESSAGES

The SUMMARY informational message cannot be suppressed with /NOWARNINGS or /WARNINGS=NOINFORMATIONALS, but it can be suppressed with the DISABLE option.

The default is /WARNINGS. This enables all diagnostic messages for the selected compiler mode except those in the PORTABLE and CHECK groups. The PORTABLE and CHECK groups must be explicitly enabled before their messages can be generated.


Previous Next Contents
  

1.800.AT.COMPAQ

privacy and legal statement