我对构建过程没有太多控制权,但是当我的下一段代码试图与先前编译的共享库链接时,我得到了未定义的符号错误引用。 [尽管上面有这些符号]

这是感兴趣的共享库中的代码片段(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

最佳答案

您的错误消息非常奇怪,因为在do not exist或我所知的其他fork(standard OpenFOAM1)中提到的(Foam::fluidThermo::fluidThermo(Foam::Time const&, Foam::word const&)等)2符号。同时,类名称Foam::fluidThermobasicThermo是标准的OpenFOAM类。

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

在下面的内容中,假设您确实具有所需的OpenFOAM版本,我将说明如何查找这些库。我将在标准OpenFOAM上进行解释。您可能需要在版本中重复此操作,以检查库名称是否不同。

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

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

现在浏览目录结构,直到发现自己位于其中具有Make子目录的目录中:这将意味着您已到达basicThermo所属库的根。您会发现它是src/thermophysicalModels/basic/。在Make/files中,您将看到以下行:

LIB = $(FOAM_LIBBIN)/libfluidThermophysicalModels


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

-lfluidThermophysicalModels \


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

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

关于c++ - 从共享库中删除符号,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31877665/

10-11 19:39