0

我对构建过程没有太多控制权,但是当我的下一段代码尝试与先前编译的共享库链接时,我得到一个未定义的符号引用错误。[虽然上述符号在so中]

这是来自感兴趣的共享库的符号片段(libmycode.so 下面给出了完整的真实姓名),我想删除这个片段的最后两行并测试删除这些是否对我的情况有帮助。

U _ZN4Foam5token21transferCompoundTokenERKNS_7IstreamE
U _ZN4Foam5token8compound10isCompoundERKNS_4wordE
U _ZN4Foam5tokenC1ERNS_7IstreamE
U _ZN4Foam6fvMeshC1ERKNS_8IOobjectE
U _ZN4Foam6fvMeshD1Ev

我再说一遍,我不能只使用 g++ -unresolved-symbols -fdata-sections -ffunction-sections 来编译它们。

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

没用

此外,我还有另一个 libmycode2.so 与我的代码链接得很好,这两个对象之间的区别是我在片段中提到的另外两行。

可执行文件的选项和文件

chem1dReader.C
chem1dToFoam.C

EXE = $(FOAM_USER_APPBIN)/pasrChem1dToFoam_m

现在选项

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

当我尝试编译 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
4

1 回答 1

1

您的错误消息很奇怪,因为提到的符号(Foam::fluidThermo::fluidThermo(Foam::Time const&, Foam::word const&)等)不存在标准 OpenFOAM中,也不存在于我所知道的其他分叉中(12)。同时,类名Foam::fluidThermobasicThermo都是标准的 OpenFOAM 类。

这很可能意味着该库libpdfFGMbasicThermophysicalModels.so是为高度修改的 OpenFOAM 版本开发的。在这种情况下,您将无法将其与标准 OpenFOAM 链接。但是,如果您确实拥有修改后的 OpenFOAM,那么您只是没有链接所需的库。

在下文中,我将解释我将如何查找这些库,假设您确实拥有所需的 OpenFOAM 版本。我将在标准 OpenFOAM 上进行解释。您可能需要在您的版本中重复它以检查库名称是否不同。

您会看到未定义的引用来自fluidThermobasicThermo类。因此,您需要链接到包含这些类的代码的库。

要查找它是哪个库,首先,basicThermo在 OpenFOAM 源中找到源的位置。您将basicThermo.Csrc/thermophysicalModels/basic/basicThermo/.

现在遍历目录结构,直到您发现自己处于一个包含Make子目录的目录中:这意味着您到达了basicThermo所属库的根目录。你会发现它是src/thermophysicalModels/basic/。在 中Make/files,您将看到以下行:

LIB = $(FOAM_LIBBIN)/libfluidThermophysicalModels

这意味着basicThermo该类被编译到该库中,并且您需要将此库添加到您链接到的库列表中。因此,将以下行添加到您的wmake/options:

-lfluidThermophysicalModels \

用 重复该过程fluidThermo,但对于这种情况,您很可能会发现库是相同的。

尝试重建您的应用程序。我希望这些未定义的引用会消失,但可能会出现新的未定义引用。通过查看缺少哪些类并添加所需的库来重复该过程。几次迭代后,您将没有未定义的引用。

于 2015-08-07T17:41:49.093 回答