MPAS | netcdf-c-4.7.4 final link failed - nonrepresentable section on output

Issue

In order to write netCDF-4 files, you must have the NetCDF-4 C library (libnetcdf) - version 4.3.1 or above - available on your system, along with all supporting libraries (libhdf5, libz, etc). The details of this differ for each operating system.

nc-config and libnetcdf.so are expected to be generated. And, check with

nc-config --cflags nc-config --libs

netcdf-c-4.7.4

final link failed: nonrepresentable section on output

Solution

  • [ ] have to add --disable-shared to avoid Error-ld: final link failed: nonrepresentable section on output.
  • [x] add -enable-static

Ref:

  1. --enable-static vs --disable-shared

In the common case that these are switches to a "configure" script generated by Autoconf and Libtool, then they officially mean closely-related, but different, things. --enable-static means do build static libraries; --disable-shared means don't build shared libraries. If you want to be sure to get only static libraries, no matter what, you need to give both options. However, often just --disable-shared will have that effect, because think about the possibilities: if the package builds only static libraries by default, then --disable-shared is a no-op; if it builds both static and shared libraries by default, then you just have to turn off the shared libraries to get what you want; and if it builds only shared libraries by default, then you might think you need both options, but if you just say --disable-shared, Libtool will usually notice that it's now being asked to build nothing, assume that that couldn't possibly be what you wanted, and flip the --enable-static switch for you.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
echo "=== netcdf-C ===="
## -disable-dap:--disable-dap的原因是缺少一个‘curl’的lib
## 4.1.3以后的版本Fortran和C分开了。把disable--netcdf-4 写进去也无所谓

cd $download_DIR
tar xvf netcdf-c-4.7.4.tar.gz 1>/dev/null 2>&1
cd netcdf-c-4.7.4/

# have to define below parameters
export FC=mpifort
export F77=mpifort
export F90=mpifort
export CC=mpicc
export CXX=mpic++

###export LIBS="-lhdf5_hl -lhdf5 -lz -ldl"

export LD_LIBRARY_PATH=$libs_DIR/lib:$LD_LIBRARY_PATH
export LDFLAGS=-L$libs_DIR/lib
export CPPFLAGS=-I$libs_DIR/include

./configure --prefix=$libs_DIR --enable-shared --enable-netcdf4 --disable-filter-testing --disable-dap
make -j 4
make check
make install
cd ..
rm -rf netcdf-c-4.7.4
echo "=== netcdf-C (end) ===="

MPAS | netcdf-c-4.7.4 final link failed - nonrepresentable section on output
https://waipangsze.github.io/2024/05/30/MPAS_install_netcdf_c_nonrepresentable_error/
Author
wpsze
Posted on
May 30, 2024
Updated on
November 15, 2024
Licensed under