Parallel-NetCDF / PnetCDF

Source code repository of PnetCDF library and utilities
https://parallel-netcdf.github.io
Other
83 stars 23 forks source link

Not compiling shared library #67

Closed afernandezody closed 4 years ago

afernandezody commented 4 years ago

Hello, The compilation for shared libraries is failing (./configure --prefix=/opt/netcdf --enable-shared) with the message:

...
  F77LD    libf77.la
make[3]: Leaving directory `/home/user/PnetCDF/src/binding/f77'
Making all in f90
make[3]: Entering directory `/home/user/PnetCDF/src/binding/f90'
make  all-am
make[4]: Entering directory `/home/user/PnetCDF/src/binding/f90'
  FC       pnetcdf.lo
  FCLD     libf90.la
make[4]: Leaving directory `/home/user/PnetCDF/src/binding/f90'
make[3]: Leaving directory `/home/user/PnetCDF/src/binding/f90'
make[3]: Entering directory `/home/user/PnetCDF/src/binding'
make[3]: Nothing to be done for `all-am'.
make[3]: Leaving directory `/home/user/PnetCDF/src/binding'
make[2]: Leaving directory `/home/user/PnetCDF/src/binding'
Making all in packaging
make[2]: Entering directory `/home/user/PnetCDF/src/packaging'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/home/user/PnetCDF/src/packaging'
Making all in .
make[2]: Entering directory `/home/user/PnetCDF/src'
make[2]: Nothing to be done for `all-am'.
make[2]: Leaving directory `/home/user/PnetCDF/src'
Making all in libs
make[2]: Entering directory `/home/user/PnetCDF/src/libs'
  GEN      libpnetcdf.la
/usr/bin/ld: .libs/libpnetcdf.lax/libf77.a/strerrnof.o: relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: .libs/libpnetcdf.lax/libf90.a/pnetcdf.o: relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output
make[2]: *** [libpnetcdf.la] Error 2
make[2]: Leaving directory `/home/user/PnetCDF/src/libs'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/user/PnetCDF/src'
make: *** [all-recursive] Error 1

I tried adding -fPIC to CCFLAGS & CXXFLAGS but it didn't make any difference. Thanks.

wkliao commented 4 years ago

Which version of PnetCDF are you using? (or cloned from this repo?)

Please provide file "config.log" which was generated after running your command 'configure' (./configure --prefix=/opt/netcdf --enable-shared). It may reveal some information.

afernandezody commented 4 years ago

Hi @wkliao, Yes, it's cloned. The compilation failed on Monday twice so I just built it as a static library (this wasn't the 1st time that I ran into that error). Unfortunately, I forgot to save the config.log as I was rushing to have a workable library. Since then, I have tried the configuration 3 times in other systems with different OSs but the error doesn't reproduce. I'm still investigating which system or configuration parameter triggers the error. Thanks.

afernandezody commented 4 years ago

I was finally able to fix the issue (when it appears) by adding -fPIC to the linker flags. Thanks.

wkliao commented 4 years ago

Just to clarify this issue. One should not need to add -fPIC to the linker flags in order to build a shared library. PnetCDF uses libtool which automatically sets the necessary compile and link flags. In most of the cases, -fPIC is added automatically when configure option --enable-shared is used.

The below extracted error messages you are getting is most likely because the MPI compilers are not built with shared libraries enabled. PnetCDF checks this possibility at configure time, which is why I asked for file 'config.log' and hope it can reveal such information.

/usr/bin/ld: .libs/libpnetcdf.lax/libf77.a/strerrnof.o: relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: .libs/libpnetcdf.lax/libf90.a/pnetcdf.o: relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output

If you would like to try it again, I am interested to learn how it goes. Please run commands below to have a clean build.

make distclean
./configure --prefix=/opt/netcdf --enable-shared
make
afernandezody commented 4 years ago

I'm also interested in understanding why it fails sometimes. I don't disagree with what you're saying about libtool but what do you mean by the MPI compilers are not built with shared libraries enabled? My interpretation is that you're referring to the MPI wrapper (not the compilers used to build it) but (I think that) OpenMPI builds with shared libraries enabled by default. Other apps compile and build their shared libraries w/o complaining; one exception was the compilation of netcdf-fortran with cmake when I had to use the -fPIC flag.

wkliao commented 4 years ago

Yes, what I meant for the "MPI compilers" are the MPI wrappers, such as mpicc, mpifort, etc. Another possibility is you first configured PnetCDF using one set of MPI compilers and then used a different set of MPI compilers to run 'make' (such as different versions of OpenMPI or mixed use of OpenMPI and MPICH, or the environmental variable PATH is changed in between configure and make.)

Without the file 'config.log', all I can do is guessing. If you encountered the same failure again, please provide that log file.