Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Makefile Error: Failed to set dynamic section sizes: bad value

I am trying to compile c++ code in Ubuntu Hyper-V virtual machine. The Makefile runs like normal but at the end I get this error:

/usr/bin/ld: netcdf/libs/libnetcdf_c++.a(netcdf.o): relocation R_X86_64_32S against symbol >`_ZTV16NcTypedComponent' can not be used when making a PIE object; recompile with -fPIE /usr/bin/ld: failed to set dynamic section sizes: bad value collect2: error: ld returned 1 exit status make: *** [Makefile:158: dos-tem] Error 1

Below is the Makefile:

# Basic dos-tem Makefile 

CC=g++


CFLAGS= -c -Wall -ansi -O0 -g -fPIC 

LIBS=-lnetcdf_c++ -lnetcdf 
LIBDIR=-Lnetcdf/libs
INCLUDES=-Inetcdf/includes
SOURCES= src/TEM.o \
         src/atmosphere/AtmosUtil.o \
         src/atmosphere/Atmosphere.o \
         src/data/BgcData.o \
         src/data/CohortData.o \
         src/data/EnvData.o \
         src/data/FirData.o \
         src/data/GridData.o \
         src/data/RegionData.o \
         src/data/RestartData.o \
         src/disturb/WildFire.o \
         src/ground/Bucket.o \
     src/ground/DoubleLinkedList.o \
         src/ground/Ground.o \
         src/ground/Mineral.o \
         src/ground/Moss.o \
         src/ground/Peat.o \
         src/ground/Richard.o \
         src/ground/Rock.o \
         src/ground/Snow_Env.o \
         src/ground/Soil_Bgc.o \
         src/ground/Soil_Env.o \
         src/ground/Stefan.o \
         src/ground/layer/Front.o \
         src/ground/layer/Layer.o \
         src/ground/layer/MineralLayer.o \
         src/ground/layer/MossLayer.o \
         src/ground/layer/OutputDepth.o \
         src/ground/layer/PeatLayer.o \
         src/ground/layer/RockLayer.o \
         src/ground/layer/SnowLayer.o \
         src/ground/layer/SoilLayer.o \
         src/input/CohortInputer.o \
         src/input/GridInputer.o \
         src/input/RegionInputer.o \
         src/input/RestartInputer.o \
         src/input/SiteinInputer.o \
         src/input/SoilclmInputer.o \
         src/lookup/CCohortLookup.o \
         src/lookup/CohortLookup.o \
         src/lookup/SoilLookup.o \
         src/output/AtmosphereOutputer.o \
         src/output/CCohortdriver.o \
         src/output/RegnOutputer.o \
         src/output/RestartOutputer.o \
         src/output/SiteOutputer.o \
         src/output/SnowSoilOutputer.o \
         src/output/SoilclmOutputer.o \
         src/output/StatusOutputer.o \
         src/output/VegetationOutputer.o \
         src/run/AtmOutData.o \
         src/run/Cohort.o \
         src/run/Controller.o \
         src/run/Grid.o \
         src/run/ModelData.o \
         src/run/RegnOutData.o \
         src/run/SiteIn.o \
         src/run/SnowSoilOutData.o \
         src/run/SoilClm.o \
         src/run/Timer.o \
         src/run/VegOutData.o \
         src/runmodes/Regioner.o \
         src/runmodes/RunCohort.o \
         src/runmodes/Siter.o \
         src/util/CrankNicholson.o \
         src/util/Exception.o \
         src/util/FileChecking.o \
         src/util/Integrator.o \
         src/util/Interpolator.o \
         src/vegetation/Vegetation_Bgc.o \
         src/vegetation/Vegetation_Env.o

OBJECTS= AtmosUtil.o \
         Atmosphere.o \
         BgcData.o \
         CohortData.o \
         EnvData.o \
         FirData.o \
         GridData.o \
         RegionData.o \
         RestartData.o \
         WildFire.o \
     Bucket.o \
         DoubleLinkedList.o \
         Ground.o \
         Mineral.o \
         Moss.o \
         Peat.o \
         Richard.o \
         Rock.o \
         Snow_Env.o \
         Soil_Bgc.o \
         Soil_Env.o \
         Stefan.o \
         Front.o \
         Layer.o \
         MineralLayer.o \
         MossLayer.o \
         OutputDepth.o \
         PeatLayer.o \
         RockLayer.o \
         SnowLayer.o \
         SoilLayer.o \
         CohortInputer.o \
         GridInputer.o \
         RegionInputer.o \
         RestartInputer.o \
         SiteinInputer.o \
         SoilclmInputer.o \
         CCohortLookup.o \
         CohortLookup.o \
         SoilLookup.o \
         AtmosphereOutputer.o \
         CCohortdriver.o \
         RegnOutputer.o \
         RestartOutputer.o \
         SiteOutputer.o \
         SnowSoilOutputer.o \
         SoilclmOutputer.o \
         StatusOutputer.o \
         VegetationOutputer.o \
         AtmOutData.o \
         Cohort.o \
         Controller.o \
         Grid.o \
         ModelData.o \
         RegnOutData.o \
         SiteIn.o \
         SnowSoilOutData.o \
         SoilClm.o \
         Timer.o \
         VegOutData.o \
         Regioner.o \
         RunCohort.o \
         Siter.o \
         CrankNicholson.o \
         Exception.o \
         FileChecking.o \
         Integrator.o \
         Interpolator.o \
         Vegetation_Bgc.o \
         Vegetation_Env.o

TEMOBJ= TEM.o
    

dos-tem: $(SOURCES) $(TEMOBJ)
    $(CC) -o peat-dos-tem $(OBJECTS) $(TEMOBJ) $(LIBDIR) $(LIBS)

lib: $(SOURCES) 
    $(CC) -o libDOSTEM.so -shared $(INCLUDES) $(OBJECTS) $(LIBDIR) $(LIBS)

.cpp.o:  
    $(CC) $(CFLAGS) $(INCLUDES) $<

clean:
    rm -f $(OBJECTS) DVMDOSTEM TEM.o libDOSTEM.so* *~

I've tried: -update netCDF packages and GNU- no change -taking -fPIC out of the Makefile -no change -replacing -fPIC with -fPIE -no change -moving -fPIC here 'CC=g++ -fPIC' an removing it from the CFLAGS line - no change -leaving -fPIC in both the CC line and CFLAGS line.

How do I resolve this? I have had colleagues run this code on their Ubuntu machines and it works just fine. This runs on other ubuntu machines, just not mine.

like image 672
Caroline Avatar asked Oct 24 '25 14:10

Caroline


1 Answers

Recompile libnetcdf_c++.a with a -fPIC option, it should solve your problem.

like image 100
Wololllooo Avatar answered Oct 27 '25 04:10

Wololllooo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!