--------------------------- SunOS to HP-UX 9.05 Porting Guide Version 1.0 --------------------------- HP Publication No. 5963-5416E Printed in USA February 1995 Edition 1 ----------------------------------------------------------------------------- Legal Notices Notice ------ The information in this document is subject to change without notice. Hewlett- Packard makes no warranty of any kind with regard to this material including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Hewlett-Packard shall not be liable for errors contained herein or for incidental or consequential damages in connection with the furnishing, performance or use of this material. Hewlett-Packard assumes no responsibility for the use or reliabilit of its software on equipment that it not furnished by Hewlett-Packard. Copyright/Trademarks -------------------- This document contains proprietary information which is protected by copyright. * UNIX and OPEN LOOK are registered trademarks of UNIX Systems Laboratories, Inc. (Novell) in the USA and other countries. * Open Software Foundation is a trademark, and OSF, OSF/1, OSF/Motif, and Motif are registered trademarks of the Open Software Foundation, Inc. * Adobe, Display Postscript, and Postscript are registered trademarks of Adobe Systems, Inc. * Sun, SunOS, Solaris, Sun Microsystems, the Sun logo, NFS, ONC, SMCC, the SMCC logo, SunSoft, the SunSoft logo, OpenWindows, and DeskSet are registered trademarks of Sun Microsystems, Inc. * All SPARC trademarks are trademarks or registered trademarks of Sparc International, Inc. SPARCstation, SPARCcenter, and SPARCclassic are licensed exclusively to Sun Microsystems, Inc. Products bearing SPARC trademarks are based upon an architecture developed by Sun Microsystems, Inc. * BSD is a trademark of the University of California. * Open Look and Sun Graphical User Interfaces were developed by Sun Microsystems, Inc. * POSIX is a registered trademark of IEEE. * X/Open is a trademark of X/Open Company Limited. * AT&T is a registered trademark of AT&T in the USA and other countries. All other trademarks and registered trademarks are the property of their respective holders. (c) Copyright 1995 Hewlett-Packard Co. All Rights Reserved. NOTE: Please forward all corrections to: sun_port@ch.hp.com. Table of Contents Forward Introduction Development Environment Overview ................................... 1 Compilers 1-1 Compiler Versions 1-1 Compiler Licensing 1-2 Location of Compilers 1-2 Compiler Directives 1-3 Location of Files and Utilities 1-3 C and C++ Header Files 1-3 X11 and Motif Header Files 1-4 System Libraries 1-4 X11 and Motif Libraries 1-4 Other Utilities 1-5 Debug Environment 1-6 HP LaserROM/UX 1-6 HP-UX Patches 1-7 SunOS to HP-UX Porting References 1-7 Compilers .......................................................... 2 C Compiler 2-1 Product Overview 2-1 Key Features 2-2 Performance and Optimization 2-2 Shared Library Support 2-3 C Compiler Ordering Information 2-3 C Language Tips and Traps 2-4 ANSI C Compiler Compile Line 2-4 Compiler Warning: Could Not Find Include File sys/filio.h 2-5 PATH_MAX Not Defined 2-5 SIG_PF Not Found 2-5 S_un Undefined Member on HP-UX 2-5 Problems 2-6 Unexpected Symbols: u_long, u_short 2-6 ANSI C and Include File 2-6 Compiler Fails With "Not Enough Space" Message 2-6 Large Executable Dumps Core 2-6 Error Message: Too Many Defines 2-6 Null Pointer Dereferencing 2-7 MIN and MAX header file differences 2-7 TCGETS and TCSETS 2-7 SunOS to HP-UX C Compiler Options Cross Reference 2-8 C Compiler Options Cross Reference 2-9 C++ Compiler 2-12 Overview of HP C++ Version A.03.50 2-12 HP C++ Run-Time Libraries 2-13 HP C++ Compiler Ordering Information 2-13 C++ Compiler Tips and Traps 2-14 SunOS to HP-UX C++ Compiler Options Cross Reference 2-16 SunOS C++ and HP-UX C++ Compiler Options 2-17 FORTRAN Compiler 2-20 FORTRAN Compiler Tips and Traps 2-20 Pascal Compiler 2-22 Product Overview 2-22 Optimization 2-22 Shared Libraries 2-22 Comments Differences 2-23 Data Type Differences 2-23 Pascal Compiler Options Cross Reference 2-24 GNU gcc/g++ 2-27 g++ Language Tips and Traps 2-27 C++ Functional Prototypes 2-27 Compiler Environment Variables 2-28 CCOPTS Environment Variable 2-28 TMPDIR Environment Variable 2-29 Other Development Tools & Information .............................. 3 make 3-1 make patch: PHCO_4762 3-1 make Environment Variable Differences 3-1 imake 3-2 imake and Long Continuation Lines 3-3 GNU gmake 3-3 Linker 3-3 Incremental Linking 3-4 Blink Link 3-4 HP-UX Debug Environment 3-5 HP Distributed Debugging Environment (HP/DDE) Version 3.05 3-6 GNU Debugging 3-7 dbx Debug Interfaces 3-7 Notes on Debugging Shared Libraries with HP/DDE 3-7 Loading Debugging Information for Shared Libraries 3-8 Making Shared Libraries Writable 3-8 A Shared Library Debugging Session 3-9 Notes on Debugging Shared Libraries with xdb 3-10 Debugging an Application Using Shared Libraries 3-10 Accessing a Function Within a Shared Library 3-10 Debugging a Dynamically Loaded Shared Library 3-10 Adopting a Program 3-10 Software Performance Analysis Tools 3-11 HP/PAK Version 6.05 3-11 HP GlancePlus/UX 3-11 Prof and Gprof 3-12 Profile-based Optimization 3-13 HP SoftBench 3-13 RCS 3-14 SCCS 3-14 trace (public domain) 3-14 Libraries .......................................................... 4 Archived Libraries 4-1 ar 4-1 ranlib 4-1 Shared Libraries 4-1 When Are the Objects Attached? (binding) 4-1 Creating Position-Independent Code (PIC) and Shared Libraries 4-2 Finding Shared Libraries: $SHLIB_PATH 4-3 Enabling Dynamic Path Searching 4-3 With chatr(1) 4-3 With the Linker 4-3 Absolute Paths to Libraries 4-4 Shared Library Performance Considerations 4-5 Shared Library Debugging 4-5 Overview of HP-UX Math Libraries 4-6 How to Select Versions of the Math Libraries 4-6 Graphics ........................................................... 5 OPEN LOOK to OSF/Motif 5-1 Learning OSF/Motif 5-2 Convincing Your Users There Is Another Way 5-2 Your Existing Code 5-2 Porting Strategy 5-3 Porting Utilities 5-4 Graphics Tool Positioning 5-4 Where to Get OSF/Motif for SunOS 5-5 Guidelines for Converting OLIT to OSF/Motif 5-5 Resolving Conflicting Resources 5-7 Window Manager Differences 5-8 Other OLIT Port Issues 5-8 Curses 5-9 Signals ............................................................ 6 BSD4.2 Compatibility 6-2 Asynchronous I/O 6-3 Examples 6-3 BSD4.3 Example 6-3 HP-UX Example 6-4 select() and poll() 6-4 Interprocess Communication (IPC) ................................... 7 FIFOs 7-1 Messages 7-1 Pipes 7-1 RPC 7-2 ONC RPC 7-2 DCE RPC 7-3 Semaphores 7-3 Shared Memory 7-3 Sockets 7-3 TCP Socket Performance 7-5 Streams 7-6 STREAMS Porting Concerns 7-6 BMS and Tooltalk 7-7 DCE Threads 7-7 Miscellaneous ...................................................... 8 Making Daemons 8-1 Unique CPU Identification 8-2 Stack Dump Function 8-2 Programmatically Obtaining Process Status 8-2 Programmatically Obtaining Ethernet Addresses 8-4 PS Instruction "Test and Set" 8-4 Porting Device Drivers 8-5 Compile the Driver 8-5 Add the Driver to the Configuration Files 8-5 Generate the conf.c and config.mk Files 8-6 Build and Install a New Kernel 8-6 Process Virtual Address Space 8-7 Dealing With Data Alignment 8-7 Alternatives for Dealing with Alignment Bus Errors 8-7 Examples of Code Expansion with Alignment Options 8-8 Large Data Space Processes 8-11 System default test case 8-12 Increase MAXDSIZ test case 8-12 Add an Additional Swap Device Test Case 8-12 Increase MAXSWAPCHUNKS Size Test Case 8-13 Relink the Programs with -N Test Case 8-15 Hint for Debugging an X11 Application 8-15 Eliminating Core Dumps 8-15 Obtaining data from /etc/utmp 8-16 Floating Point 8-17 Exception Conditions 8-17 Inexact Result (Rounding) 8-18 HP on the Net ...................................................... 9 University of Liverpool Archive 9-1 Interworks Software Archive 9-2 GNU Software Archive 9-2 HP World Wide Web Sites 9-3 HP's WWW Home Page 9-3 HP WWW SupportLine Page 9-3 HP WWW Patch Server Page 9-3 Other HP-Related WWW Sites 9-3 User Groups 9-4 Interworks 9-4 Interex 9-4 News Groups 9-4 The comp.sys.hp.* hierarchy 9-4 Public Domain Made Easy ............................................ A Building Public Domain Software on HP-UX A-1 Overview A-1 C Compiler A-2 make A-2 imake A-2 imake distribution A-2 Location of imake Configuration Files A-3 Modifications to the Configuration File site.def A-3 Location of Certain Include Files and Libraries A-4 Motif and Xt A-5 Xaw and Xmu A-6 Example: Building the Cutview Program A-7 Simple Imakefile Containing a ComplexProgramTarget A-7 Steps to Building the Software A-7 System and Library Command Cross Reference ......................... B SunOS and HP-UX System Call Differences B-1 SunOS and HP-UX Library Routine Differences B-24 pstat(2) Man Page .................................................. C DBX to XDB Command Summary Cross-Reference ......................... D Execution and Tracing D-1 Displaying and Naming Data D-2 Accessing Source Files D-3 Miscellaneous D-3 Machine Level D-4 Series 700/800 Compatibility ....................................... E Compatibility: What Does It Mean? E-1 What is Not Common E-1 Non-Kernel Differences Between Series 700 and Series 800 E-3 New Math Libraries E-3 X11R5 Server E-4 Building One Executable for Series 700/800 E-4 Building Two Executables for Series 700/800 E-4 Product Information ................................................ F Accent STP F-1 ALSYS, INC. F-2 Bluestone F-2 Hewlett-Packard Company (HP) F-3 Integrated Computer Solutions, Inc. (ICS) F-5 iXOS Software F-6 Melillo Consulting F-6 Qualix F-7 UIM/X F-7 UniPress Software, Inc. F-8 V. I. Corporation F-9 XView Library F-9 Forward This guide provides information and hints on porting from SunOS 4.1.3 to HP-UX 9.05. A porting experience from SunOS to HP-UX need not -- and should not -- be painful. HP-UX has many of the same system calls and tools found on SunOS. This guide should direct you through most of the known differences and facilitate your introduction to the development environment on HP-UX. The guide is an assimilation of white papers, discussions on the Internet, and most importantly, the real life porting experiences of customers and HP engineers, channel partners, and ISVs porting from SunOS to HP-UX. We would like to acknowledge all these valued sources of information. Every effort has been made to ensure that all the enclosed information is correct. Developers who have already successfully ported from SunOS to HP-UX have found this guide very useful. If you do find errors in this guide, have additional information that should be included in the guide, or have any other comments and feedback, please direct that information via email to sun_port@ch.hp.com. Enjoy! intro-1 Introduction This guide provides information and hints on porting from SunOS 4.1.3 to HP-UX 9.05. This introduction provides an overview of HP-UX standards and operating system directions. The introduction is recommended reading for all developers and key decision-makers in your organization. The remaining chapters provide in-depth technical information pertaining to specific areas of the porting task. In addition to this guide, the HP-UX/SunOS Interoperability Cookbook is available to aid the system administrator who manages a mixed SunOS and HP-UX networked environment. Hewlett-Packard has developed both the Porting Guide and the Interoperability Cookbook to help you take advantage of real open systems multi-vendor environments. ----------------------------------------------------------------------------- Standards Directions SunOS 4.1.3 is an implementation of the Berkeley BSD 4.3 operating system. The Solaris 2.x operating system is based on Novell UNIX System V.4. The HP-UX UNIX operating system is based on open systems standards. HP-UX passes: * System V Verification Suite (SVVS). * X/Open XPG4. * POSIX 1003.1, 1003.2. * OSF AES. Also, selected BSD4.2 and BSD4.3 extensions have been added to HP-UX to ease the migration of BSD-based applications to HP-UX. The top goals of each HP-UX release are to provide binary compatibility, a high level of portability to other environments, tracking standards, and quality. Even though HP-UX is and has been an implementation of UNIX System V, since the conception of Common Open Software Environment (COSE), System V and POSIX are no longer the target for application portability. The target today is X/Open (COSE Spec.1170). intro-2 ----------------------------------------------------------------------------- X/Open -- COSE Spec.1170 HP, along with IBM, Novell, and SunSoft announced at the March 17, 1993 UniForum Conference in San Francisco their intent to deliver a common open software environment (COSE) across multiple UNIX system platforms. Since this announcement, these companies have worked with the industry to create two important technologies to unify the UNIX operating environment: * The Common Desktop Environment (CDE). * A Single Specification for UNIX commonly known as the Spec.1170 Application Programming Interface (API). The long-term success of the COSE process was assured when HP, along with the other companies, helped restructure the Open Software Foundation (OSF) and incorporated the COSE process as a formal part of the OSF. These technology projects are now referred to as Pre-Structured Technology Projects, or PSTs. The intent of Spec.1170 was to define a common API across the various implementations of the UNIX operating system. Because COSE was a process and not an organization, it could not be in the API standards business. Therefore, these companies worked closely with X/Open to have Spec.1170 formally reviewed by the industry and adopted as the Single Specification for the UNIX operating system. In August of 1994, X/Open adopted Spec.1170 as XPG4 Issue 4, version 2 (XPG4.2). X/Open is in the process of creating a verification test suite and branding program. At publishing time, no vendor is fully XPG4.2 compliant. X/Open will introduce this program in the spring of 1995, with most major vendors (including HP) branding their operating system as UNIX-compliant by the end of 1995. It is very important to note that HP-UX, as well as most other vendors' operating systems, fully supports most of the APIs defined in XPG4.2 (HP-UX already contains 85% to 90% of the Spec.1170 APIs). XPG4.2 contains minor modifications to existing XPG4.1 interfaces, but primarily adds many common APIs found on most platforms. To the XPG4 base (about 50% of the APIs), additional APIs from Berkeley Software Distribution (BDS4.3), the OSF AES, and SVID Issue 3 have been added. Existing XPG4 interfaces have also been clarified. These additional APIs were added based on analysis of API calls made by the 50 leading applications that run on the UNIX operating system. ----------------------------------------------------------------------------- Common Desktop Environment 1.0 (CDE 1.0) Hewlett-Packard, IBM, Novell, and SunSoft are jointly developing and defining a consistent set of application programming interfaces (APIs) for a Common Desktop Environment (CDE) that can be implemented on operating environments that support X Windows and OSF Motif. This Common Desktop Environment provides end users with a consistent graphical user interface across workstations and PCs, and software developers with a single set of programming interfaces for HP-UX, AIX, Solaris, UnixWare and other UNIX system based platforms. This advanced environment will enable users to transparently access data and applications from anywhere in the network. intro-3 The CDE 1.0 specification incorporates existing technology from participating vendors and has been designed to support distributed, enterprise computing applications. As such, it will scale across a range of client/server platforms, support small workgroups to large enterprises, and support simple text and data uses as well as advanced collaborative multimedia applications. CDE 1.0 incorporates elements from HP's Visual User Environment (HP VUE), IBM's Common User Access model, SunSoft's OPEN LOOK DeskSet productivity tools, and Novell's UnixWare Client components. Specific technologies used by the developing companies include the X Window System (X11R5), OSF Motif toolkit, and SunSoft's ToolTalk interapplication communication with extensions to incorporate HP Encapsulator. Because most of this environment exists today, the companies have integrated key technologies available in the open marketplace and have innovated only where appropriate to give users and software developers a consistent UNIX desktop environment. ----------------------------------------------------------------------------- Where To Go From Here? So, where do you go from here, and how do you get there? Neither CDE nor X/Open XPG4.2 are available today on Sun or HP hardware, and you do not want to port your application to one UNIX platform, then have to port again in 12 months. Even though HP-UX does not have 100% of the X/Open and CDE interfaces today, HP-UX is closer than most UNIX platforms. HP-UX already supports XPG3 and XPG4.1. What X/Open XPG4.2 adds to the specification is: * Core APIs of BSD 4.3, OSF AES, and SVID Issue 3. * Sockets. * STREAMS. * Enhanced internationalization. Of these additions, HP-UX already supports all OSF AES and SVID Issue 3 APIs, and most of the core APIs of BSD 4.3. It already supports Berkeley sockets, and STREAMS is already a layered product. The biggest piece missing today on an HP-UX release is XPG4.2's enhanced internationalization APIs. The key application programming concerns of CDE are the graphics and windowing system environment. HP-UX is already shipping the windowing environment CDE (based on HP VUE) and the window programming environment (X11R5 and OSF/Motif). None of these interfaces are new to HP-UX. HP-UX has been shipping these industry-standard interfaces for years, providing a stable platform for all your open-systems solutions. HP-UX has a long tradition of and commitment to providing continuity between releases to minimize the impact of industry changes to our customers. 1-1 Chapter 1 Development Environment Overview This chapter describes differences between HP-UX and SunOS that you should understand before you begin to develop, compile, and debug programs on your HP-UX workstation. ----------------------------------------------------------------------------- Compilers Table 1-1: lists the standards that HP-UX 9.05 compilers support: Table 1-1: HP-UX 9.05 Compiler Standards Language Standard ============================================================================= C/ANSI C Kernighan and Ritchie POSIX C ANSI C ----------------------------------------------------------------------------- C++ USL/Novel 3.0. (HP C++ B2402 A.03.50 ----------------------------------------------------------------------------- Pascal HP ANSI/IEEE 770 HP NON ANSI HP Domain/Pascal ----------------------------------------------------------------------------- FORTRAN ANSI-77 MIL-STD 1753 FIPS PUB 69-1 ISO-1539-1980(E) ----------------------------------------------------------------------------- HP-UX also supports COBOL, ADA, and Basic. Compiler Versions ----------------- On HP-UX, compilers are typically not tied to minor OS releases. For example, there are no HP-UX 9.01, 9.03, and 9.05 versions of the C compiler. HP ships compilers as part of the "HP-UX Applications Release 9.0" CD separate from the OS. The latest version of a compiler is always recommended over earlier versions, because HP guarantees forward compatibility for both executables and libraries across new OS releases and compiler versions. Thus, if a library was built using an earlier version of a compiler, you can use that library with the latest version of the compiler without recompiling older libraries. New compiler versions are released to provide optimization improvements, fix defects, additional language features, and enhancements for new architectures. 1-2 You should always check your latest HP-UX Application Release 9.0 for new versions of the compilers. At publishing time of this manual (January 1995), the latest versions of the compilers could be found on the HP-UX 9.0 Applications Release, November 1994. Table 1-2: lists the compiler versions, which can be verified using the what(1) command. Table 1-2: Compiler Versions Compiler Version Location ============================================================================= C A.09.61 /bin/cc C++ A.03.50 /usr/bin/CC FORTRAN 09.16 (DART 16) /usr/bin/f77 Pascal A.09.12 /usr/bin/pc ----------------------------------------------------------------------------- Compiler Licensing ------------------ Compilers are licensed on a per-node basis, not per process. If your system has a licensed compiler, you have the right to run as many synchronous compiles as required for your environment. This allows multiple developers to share a single HP 9000 Series 700/800 as a compile server. Location of Compilers --------------------- Unlike SunOS, where compilers are typically versioned under /usr/lang, HP-UX compilers are not versioned and the C compiler does not require two separate compilers for K&R and ANSI support. By default, the K&R compiler mode is used. The ANSI compiler mode is invoked by executing: /bin/cc -Aa See "C Compiler" on pageÊ2-1 for more details. The compilers are usually located in /usr/bin or /bin. The C compiler is /bin/cc. Other compilers, if they are installed, are located in /usr/bin. See Table 1-2:. By default, the C compiler shipped with the standard release is not a fully functional C. This compiler (the "bundled" compiler) is provided for system administration purposes and is used to rebuild the kernel. The easiest way to determine which compiler you are using is to examine the C compiler what string. If the string contains the word Bundled, then the fully functional development compiler has not been installed on your system. For example, if you execute what /bin/cc, the following would indicate the development compiler is not installed: /bin/cc: HP92453-01 A.09.19 HP C (Bundled) Compiler The following would indicate the development compiler is installed: /bin/cc: HP92453-01 A.09.61 HP C Compiler 1-3 Compiler Directives ------------------- HP-UX supports many industry application programming interfaces (APIs). On HP- UX, compiler directives are used to enforce compliance to a particular standard. This is accomplished by only allowing the particular system calls associated with the standard to be defined in the program name space. The directives supported by the C and C++ compilers are listed in Table 1-3:. Table 1-3: C and C++ Compiler Directives and their SunOS Counterparts SunOS 4.1.x SunOS 5.x HP-UX 9.x Notes ============================================================================= _POSIX_SOURCE _POSIX_SOURCE _POSIX_SOURCE Posix source. ----------------------------------------------------------------------------- _XOPEN_SOURCE _XOPEN_SOURCE X/Open source. ----------------------------------------------------------------------------- __STDC__ __STDC__ Standard C. ----------------------------------------------------------------------------- _HPUX_SOURCE HP-UX with BSDisms. ----------------------------------------------------------------------------- _AES_SOURCE OSF AES source. ----------------------------------------------------------------------------- _cplusplus A C++ compiler directive that is automatically turned on by HP-UX C++ to include C++ header file prototypes. ----------------------------------------------------------------------------- The HP-UX compiler directive that most closely corresponds to SunOS developed code is _HPUX_SOURCE. Therefore, this directive will probably be required to directly port SunOS-developed software to HP-UX. The HP-UX C++ and the non- ANSI HP-UX C compilers automatically predefine this namespace. HP-UX ANSI C does not predefine the namespace. You must define it explicitly on the compile line: cc -Aa -D_HPUX_SOURCE . . . In the above compile line, the -Aa option turns on ANSI mode for the C compiler. Unlike SunOS, HP-UX ships one C development compiler, which supports both K&R C and ANSI C. See "SunOS to HP-UX C Compiler Options Cross Reference" on pageÊ2-8 or the cc man page for more information. Also, compiler options -Aa -D_HPUX_SOURCE are equivalent to compiler option -Ae. So, ANSI C code developed on SunOS could also use the compile line: cc -Ae . . . ----------------------------------------------------------------------------- Location of Files and Utilities C and C++ Header Files ---------------------- SunOS header files are typically versioned in: /usr/lang/SCx.x.x/include 1-4 These are separated into C and C++ version directories. Under HP-UX, with one exception, only one set of header files is installed, and the files support both C and C++. They are installed in: /usr/include The HP C++ compiler automatically includes the -D_cplusplus directive to include the C++ prototypes. The one exception is that HP does ship a few C++ specific headers, which are located in: /usr/include/CC The HP C++ compiler knows to search in this directory for necessary headers prior to searching /usr/include, without specifically declaring -I/usr/include/CC on the compile line. X11 and Motif Header Files -------------------------- To accommodate applications designed with different X11 and Motif versions, HP-UX has separated the X11 and Motif header files. Developers must specify on the compile line the version the application depends upon. HP-UX has the following X11 and Motif directory structure: Table 1-4: X11 and Motif Directory Structure Version Location ============================================================================= X11R4 /usr/include/X11R4/X11 X11R5 /usr/include/X11R5/X11 Motif1.1 /usr/include/Motif1.1/[Mrm, Xm, Xv, uil] Motif1.2 /usr/include/Motif1.2/[Mrm, Xm, Xv, uil] ----------------------------------------------------------------------------- An example of the compiler options that specify the correct version follows: -I/usr/include/X11R5 -I/usr/include/Motif1.2 System Libraries ---------------- HP-UX system libraries are located under /lib and /usr/lib, where /lib contains all the libraries required by the OS to run, and /usr/lib contains libraries for all layered (separately obtained) products. By default, the linker will search for libraries in these two directories. X11 and Motif Libraries ----------------------- As with system header files, in order to accommodate applications built with different X11 and Motif revisions, HP-UX has separated the X11 and Motif libraries. Developers must specify on the compile or link line which versions the application depends upon. 1-5 HP-UX has the following X11 and Motif library directory structure: Table 1-5: X11 and Motif Library Directory Structure Version Location ============================================================================= X11R4 /usr/lib/X11R4 X11R5 /usr/lib/X11R5 Motif1.1 /usr/lib/Motif1.1 Motif1.2 /usr/lib/Motif1.2 ----------------------------------------------------------------------------- This structure requires that the developer modify the link options to specify the correct versions. For example: -L/usr/lib/X11R5 -L/usr/lib/Motif1.2 Other Utilities --------------- Table 1-6: Location of Other Utilities Utility Location ============================================================================= ar /bin cpp (1) /lib cpp.ansi (1) /lib imake (2) /usr/contrib/mitX11R5/bin lex (3) /usr/bin lin (3) /usr/bin ln /bin make /bin ranlib (4) /bin rcs (3) /usr/bin (rcs, ci, co, rcsdiff, rcslog, ...) sccc (5) /usr/bin yacc (3) /usr/bin (1) cpp is the C preprocessor used for K&R C. cpp.ansi is the default C processor used for ANSI C. (2) imake is not an HP-UX supported tool, although it is available from several sources. See Chapter 3 and Appendix A for discussions on imake. (3) lex, lint, rcs and yacc are installed with the development environment. (4) ranlib is not required but is included for backwards compatibility. (For more information, see Chapter 4, "Libraries 4.") (5) SCCS interfaces (get, delta, admin, ...) are located in /usr/bin. The Berkeley sccs command is available as a patch in HP-UX patch PHCO_4583 and includes: /usr/bin/sccs /usr/man/man1.Z/sccs.1 ----------------------------------------------------------------------------- 1-6 Debug Environment ----------------- HP provides four debuggers for HP-UX 9.05. In addition, the internet source code libraries offer the GNU debugger, gdb. The debuggers available from HP are: HP/DDE HP Distributed Debugging Environment (HP/DDE) is a high-level language debugger with an OSF/Motif interface. HP/DDE is available with the HP ProgrammerÕs Toolset (HP part no. B3478AB/B3473AB), or with HP SoftBench. HP/DDE is the recommended debugger for all software developers new to HP-UX. xdb HPÕs symbolic source level debugger for C, C++, FORTRAN, and Pascal. The interface runs in a terminal window. xdb is shipped with the HP Programming Environment. When you purchase an HP-UX compiler, you also get xdb. adb Known as an absolute debugger, adb typically is used for assembly language debugging and kernel patching. See the "ADB Tutorial" (HP part no. 92432-90006) for more information. Softdebug The HP SoftBench program debugger is available only with the HP SoftBench CASE tool framework. Softdebug offers an easy-to-use graphical user interface to either xdb or HP/DDE, and hooks with other HP SoftBench software development tools. ----------------------------------------------------------------------------- HP LaserROM/UX HP LaserROM/UX is similar to SunOSÕs AnswerBook. The key differences between the two products are: * Searched keywords are highlighted in HP LaserROM/UX. * The entire manual set is on HP LaserROM/UX (for all products, not just installed products). * HP LaserROM/UX can be remote displayed to any X11 server. HP LaserROM/UX is very useful for all HP-UX users. It is especially useful for performing keyword searches for SunOS commands you could readily locate on your HP-UX system. HP LaserROM/UX has two user interfaces: a graphical user interface and a character-mode user interface. Both user interfaces allow you to access information on compact disks. NOTE: The HP part no. for HP LaserROM/UX (including CD-ROM documentation) is B2355B. 1-7 ----------------------------------------------------------------------------- HP-UX Patches If you are currently using the latest compilers, there are only a few patches which you need to consider for your development system. The "Compiler Versions" section above describes the latest compiler versions to date. As stated, always run the latest version of the HP compilers. The below list of patches is not complete. It is good practice to keep track of any new HP-UX patch. For example, MIT releases new run time and development X11 libraries every 3 months. HP-UX in turn releases these updates to its customers in the form of a patch every 3 months. Keeping track of new patches is a fairly simple task, and can be accomplished by quickly scanning for new patches using the HP Mosaic Patch Server. For more information, see Chapter 9, "HP on the Net." Table 1-7: Patches ============================================================================= PHCO_4762 /bin/make patch. PHCO_4502 curses library patch. PHCO_4583 Berkeley sccs(1) command. PHNE_4431 Increases rpc(1) socket buffer size from 8k to 32k. PHNE_4879 NFS and NIS mega patch. PHSS_4716 Series 700/800 cumulative ld(1) patch. ----------------------------------------------------------------------------- ----------------------------------------------------------------------------- SunOS to HP-UX Porting References * "HP LaserROM/UX" (HP part no. B2355B). * "HP-UX Portability Guide" (HP part no. B2355-90625). * "HP-UX Reference, Release 9.0, Volume 2" (HP part no. B2355-90033). * "HP-UX Driver Development Guide" (HP part no. 98577-90014). * "P-UX Floating-Point Guide" (HP part no. B2355-90024). * "How HP-UX Works: Concepts for the System Administrator" (HP part no. B2355-90029). * "Programming on HP-UX" (HP part no. B2355-90026). * "HP Precision Architecture and Instruction Set Reference Manual" (HP part no. 09740-90014). * "PA-RISC Procedure Calling Conventions Reference Manual," Edition 2 (HP part no. 09740-90015). * "ASSEMBLY LANGUAGE Reference Manual" (HP part no. 92432-90001). 1-8 * "HP Pascal/HP-UX ProgrammerÕs Guide" (HP part no. 92431-90006 "HP Pascal/HP-UX Reference Manual" (HP part no. 92431-90005 "HP Pascal/HP-UX Release Notes" (HP part no. B2415-90001). * The SUN manual pages, sections 2, 3 and 4. * "HP-UX/SunOS Interoperability Cookbook" (contact your HP Sales Representative and reference LDC 5962-9867E). * "Advanced Programming in a UNIX Environment" (W. Richard Stevens Addison-Wesley, ISBNÊ#Ê0-201-56317-7). * Various usenet newsgroups: comp.sys.hp.hpux comp.sys.hp.apps * Application-specific newsgroups, such as comp.graphics or comp.windows.x.motif. 2-1 Chapter 2 Compilers This chapter discusses the following compilers: * C * C++ * FORTRAN * Pascal * GNU gcc/g++ NOTE: The HP-UX Portability Guide describes many general portability concerns, such as data types, memory alignment, and how to write portable applications. This chapter should be used in conjunction with the HP-UX Portability Guide. ----------------------------------------------------------------------------- C Compiler Product Overview ---------------- The current C compiler revision (as of January 1995) is "HP 92453-01 A.09.61 HP C Compiler." To check the revision, execute: what /bin/cc HP C/ANSI C on HP-UX (hereafter referred to as HP C) is Hewlett-Packard's implementation of the C language for the HP 9000 Series 700/800. The compiler runs in two modes: full ANSI mode, or Kernighan and Ritchie (K&R) mode, sometimes referred to as compatibility mode: * K&R mode (-Ac) is the default mode. It is provided for programs that rely on certain non-standard behaviors of pre-ANSI compilers or preprocessors, including previous releases of HP C that do not conform to the ANSI standard. * ANSI modes (-Aa and -Ae) accepts ANSI standard code. ANSI is the recommended mode of compilation. The C compiler consists of a front-end that converts source code into an "intermediate code representation" common to all the HP-UX compiler languages. Each compiler language front-end interfaces to a common optimizing back-end. By sharing a common back-end (which performs the bulk of optimization and machine code generation) each compiler delivers optimal code, independent of the language-dependent front-ends. 2-2 Key Features ------------ The C compiler adheres to industry standards and includes the following features: * The C preprocessor, header files, and libraries (not just the compiler itself) also meet the requirements of the ANSI standard. * The -Ae command line option provides an extended ANSI mode that combines ANSI C with extensions. This option is the same as specifying -Aa, -D_HPUX_SOURCE, and +e, which enables the sized enum and $ in identifier extensions. * All ANSI diagnostics are provided as specified by the standard. * HP ANSI C respects name space requirements and adds no additional keywords to the language. * The +ESlit command line option places string literals and constants into read-only text storage. * The +ESsfc command line option replaces function pointer comparison millicode calls with inline code. * Multi-byte character and wide-character support are provided. * New optimization options provide faster runtime as well as increased flexibility in tuning your application for the best possible performance. (For more details on optimization, see the following section.) Performance and Optimization ---------------------------- For many C programmers, performance is an important factor in their development efforts. The HP C optimizer transforms programs so machine resources are used more efficiently. The optimizer can dramatically improve application run-time speed. HP C performs only minimal optimizations unless you specify otherwise. You activate additional optimizations using command line options. Trade-offs between compiler time, code expansion and execution performance can be balanced to best satisfy your particular requirements. Profile based optimization (PBO) also gives increased performance. (See "Profile-based Optimization" on page -13.) 2-3 There are four major levels of optimization: * Level 1 is very quick optimization on one file. * Level 2 (or -O) is traditional optimization on one file. * Level 3 is extensive optimization on one file. * Level 4 is a superset of the other levels; it is an extensive optimization over the entire program. Level 4 optimization can produce the fastest executable code. Additional parameters enable you to control the size of the executable program, compile time, and aggressiveness of the optimizations performed. NOTE: See the C compiler man page for the optimization features associated with each level. Compile time, memory, and CPU usage increase with each higher level of optimization due to the increasingly complex analysis that must be performed. You can control the trade-offs between compile-time increases and code performance by choosing the level of optimization you desire. Generally, the optimizer is not used during code development. It is used when compiling production-level code for benchmarking and general use. In addition to the global optimization changes, HP has implemented new advanced optimization options: +Olibcalls and inline alloca (). NOTE: For specific optimization information dealing with the C compiler itself, refer to Chapter 4 of the HP C Reference Manual. Shared Library Support ---------------------- HP-UX shared libraries typically have the .sl suffix. SunOS shared libraries typically have the .so suffix. To conserve swap space, the C compiler supports shared libraries. Rather than copying the program- specified library routines into the executable, links to the library routines are created in the executable file. By activating these links at execution time, the size of the application's executable file is reduced. Beyond the disk space savings, sharing these routines across multiple executables reduces the virtual memory requirements as well. C Compiler Ordering Information ------------------------------- To order the C compiler or other HP products, call 1-800-637-7740 (in Canada, call 1-800-387-3867), or contact your local HP sales office or authorized HP reseller. 2-4 The following table lists the 9.05 HP C/ANSI C products for any HP-UX 9.05 operating system: HP C++ Products Product Description ============================================================================= HP part no. B2354A - S700 C C/ANSI C compiler and XDB debugger Developer's Bundle License-to-Use HP-UX Developer's Toolkit General Programming Tools ----------------------------------------------------------------------------- HP part no. B2412A - S800 C C/ANSI C compiler and XDB debugger Standalone Compiler License-to-Use for HP 9000 Series 800 ----------------------------------------------------------------------------- HP part no. B2413A - S700 C C/ANSI C compiler and XDB debugger Standalone Compiler License-to-Use for HP 9000 Series 700 ----------------------------------------------------------------------------- NOTE: The B2354A product does not bundle manuals under the C compiler. Manuals can be ordered separately under "HP-UX 9.0 Documentation" (HP part no. B2355B). ----------------------------------------------------------------------------- C Language Tips and Traps This section lists the differences between the HP C compiler and the Sun C compiler. Reference: HP-UX Portability Guide (HP part no. B2355-90625), chapters 4 and 5. ANSI C Compiler Compile Line -------------------------------- The SunOS 4.1.3 ANSI C compiler line differs from that of the HP-UX ANSI C compiler. HP-UX supports many BSD system and library calls, but not by default. When compiling under ANSI mode, header files define only those names specified by the standard. To get the same name space that defines these BSD- isms, define the symbol _HPUX_SOURCE. Avoid explicitly defining _INCLUDE_HPUX_SOURCE, as this does not always have the desired effect. cc -Aa ... -D_HPUX_SOURCE .... The -Aa above turns on ANSI C compliance. For convenience, cc -Ae is the equivalent of the following: cc -Aa -D_HPUX_SOURCE ... The man page for cc says the following about -Ae: "Extended ANSI mode. Same as -D_HPUX_SOURCE and -Aa and allows the following extensions: $ characters can appear in identifier names, and enum declarations can include integral type specifiers. Additional extensions may be added to this option in the future." 2-5 Although not recommended, in a makefile the C compiler can be assigned to c89 to provide POSIX/ANSI compliance without adding the -Aa flag: CC = c89 c89 is in fact hard linked to cc. The different name indicates to the compiler that it should switch to ANSI mode. NOTE: See "SunOS to HP-UX C Compiler Options Cross Reference" on page 2-8. Compiler Warning: Could Not Find Include File sys/filio.h --------------------------------------------------------- filio.h is a SUN specific include file and is not available. Most of the contents of filio.h are available in ioctl.h. The following workaround can be used: #ifdef __hpux #include #else #include #endif File and device I/O controls differ between SYSV and BSD. See Appendix F, the "System and Library Command Cross Reference" for more information. PATH_MAX Not Defined -------------------- Use pathconf(2) function to obtain this information. SIG_PF Not Found ---------------- Use the following macro: #define SIG_PF (void(*)(int)) S_un Undefined Member on HP-UX ------------------------------ HP-UX's netinet/in.h does not include a definition for the "S_un" type. Use the following workaround: struct in_addr { union { struct { u_char s_b1,s_b2,s_b3,s_b4; } S_un_b; struct { u_short s_w1,s_w2; } S_un_w; u_long S_addr; } S_un; } #define s_addr S_un.S_addr 2-6 Problems -------------------- On HP-UX, is supplied only for backward compatibility with older HP-UX applications. Instead use . on HP-UX is equivalent to on SunOS. Unexpected Symbols: u_long, u_short ----------------------------------- These BSD defines are not available in the standard compiler options. To define these BSD defines, include -D_HPUX_SOURCE on the compile line: CPPFLAGS = -I$(...)/... -I... -D_HPUX_SOURCE ANSI C and Include File ----------------------------------- Several compilation errors occur when compiling a C file with the ANSI-C switch -Aa. Because Sockets is a BSD interface, you need to include the BSD name space. Simply add -D_HPUX_SOURCE to CFLAGS in the Makefile. See "ANSI C Compiler Compile Line" on page 2-4. Compiler Fails With "Not Enough Space" Message ---------------------------------------------- The Not enough space system error occurs when a process attempts to exceed the maximum size of the data segment. This message indicates that the compiler is unable to allocate enough memory to compile the program unit. By default, the maximum size of the data segment of an executing process is 64Mb. If your process needs a larger data segment, run the System Administrator Manager (sam) to increase the MAXSIZ kernel parameter (see the HP-UX System Administration Tasks manual, Chapter 11). You may also need to increase swap space and/or the MAXSWAPCHUCKS kernel parameter. See "Large Data Space Processes" on page 8-11 for more information. Large Executable Dumps Core --------------------------- If a large executable (80 Mbytes, for example) crashes in a core dump with a "segmentation violation," your program probably ran out of data space. See "Large Data Space Processes" on page 8-11. Error Message: Too Many Defines ------------------------------- If you are using version A.09.61 or later of the C compiler, you should never see this error message. If you are using an earlier compiler, use the -Wp,-H where is the number of bytes to add to cpp's table size. For example: -Wp,-H500000 2-7 Null Pointer Dereferencing -------------------------- Dereferencing a NULL pointer is not a good programming practice. HP-UX cc provides the ability to set the runtime behavior of this situation on the compile line. To disallow this behavior and force a SEGV, the -z flag should be used. ----------------------------------------------------------------------------- MIN and MAX header file differences The difference between HP-UX fast MIN and MAX macros and those on SunOS is that SUN does an: #ifndef ... where HP-UX just goes ahead and defines it. This will occasionally cause error messages. The SunOS 4.1.3 /usr/include/sys/param.h has: /* * Macros for fast min/max. */ #ifndef MIN #define MIN(a,b) (((a)<(b))?(a):(b)) #endif #ifndef MAX #define MAX(a,b) (((a)>(b))?(a):(b)) #endif The HP-UX /usr/include/sys/param.h has: /* * Macros for fast min/max. */ #define MIN(a,b) (((a)<(b))?(a):(b)) #define MAX(a,b) (((a)>(b))?(a):(b)) ----------------------------------------------------------------------------- TCGETS and TCSETS HP-UX is missing TCSETS and TCGETS ioctl() operations. The standard way to perform the TCGETS and TCSETS operations is to use the functions tcgetattr() and tcsetattr(). Those functions are specified in several standards and provided in HP-UX and Solaris. 2-8 ----------------------------------------------------------------------------- SunOS to HP-UX C Compiler Options Cross Reference This cross-reference should not be used in place of the system man pages and reference manuals. Please refer to the following references for additional information: * cc(1) man page * cpp(1) man page * ld(1) man page * HP-UX Portability Guide. Refer to Chapter 4, "Porting from BSD4.3 to HP-UX," and Chapter 5, "Porting C Programs." NOTE: The C compiler provided as part of the standard HP-UX operating system is not a development C compiler. It is supplied as a standard component of the OS for the purpose rebuilding the HP-UX kernel. The kernel C compiler is a K&R compiler which does not support the options -A, -G, -g, -O, -p, -v, -y, +z, and +Z. The following option is recognized only by cc: -Amode Specify the compilation standard to be used by the compiler. Mode can be one of the following letters: c (Kernighan and Ritchie). This option is currently the default. This mode is also known as compatibility mode. a Compile under ANSI mode. When compiling under ANSI mode, header files define only those names specified by the standard. To get the same name space as in K&R mode (compatibility mode, -Ac), define the symbol _HPUX_SOURCE. Note that the -W option is used to pass arguments to subprocesses. It is analogous to SunOS's -Qoption compiler option. The following C compiler directives are supported: Table 8-8: C and C++ Compiler Directives and their SunOS Counterparts SunOS 4.1.x SunOS 5.x HP-UX 9.x Notes =========================================================================== _POSIX_SOURCE _POSIX_SOURCE _POSIX_SOURCE Posix source. --------------------------------------------------------------------------- _XOPEN_SOURCE _XOPEN_SOURCE X/Open source. --------------------------------------------------------------------------- __STDC__ __STDC__ Standard C. --------------------------------------------------------------------------- _HPUX_SOURCE HP-UX with BSDisms. --------------------------------------------------------------------------- _AES_SOURCE OSF AES source. --------------------------------------------------------------------------- _cplusplus A C++ compiler directive that is automatically turned on by HP-UX C++ to include C++ header file prototypes. --------------------------------------------------------------------------- 2-9 Every standard defines a namespace (a set of names defined by the standard). Most guarantee that all other symbols are available. If, for example, you want to write POSIX compliant source, you are free to use the symbol timezone without restriction, even if you include to get the prototype for time(). That is part of what POSIX guarantees, therefore the header file is not allowed to provide a conflicting declaration for the symbol timezone if you are compiling for POSIX compliance. However, X/OPEN specifies that should include a declaration of a variable called timezone if you are compiling for X/OPEN compliance. Therefore, a mechanism is needed to tell header files which standard's namespace you wish to use. Most standards accomplish this by defining a macro like _POSIX_SOURCE. If you define this macro in your compilation, you are guaranteed a POSIX compliant namespace -- hence you don't get a declaration of timezone. If you define the corresponding _XOPEN_SOURCE, you do get the declaration. When compiling in ANSI mode, all you get by default is the raw ANSI namespace. This doesn't include, for example, open(). Since most standards form subsets of each other, the easiest way to implement this is via internal macros of the form _INCLUDE_POSIX_SOURCE et al. Defining _XOPEN_SOURCE automatically turns on both _INCLUDE_POSIX_SOURCE and _INCLUDE_XOPEN_SOURCE because X/OPEN is, in general, a superset of POSIX. The _INCLUDE_*_SOURCE macros are therefore for internal use only. Users should define only the _*_SOURCE versions. To get the full HP-UX namespace use _HPUX_SOURCE, which turns on everything else. See stdsyms(5) for more detail. C Compiler Options Cross Reference ---------------------------------- Table 8-9: C Compiler Options Cross Reference SunOS C Compiler HP-UX 9.05 C Option or Flag and ANSI C Comments ============================================================================= -a Not available. ----------------------------------------------------------------------------- -assertx Not available. ----------------------------------------------------------------------------- -align Not available. ----------------------------------------------------------------------------- -Bdynamic -Wl, -a, shared Link with shared libraries (*.sl). ----------------------------------------------------------------------------- -Bstatic -Wl, -a, archive Link with archive libraries (*.a). ----------------------------------------------------------------------------- -bsdmalloc Not available. ----------------------------------------------------------------------------- -C Same. ----------------------------------------------------------------------------- -c Same. ----------------------------------------------------------------------------- -cg87 Not applicable. Sun-4 option. ----------------------------------------------------------------------------- 2-10 ----------------------------------------------------------------------------- -cg89 Not applicable. Sun-4 option. ----------------------------------------------------------------------------- -cg92 Not applicable. Sun-4 option. ----------------------------------------------------------------------------- -dalign Not applicable. This is the default on HP-UX. ----------------------------------------------------------------------------- -dryrun Not available. ----------------------------------------------------------------------------- -Dx Same. -Dname. ----------------------------------------------------------------------------- -d Not available. ----------------------------------------------------------------------------- -E Same. ----------------------------------------------------------------------------- -fast -O ----------------------------------------------------------------------------- -fnonstd +FPstring See ld(1) +FP option. ----------------------------------------------------------------------------- -fsingle +f K&R mode only. ----------------------------------------------------------------------------- -g Same. ----------------------------------------------------------------------------- -go Not available. ----------------------------------------------------------------------------- -H -Wp, -H Support for the ANSI and C++ compilers only. Not available in HP-UX C K&R mode. ----------------------------------------------------------------------------- -help Not available. ----------------------------------------------------------------------------- -keeptmp Not available. ----------------------------------------------------------------------------- -Ix Same. ----------------------------------------------------------------------------- -libmil Not available. ----------------------------------------------------------------------------- -lx Same. ----------------------------------------------------------------------------- -Lx Same. ----------------------------------------------------------------------------- -M mkmf(1) Use makefile generator .mkmf(1). ----------------------------------------------------------------------------- -misalign +u[num] ----------------------------------------------------------------------------- -native Not applicable. Done by default. ----------------------------------------------------------------------------- -nolib Not available. ----------------------------------------------------------------------------- -nolibmil Not available. ----------------------------------------------------------------------------- -native Not applicable. Done by default. ----------------------------------------------------------------------------- -noc2 Not available. ----------------------------------------------------------------------------- -o file Same. ----------------------------------------------------------------------------- -O[1,2,3,4] -Oopt opt includes 1, 2, 3, E, m1, s, & V. ----------------------------------------------------------------------------- 2-11 ----------------------------------------------------------------------------- -O Same. Same as -O2. ----------------------------------------------------------------------------- -P Same. ----------------------------------------------------------------------------- -PIC +Z ----------------------------------------------------------------------------- -p Same. ----------------------------------------------------------------------------- -pg -G ----------------------------------------------------------------------------- -pic +z ----------------------------------------------------------------------------- -pipe Not available. ----------------------------------------------------------------------------- -Qdir x -tx, name ---------------------------- -Qpath x -tx, name Where x is the symbol of the ---------------------------- replaced process. -qdir x -tx, name ---------------------------- -qpath x -tx, name ----------------------------------------------------------------------------- -Qoption cpp x -Wp, opt ----------------------------------------------------------------------------- -Qoption iropt Not available. ----------------------------------------------------------------------------- -Qoption cg x Not available. ----------------------------------------------------------------------------- -Qoption inline x Not available. ----------------------------------------------------------------------------- -Qoption as x -Wa, opt ----------------------------------------------------------------------------- -Qoption asS x Not available. ----------------------------------------------------------------------------- -Qoption ld x -Wl, opt ----------------------------------------------------------------------------- -Qproduce .o -c ----------------------------------------------------------------------------- -Qproduce .s -S ----------------------------------------------------------------------------- -Qproduce .c Not available. ----------------------------------------------------------------------------- -Qproduce .i -P ----------------------------------------------------------------------------- -R Not available. ----------------------------------------------------------------------------- -r -Wl, -r ----------------------------------------------------------------------------- S Same. ----------------------------------------------------------------------------- -s Same. ----------------------------------------------------------------------------- -sb -y, -yscan HP SoftBench options. ----------------------------------------------------------------------------- -strconst +ESlit ----------------------------------------------------------------------------- -sun2 Not applicable. Sun-2 option. ----------------------------------------------------------------------------- 2-12 ----------------------------------------------------------------------------- -sun3x Not applicable. Sun-3 option. ----------------------------------------------------------------------------- -sun386 Not applicable. Sun-386 option. ----------------------------------------------------------------------------- -sun3 Not applicable. Sun-3 option. ----------------------------------------------------------------------------- -sun4c Not applicable. Sun-4 option. ----------------------------------------------------------------------------- -sun4 Not applicable. Sun-4 option. ----------------------------------------------------------------------------- -sys5 Not applicable. This is the default. ----------------------------------------------------------------------------- -target x +DAarchitecture, Valid PA-Risc architectures +DSarchitecture are 1.0 and 1.1. ----------------------------------------------------------------------------- -temp=dir Not available. Use TMPDIR environment variable. ----------------------------------------------------------------------------- -time Not available. ----------------------------------------------------------------------------- -u -Wl, -u symbol ----------------------------------------------------------------------------- -unroll=n Same. FORTRAN option, -WP, -unroll=n. ----------------------------------------------------------------------------- -Ux Same. ----------------------------------------------------------------------------- -V Not available. ----------------------------------------------------------------------------- -v Same. ----------------------------------------------------------------------------- -vc -w[1|2|3] ----------------------------------------------------------------------------- -w Same. ----------------------------------------------------------------------------- -X[t,a,c,s] -Ac or -Aa Also -D_HPUX_SOURCE, -D_XOPEN_SOURCE, -D_POSIX_SOURCE. ----------------------------------------------------------------------------- ----------------------------------------------------------------------------- C++ Compiler Overview of HP C++ Version A.03.50 ---------------------------------- HP C++ is the implementation of the C++ programming language on HP 9000 Series 700 and 800 systems. Version A.03.50 runs on HP-UX 9.0x. It is based on release 3.0.3 of the USL/Novel C++ translator, which transforms C++ source text into C code. In addition to USL/Novel C++ 3.0.2, HP C++ 3.0 supports exception handling as specified in the ANSI C++ base document. USL has chosen to incorporate HP's implementation of exception handling into its next release of C++. HP's implementation of exception handling, available from HP today, will therefore become the standard for exception handling. 2-13 While other vendors offer a C++ to C translator, HP C++ includes a compiler. The C++ compiler produces code that has better quality and also significantly improves the speed of compilation. Additionally, the facility for translation to C code is included for those who prefer this mechanism. HP C++ is integrated with the system linker, eliminating the need for a second pass. For details on the differences between USL/Novel versions 3.0.2 and 3.0.3 please read the "Release Notes" section of the USL C++ Language System Release 3.0 manual (HP part no. 92501-90001) shipped with this product. HP C++ Run-Time Libraries ------------------------- The libC.sl and libC.a libraries are the HP C++ run-time libraries. These libraries contain the USL C++ 3.0 iostream library functionality and support for run-time memory management. Either libC.sl or libC.a is automatically linked by the HP C++ driver program CC depending upon whether you are creating a shared or archived executable. The default is to link in shared versions of libC.sl. You must use the -Wl,- a,archive option to create an archived C++ executable. The ANSI C versions of this library (libC.ansi.sl and libC.ansi.a) are also included. If you have compiled your objects with the +a1 option, you must also pass this option to the CC link command. The CC driver will automatically select the ANSI C library instead of the K&R library. HP C++ Compiler Ordering Information ------------------------------------ To order the C++ Compiler or other HP products, call 1-800-673-7740 (in Canada, call 1-800-387-3867), or contact your local HP sales office or authorized HP reseller. HP C++ is sold on a user-based license. You need to purchase a license for each person using C++. Media and documentation are purchased separately for licenses. Table 8-10: HP C++ Compiler Ordering Information Part Number Product ============================================================================= HP part no. B2402A HP C++ 3.0 license-to-use. Includes C++ compiler and xdb debugger. -- option 0AN -- license-to-use HP C++ on 1 seat -- option 0A9 -- license-to-use HP C++ on 10 seat -- option 0AG -- license-to-use HP C++ on 25 seat -- option 0AA -- license-to-use HP C++ on 50 seat ----------------------------------------------------------------------------- HP part no. B2403A Media and codeword certificate. ----------------------------------------------------------------------------- 2-14 C++ Compiler Tips and Traps --------------------------- This section lists the differences between the HP C++ compiler and the Sun C++ compiler. The current C++ Compiler revision (as of January 1995) is HP C++ B2402 A.03.50. To check the revision, execute: what /usr/bin/CC --- C++ Compiler Compile Line The SunOS 4.1.x ANSI C++ compiler line may differ from that of the HP-UX ANSI C++ compiler compile line. Unlike the HP-UX C compiler, the HP-UX C++ compiler supports many BSD system and library calls by default. You do not need to include the -D_HPUX_SOURCE on your C++ compile line. You may need to include the +a1 option. This option enables many ANSI features of the C++ compiler: CC ... +a1 --- c_varieties.h The following are defined in c_varieties.h on SunOS 4.1.x. They do not exist on SunOS 5.x or HP-UX, and should not be used because they are not forward compatible. See c_varieties.h on SunOS 4.1.3 for more details and an example of the correct format. # define EXTERN_FUNCTION( rtn, args ) rtn args # define DOTDOTDOT ... # define _VOID_ void --- Null Pointer Differences The Sun C++ compiler treats NULL pointers differently from the HP C++ compiler. For example, the following code: char * foo=0; printf("The string is : %s\n", foo); Would produce the following: On HP-UX: The string is: On SunOS: The string is: (null) To force both systems to produce the same result, assign an empty string to foo: char *foo=""; 2-15 --- HP-UX's RPC Functions Are Not C++-ized You must modify to include: #ifdef __cplusplus extern C { extern int yp_bind(...); extern int _yp_dobind(...); extern void yp_unbind(...); extern int yp_get_default_domain (...); extern int yp_match (...); extern int yp_first (...); extern int yp_next(...); extern int yp_master(...); extern int yp_order(...); extern int yp_all(...); extern char *yperr_string(...); extern int ypprot_err(...); } #else : --- CC/setjmp.h Defect Change: jmp_buf * __EH_JMPBUF_TEMP; to: extern jmp_buf *__EH_JMPBUF_TEMP; --- Compiler Fails With "Not Enough Space" Message The Not enough space system error occurs when a process attempts to exceed the maximum size of the data segment. This message indicates that the compiler is unable to allocate enough memory to compile the program unit. By default, the maximum size of the data segment of an executing process is 64Mb. If your process needs a larger data segment, run the System Administrator Manager (sam) to increase the MAXSIZ kernel parameter (see the HP-UX System Administration Tasks manual, Chapter 11). You may also need to increase swap space and/or the maxswapchucks kernel parameter. See "Large Data Space Processes" on page 8-11 for more information. --- Large Executable Dumps Core If a large executable (80 Mbytes, for example) crashes in a core dump with a "segmentation violation," your program may have ran out of data space. See "Large Data Space Processes" on page 8-11. 2-16 SunOS to HP-UX C++ Compiler Options Cross Reference --------------------------------------------------- This cross-reference should not be used in place of the system man pages and reference manuals. Please refer to the following references for additional information: * C++ Online Help * ld(1) man page * C++ Programmer's Guide Note that the -W option is used to pass arguments to subprocesses. It is analgous to SunOS's -Qoption compiler option. The following C++ compiler directives are supported: Table 8-11: C and C++ Compiler Directives and their SunOS Counterparts SunOS 4.1.x SunOS 5.x HP-UX 9.x Notes ============================================================================= _POSIX_SOURCE _POSIX_SOURCE _POSIX_SOURCE Posix source. --------------------------------------------------------------------------- _XOPEN_SOURCE _XOPEN_SOURCE X/Open source. --------------------------------------------------------------------------- __STDC__ __STDC__ Standard C. --------------------------------------------------------------------------- _HPUX_SOURCE HP-UX with BSDisms. --------------------------------------------------------------------------- _AES_SOURCE OSF AES source. --------------------------------------------------------------------------- _cplusplus A C++ compiler directive that is automatically turned on by HP-UX C++ to include C++ header file prototypes. --------------------------------------------------------------------------- See "The following C compiler directives are supported:" on page 2-8 for notes on these directives. 2-17 SunOS C++ and HP-UX C++ Compiler Options ---------------------------------------- Table 8-12: C++ Compiler Options SunOS C++ HP-UX 9.05 C++ Comments Option or Flag ============================================================================= -a Not available. ----------------------------------------------------------------------------- -Bstatic -Wl, -a, archive Link archive library (*.a). ----------------------------------------------------------------------------- -Bdynamic -Wl, -a, shared Link shared library (*.sl). ----------------------------------------------------------------------------- -bsdmalloc Not available. ----------------------------------------------------------------------------- -c Same. ----------------------------------------------------------------------------- -cg87 +DA and +DS SunOS code gen & sched for 1987+ SPUs. ----------------------------------------------------------------------------- -cg89 +DA and +DS SunOS code gen & sched for 1989+ SPUs. ----------------------------------------------------------------------------- -cg92 +DA and +DS SunOS code gen & sched for 1992+ SPUs. ----------------------------------------------------------------------------- -dalign Not applicable. Sun-4 option. ----------------------------------------------------------------------------- -dryrun Not available. ----------------------------------------------------------------------------- -Dx Same. ----------------------------------------------------------------------------- +d Same. ----------------------------------------------------------------------------- +e0 Same. ----------------------------------------------------------------------------- +e1 Same. ----------------------------------------------------------------------------- -E Same. ----------------------------------------------------------------------------- -fast -O Optimize for speed. ----------------------------------------------------------------------------- -F Same. ----------------------------------------------------------------------------- -fnonstd +FPstring See ld(1) +FP options. ----------------------------------------------------------------------------- -g Same. ----------------------------------------------------------------------------- -G -b Build a shared library. ----------------------------------------------------------------------------- -H -Wp, -H ----------------------------------------------------------------------------- -h Not available. Names a shared dynamic library. ----------------------------------------------------------------------------- -help Not available. Displays information on cc. ----------------------------------------------------------------------------- -keeptmp +save Option not in HP-UX man page. ----------------------------------------------------------------------------- +i Same. ----------------------------------------------------------------------------- -Ix Same. Specifies include path. ----------------------------------------------------------------------------- 2-18 ----------------------------------------------------------------------------- -libmieee Not available. Selects IEEE 754 math library. ----------------------------------------------------------------------------- -libmil Not available. ----------------------------------------------------------------------------- -lx Same. ----------------------------------------------------------------------------- -Lx Same. ----------------------------------------------------------------------------- -misalign +u[num] ----------------------------------------------------------------------------- -native +DA and +DS Done by default. ----------------------------------------------------------------------------- -nolib Not available. ----------------------------------------------------------------------------- -nolibmil Not available. ----------------------------------------------------------------------------- -o file Same. ----------------------------------------------------------------------------- -O[1,2,3,4] +Oopt opt includes 1, 2, 3, E, m1, s, and V. ----------------------------------------------------------------------------- -O Same. Same as -O2. ----------------------------------------------------------------------------- -O4 Not available. Level 4 optimization. ----------------------------------------------------------------------------- +p Same. ----------------------------------------------------------------------------- -P Same. ----------------------------------------------------------------------------- -PIC +Z ----------------------------------------------------------------------------- -p Not available. ----------------------------------------------------------------------------- -pg -G ----------------------------------------------------------------------------- -pic +z ----------------------------------------------------------------------------- -pipe Not available. ----------------------------------------------------------------------------- -pta Same. ----------------------------------------------------------------------------- -ptn Same. ----------------------------------------------------------------------------- -ptr Same. ----------------------------------------------------------------------------- -pts Same. ----------------------------------------------------------------------------- -ptv Same. ----------------------------------------------------------------------------- -ql Not available. Profile with lprof. ----------------------------------------------------------------------------- -qp Not available. Profile with prof. ----------------------------------------------------------------------------- -Qdir x -tx, name Where x is the symbol of the replaced process. ----------------------------------------------------------------------------- -Qpath x -tx, name ----------------------------------------------------------------------------- 2-19 ----------------------------------------------------------------------------- -Qoption -W Pass option to compiler subprocess. ----------------------------------------------------------------------------- -Qoption acpp x -Wp, opt ----------------------------------------------------------------------------- -Qoption acomp x Not available. ----------------------------------------------------------------------------- -Qoption cfront x -WC, opt ----------------------------------------------------------------------------- -Qoption iropt Not available. ----------------------------------------------------------------------------- -Qoption as x -Wa, opt ----------------------------------------------------------------------------- -Qoption ld x -Wl, opt ----------------------------------------------------------------------------- -Qoption ptcomp x -Wr, opt ----------------------------------------------------------------------------- -Qoption ptlink x -Wi, opt ----------------------------------------------------------------------------- -Qproduce .o -c ----------------------------------------------------------------------------- -Qproduce .s -S ----------------------------------------------------------------------------- -Qproduce .cc +i ----------------------------------------------------------------------------- -Qproduce .i -P ----------------------------------------------------------------------------- -Rx +b opt Runtime shared lib load path. ----------------------------------------------------------------------------- -S Same. ----------------------------------------------------------------------------- -sb Not available. ----------------------------------------------------------------------------- -sbfast Not available. ----------------------------------------------------------------------------- -temp=dir Not available. Use TMPDIR environment variable. ----------------------------------------------------------------------------- -time Not available. Reports compilation time. ----------------------------------------------------------------------------- -Ux Same. ----------------------------------------------------------------------------- -V Not available. Reports version nums of subpr. ----------------------------------------------------------------------------- -v Same. ----------------------------------------------------------------------------- +w Same. ----------------------------------------------------------------------------- -w Same. ----------------------------------------------------------------------------- -xF Not available. Enables SparcWorks performance analysis. ----------------------------------------------------------------------------- -Xm Not available. Allows $ in identifiers. ----------------------------------------------------------------------------- -xs Not available. Puts sym table into a.out. ----------------------------------------------------------------------------- 2-20 ----------------------------------------------------------------------------- FORTRAN Compiler FORTRAN Compiler Tips and Traps ------------------------------- This section lists the differences between the HP FORTRAN compiler and the Sun FORTRAN compiler. The current FORTRAN compiler (as of January 1995) is HP-UX FORTRAN/9000 940228 (HP-UX 9.0 Application Release -- April 1994) B2408A/B2409B 09.16. To check the revision, execute: what /usr/bin/f77 --- FORTRAN Symbol Name Differences By default, SunOS 4.1.3 FORTRAN appends underscores to all symbol names. HP-UX FORTRAN does not. To make HP-UX FORTRAN behave like SunOS 4.1.x FORTRAN, apply the +ppu compiler option to HP-UX compile line. This appends underscores to external names. --- Routine flush is Undefined This routine forces any output associated with an output file unit to disk; for example, flush any buffers associated with the file. HP FORTRAN has no comparable function. Here is an example of how to reimplement the FORTRAN fflush() routine using the C library fflush(): C This example shows how to flush a FORTRAN unit using fflush(3S). C The FORTRAN unit number is converted to a stream pointer with the C fstream intrinsic. Then the stream pointer is passed to fflush. C The $ALIAS directives for fflush and sleep make them pass their C parameters by value instead of by reference since they are C connecting with C library routines. (Sleep is only used to C illustrate the effect of the buffering.) $ALIAS sleep = Ôsleep'(%val) $ALIAS fflush = Ôfflush'(%val) program flush integer*4 fp open (10, file='DATA', status='NEW') C Get the stream pointer for unit 10 to pass to fflush fp = fstream(10) do ii=1,100 write (10,*) ii call fflush(fp) call sleep(1) end do end 2-21 --- Compiler Fails With "Not Enough Space" Message The Not enough space system error occurs when a process attempts to exceed the maximum size of the data segment. This message indicates that the compiler is unable to allocate enough memory to compile the program unit. By default, the maximum size of the data segment of an executing process is 64Mb. If your process needs a larger data segment, run the System Administrator Manager (sam) to increase the MAXSIZ kernel parameter (see the HP-UX System Administration Tasks manual, Chapter 11). You may also need to increase swap space and/or the MAXSWAPCHUCKS kernel parameter. See "Large Data Space Processes" on page 8-11 for more information. --- Large Executable Dumps Core If a large executable (80 Mbytes, for example) crashes in a core dump with a "segmentation violation," your program probably ran out of data space. See "Large Data Space Processes" on page 8-11. --- Can't Find libF77.a on HP-UX Remove libF77.a from compile/link line. On the HP Series 700/800 systems, the contents of libF77 is contained in /usr/lib/libcl.[a,sl] and does not need to be explicitly included in the link line. --- Line Length is Too Small Use the +es compile-line option to increase the number of characters allowed per line. The default is 72 characters. --- Mixed Formats in I/O Statements SunOS 4.1.3 FORTRAN allows mixed formats in formatted I/O statements. Thus, it is possible for a WRITE statement to have an output variable of type REAL, and a format specification for a type INTEGER. By default, HP FORTRAN does not allow mixed formats in formatted I/O statements. However, you can override the default with the $MIXED_FORMATS ON directive. --- REWIND Doesn't Behave As Expected The manual says that the REWIND statement can be used on sequential files only, but violating this requirement would not always cause an error. The problem is that REWIND performed an auto-open and did not fail. Starting with HP-UX 9.0 Application Release -- April 1994, REWIND will not do an auto-open and will behave as expected. 2-22 ----------------------------------------------------------------------------- Pascal Compiler Product Overview ---------------- This section lists the differences between the HP Pascal compiler and the Sun Pascal compiler. (References: "HP-UX Portability Guide", Chapter 7; "HP Pascal/HP-UX Reference Manual;" and "Sun Pascal Reference Manual.") You may be aware that HP-UX actually supports two Pascal compilers: Apollo Pascal and HP Pascal. The Apollo Pascal compiler, a port to HP-UX of the Domain Pascal compiler, was developed as a migration tool for customers moving from DomainOS to HP-UX. This section describes only the HP Pascal compiler. The current HP Pascal Compiler revision is: Pascal Compiler Driver Version A.09.12 94/03/01 and HP92431 A.09.12 94/02/17 Pascal/UX Compiler To check the revision, execute: what /usr/bin/pc /usr/lib/pascomp HP Pascal is a superset of the ANSI/IEEE 770 X3.97-1983 and ISO 7185-1983 standards. For a complete list of the HP Pascal extensions, please refer to the HP Pascal/HP-UX Reference Manual. If the Pascal code you are porting contains non-ANSI features, you can get a list of these features by using the -A (produce warnings when non-ANSI Pascal features are found) and -L (write program listing to stdout) command line options. Optimization ------------ Various levels and types of optimization can be enabled and disabled with command line options. Profile-Based Optimization (PBO) is also a feature of the latest HP Pascal compiler. Refer to the man page for pc(1) and the HP Pascal/HP-UX Release Notes for details on each optimization feature. Shared Libraries ---------------- HP Pascal modules can be placed in shared libraries. A linker defect affected Pascal shared libraries. The problem is described as follows from the "HP9000 S700 Software Status Bulletin": The problem in this defect is that a shared library built from Pascal object files that contain "qualified" data symbols (that is, they come from Pascal modules) will not have these data symbols exported from the library. This means that they will not be available to satisfy imports from the program file or other shared libraries. This problem has been resolved, and a fix is available in the s700_800 9.X cumulative ld(1) patch PHSS_4716. Check the patch server on Mosaic at http://www.nsa.hp.com/patches/ to verify the latest patch number. 2-23 Comments Differences -------------------- Sun Pascal allows you to use either braces, quotation marks, parenthesis/ asterisk pairs, or slash/asterisk pairs for comments. In Sun Pascal, you can nest comments by using one type of comment delimiter inside another. HP Pascal allows you to use braces or parenthesis/asterisk pairs for comments. You cannot nest comments. Data Type Differences --------------------- Data type differences are summarized below. Refer to the respective reference manuals for full details. --- Real Data Types Sun Pascal has the following real data types and sizes: * real (with -xl option), 32 bits * real (without -xl option), 64 bits * single, 32 bits * shortreal, 32 bits * double, 64 bits * longreal, 64 bits HP Pascal has the following real data types and sizes: * longreal, 64 bits * real, 32 bits --- Integer Data Types Sun Pascal has the following integer data types and sizes: * integer (without -xl option), 32 bits * integer (with -xl option), 16 bits * integer16, 16 bits * integer32, 32 bits HP Pascal has the following integer data types and sizes: * integer, 32 bits * shortint, 16 bits * longint, 64 bits --- Subranges Sun Pascal subranges can be of integer, boolean, character, and enumerated data types. HP Pascal also allows subranges of integer, boolean, character, and enumerated data types, as well as the predefined data types of bit16 (0..65535 subrange), bit32 (0..232-1) subrange, and bit52 (0..252-1 subrange). 2-24 --- Arrays Sun Pascal has the standard array data type and three predeclaredcharacter array types: alfa, string, and varying. HP Pascal has the standard array data type and a string type, which is a packed array of char with a declared length. --- Pointers Sun Pascal has the standard pointer type and a universal pointer type. HP Pascal has the standard pointer type, and the predefined types globalanyptr and localanyptr. Both globalanyptr and localanyptr are assignment compatible with any other pointer type. Globalanyptr is a long pointer, and localanyptr is a short pointer. --- Variable initialization Sun Pascal allows variable initialization in the var declaration. HP Pascal does not allow this. Pascal Compiler Options Cross Reference --------------------------------------- Table 8-13: Pascal Compiler Options Cross Reference Sun Pascal Option HP Pascal Comments ============================================================================= -a Not available. See the HP Pascal options -G and -p for profiling and -y for static analysis. ----------------------------------------------------------------------------- -align Not available. ----------------------------------------------------------------------------- -b Not available. ----------------------------------------------------------------------------- -B static -Wl,-a archive Also -Wl, -a default, which ---------------------------------------- means use shared libraries if -B dynamic -Wl,-a shared available, else use archive. ----------------------------------------------------------------------------- -c -c ----------------------------------------------------------------------------- -cond Not available. ----------------------------------------------------------------------------- -config Not available. See -D option. ----------------------------------------------------------------------------- -C Not available. In HP Pascal, range checking is on by default. Use +R to inhibit range checking. ----------------------------------------------------------------------------- -cg87 Not available. Sun-4 only. ----------------------------------------------------------------------------- -cg89 Not available. Sun-4 only. ----------------------------------------------------------------------------- -dalign Not available. Sun-4 only. ----------------------------------------------------------------------------- 2-25 ----------------------------------------------------------------------------- -dryrun Not available. See -C, which suppresses code generation, and -v for verbose mode. ----------------------------------------------------------------------------- -D[=] -D= can be TRUE or FALSE, -D if is not specified, is set to TRUE. can also be defined with $SET directive. ----------------------------------------------------------------------------- -fast -O ----------------------------------------------------------------------------- -fnonstd +FP See ld(1) +FP options. ----------------------------------------------------------------------------- -f Not available. Sun-3 only. ----------------------------------------------------------------------------- -g -g ----------------------------------------------------------------------------- -G Not available. For Sun Pascal 1.1 compatibility. ----------------------------------------------------------------------------- -help Not available. ----------------------------------------------------------------------------- -H Not available. In HP Pascal, range checking is on by default. ----------------------------------------------------------------------------- -i Not available. Use -L for program listing. ----------------------------------------------------------------------------- -I -I ----------------------------------------------------------------------------- -J Not available. Sun-3 only. ----------------------------------------------------------------------------- -l -L ----------------------------------------------------------------------------- -l -l ----------------------------------------------------------------------------- -lpfc Not available. ----------------------------------------------------------------------------- -libmil Not available. ----------------------------------------------------------------------------- -L Not available. ----------------------------------------------------------------------------- -misalign Not available. Sun-4 only. ----------------------------------------------------------------------------- -native Not available. See +DA for architecture- specific code generation. ----------------------------------------------------------------------------- -nolibmil Not available. ----------------------------------------------------------------------------- -o -o ----------------------------------------------------------------------------- -O [] -O, -O is the same as +O2 +O, is 0, 1, 2, 3, or 4 +O