0

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
fedvasu
  • 1,232
  • 3
  • 18
  • 38
  • U means the symbol is undefined. it's look like you need to link your executable with the `openFOAM` library. – SHR Aug 07 '15 at 12:46
  • I am linking it with relevant Foam headers and shared objects, that is why I said I don't have control over build process, I have checked 10 times if I am including the proper libraries in the wmake(openFoam) files. I wouldn't have asked this question, If I thought there was a configuration problem. – fedvasu Aug 07 '15 at 12:48
  • You can also use `ldd` to check if your `libmycode.so` is linked with the `openFOAM` so properly. – SHR Aug 07 '15 at 12:57
  • Are you linking with `libfiniteVolume`? And can you paste here the contents of your `wmake/files` and `wmake/options`? – Petr Aug 07 '15 at 14:41
  • @Petr I have updated my question, the library where I am getting missing symbols is libpffFGMbasicThermophysicalModels – fedvasu Aug 07 '15 at 15:12
  • I'll look into this a bit later. Can you also post the exact error message? Also try linking with libOpenFOAM too – Petr Aug 07 '15 at 15:15
  • Which version of OpenFOAM do you use and what is this `libpdfFGMbasicThermophysicalModels.so`? It mentions `Foam::fluidThermo::fluidThermo(Foam::Time const&, Foam::word const&)` and `Foam::fluidThermo::TimeConstructorTablePtr_` etc., but I do not see such constructors in `fluidThermo` (see, e.g. [here](https://github.com/OpenFOAM/OpenFOAM-2.3.x/blob/master/src/thermophysicalModels/basic/fluidThermo/fluidThermo.H)) – Petr Aug 07 '15 at 17:21

1 Answers1

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.

Wandering Fool
  • 2,170
  • 3
  • 18
  • 48
Petr
  • 9,812
  • 1
  • 28
  • 52