Remove a symbol from shared object

I don't have much control over the build process, but I am getting an undefined reference to symbols error when my next piece of code tries to link with the previously compiled shared library. [Although the said symbols are there in the so]

here is a snippet of symbols from the shared library of interest (libmycode.so below complete real name is given), I want to remove last two lines of this snippet and test if removing those helps my case.

U _ZN4Foam5token21transferCompoundTokenERKNS_7IstreamE
U _ZN4Foam5token8compound10isCompoundERKNS_4wordE
U _ZN4Foam5tokenC1ERNS_7IstreamE
U _ZN4Foam6fvMeshC1ERKNS_8IOobjectE
U _ZN4Foam6fvMeshD1Ev

I repeat, I can't just compile them using g++ -unresolved-symbols -fdata-sections -ffunction-sections.

Also

objcopy -N 'Foam::fvMesh()' libmycode.so

didn't work

Also I have another libmycode2.so which links just fine with my code and the difference between these two objects is the additional two lines which I mentioned in the snippet.

options and files of executables

chem1dReader.C
chem1dToFoam.C

EXE = $(FOAM_USER_APPBIN)/pasrChem1dToFoam_m

Now options

EXE_INC =  
-I$(LIB_SRC)/OpenFOAM/lnInclude 
-I$(LIB_SRC)/finiteVolume/lnInclude 
-I$(LIB_SRC)/turbulenceModels 
-I$(LIB_SRC)/turbulenceModels/compressible/turbulenceModel/lnInclude 
-I$(LIB_SRC)/turbulenceModels/compressible/RAS/lnInclude 
-I$(LIB_SRC)/turbulenceModels/compressible/LES/lnInclude 
-I$(LIB_SRC)/turbulenceModels/LES/LESdeltas/lnInclude 
-I$(LIB_SRC)/thermophysicalModels/specie/lnInclude 
-I$(LIB_pasrFGM_m_SRC)/pdfFGMThermo/basic/lnInclude 
-I$(LIB_pasrFGM_m_SRC)/pdfFGMThermo/reactionThermo/lnInclude 
-I$(LIB_pasrFGM_m_SRC)/combustionModels/lnInclude

EXE_LIBS = 
-L$(FOAM_USER_LIBBIN) 
-lODE 
-lspecie 
-lcompressibleLESModels 
-lcompressibleTurbulenceModel 
-lcompressibleRASModels 
-lpdfFGMbasicThermophysicalModels 
-lpdfFGMreactionThermophysicalModels 
-lpdfFGMCombustionModels 
-lfiniteVolume

Exact error message when I try to compile pasrChem1dToFoam_m

dReader.o Make/linux64GccDPOpt/chem1dToFoam.o -L/home/vasu/OpenFOAM/OpenFOAM-2.3.1/platforms/linux64GccDPOpt/lib 
 -L/home/vasu/OpenFOAM/vasu-2.3.1/platforms/linux64GccDPOpt/lib -lODE   -lspecie -lcompressibleLESModels -lcompressibleTurbulenceModel - lcompressibleRASModels -lpdfFGMbasicThermophysicalModels - lpdfFGMreactionThermophysicalModels -lpdfFGMCombustionModels -  lfiniteVolume -lOpenFOAM -ldl   -lm -o 

/home/vasu/OpenFOAM/vasu-  2.3.1/platforms/linux64GccDPOpt/bin/pasrChem1dToFoam_m
/home/vasu/OpenFOAM/vasu-2.3.1/platforms/linux64GccDPOpt/lib/libpdfFGMbasicThermophysicalModels.so: undefined reference to `Foam::fluidThermo::destroyTimeConstructorTables()'
/home/vasu/OpenFOAM/vasu-2.3.1/platforms/linux64GccDPOpt/lib/libpdfFGMbasicThermophysicalModels.so: undefined reference to `Foam::basicThermo::constructTimeConstructorTables()'
/home/vasu/OpenFOAM/vasu-2.3.1/platforms/linux64GccDPOpt/lib/libpdfFGMbasicThermophysicalModels.so: undefined reference to `Foam::basicThermo::destroyTimeConstructorTables()'
/home/vasu/OpenFOAM/vasu-2.3.1/platforms/linux64GccDPOpt/lib/libpdfFGMbasicThermophysicalModels.so: undefined reference to `Foam::fluidThermo::fluidThermo(Foam::Time const&, Foam::word const&)'
/home/vasu/OpenFOAM/vasu-2.3.1/platforms/linux64GccDPOpt/lib/libpdfFGMbasicThermophysicalModels.so: undefined reference to `Foam::fluidThermo::constructTimeConstructorTables()'
/home/vasu/OpenFOAM/vasu-2.3.1/platforms/linux64GccDPOpt/lib/libpdfFGMbasicThermophysicalModels.so: undefined reference to `Foam::basicThermo::TimeConstructorTablePtr_'
/home/vasu/OpenFOAM/vasu-2.3.1/platforms/linux64GccDPOpt/lib/libpdfFGMbasicThermophysicalModels.so: undefined reference to `Foam::fluidThermo::TimeConstructorTablePtr_'
 collect2: error: ld returned 1 exit status
/home/vasu/OpenFOAM/OpenFOAM-2.3.1/wmake/Makefile:149: recipe for target '
/home/vasu/OpenFOAM/vasu-2.3.1/platforms/linux64GccDPOpt/bin/pasrChem1dToFoam_m' failed
make: *** [/home/vasu/OpenFOAM/vasu-2.3.1/platforms/linux64GccDPOpt/bin/pasrChem1dToFoam_m] Error 1

Your error messages are quite strange, because the symbols mentioned ( Foam::fluidThermo::fluidThermo(Foam::Time const&, Foam::word const&) etc.) do not exist in standard OpenFOAM, nor in other forks that I am aware of (1, 2). At the same time, class names Foam::fluidThermo and basicThermo are standard OpenFOAM classes.

This most probably means that the library libpdfFGMbasicThermophysicalModels.so was developed for a highly modified version of OpenFOAM. In such a case, you would not be able to link it against standard OpenFOAM. However, if you actually have that modified OpenFOAM, then you just are not linking the needed libraries.

In what follows, I explain what I would do to find what these libraries are, assuming you actually have the needed OpenFOAM version. I will explain it on standard OpenFOAM. You might need to repeat it with your version to check if the library name(s) differs.

You see that undefined references come from fluidThermo and basicThermo classes. Therefore, you need to link to a library that contains the code for these classes.

To find which library it is, firstly, find the location of the sources for basicThermo in OpenFOAM sources. You will find the file basicThermo.C in src/thermophysicalModels/basic/basicThermo/ .

Now walk up the directory structure until you find yourself in a directory that has Make subdirectory in it: this will mean that you reached the root of the library to which basicThermo belongs. You will find that it is src/thermophysicalModels/basic/ . There, in Make/files , you will see the following line:

LIB = $(FOAM_LIBBIN)/libfluidThermophysicalModels

This means that basicThermo class is compiled into that library and that you need to add this library to the list of libraries you link to. Thus, add the following line to your wmake/options :

-lfluidThermophysicalModels 

Repeat the process with fluidThermo , but for this case, you most probably will find that the library is the same.

Try to rebuild your application. I expect that these undefined references will go, but probably new undefined references will appear. Repeat the process by looking at what classes are missing and adding needed libraries. After a few iterations you will have no undefined references.

链接地址: http://www.djcxy.com/p/42618.html

上一篇: getApplication()与getApplicationContext()

下一篇: 从共享对象中删除一个符号