+z +Z compiler flag for HP

1.      今天遇到一问题,在sles11/vxworks下编译通过,但是在hpux下失败

2.      编译错误:

/usr/ccs/bin/ld:DP relative code in file /projects/xxx/DERIVED/tfa_pa32-hpux.a(tfa02_pa32-hpux.o) -shared library must be position

    independent.  Use +z or +Z to recompile.

3.    修改makefile,添加+z选项

ifeq($(BLD_TARGET_ARCH),pa32-hpux)

TS_LOGLIB_OPTS.o+= +z

endif

4.    重新编译

5.    报新的错误如下:

/usr/ccs/bin/ld:Data Linkage Table (+z) overflow in file /projects/xxx/loglib_pa32-hpux-mt.a(a7ts_log_pa32-hpux-mt.o)- use +Z option to recompile

   Reference from:  /projects/xxx/loglib_pa32-hpux-mt.a(a7ts_log_pa32-hpux-mt.o)(0x604)

6.    查询+z 和 +Z 的区别,如下:

+z,+Z Both ofthese options cause the compiler to generate position independent code(PIC) for use in building shared libraries. +Z is the default in 64-bitmode. The -G and -p options are ignored if +z or +Z is used. Normally,+z should be used to generate PIC; however, when certain limits areexceeded, +Z is required to generate PIC. The ld linker issues theerror indicating when +Z is required. If both +z and +Z are 
specified, only the last one encountered applies. For a more completediscussion regarding PIC and these 
options, see HP-UX Linker and Libraries Online User's Guide and the manualProgramming on HP-UX.  

7.      修改makefile,添加+Z选项:

ifeq($(BLD_TARGET_ARCH),pa32-hpux)

TS_LOGLIB_OPTS.o+= +Z

endif

8.    编译通过。

9.    结论:

9.1  +z/+Z 相当于gcc 中的-fPIC;

(The '+Z' refers to *compiler* flag for HP cc/CC, which isequivalent to '-fPIC' for gcc.)

9.2  +z +Z有区别;

9.3  这个选项是编译(compile)选项,而不是链接(ld)选项;


你可能感兴趣的:(Linux/HPUX,compiler,linker,makefile,reference,library,file)