编译自己的求解器遇到问题“undefined reference”
-
Hello,各位大神,
我在编译自己一个求解器的过程中出现了如下的问题:提示说有用undefined reference.
-lincompressibleTransportModels -lOpenFOAM -ldl \ -lm -o /home/hui/OpenFOAM/hui-v1906/platforms/linux64GccDPInt32Opt/bin/dynaPorousNetFoam Make/linux64GccDPInt32Opt/dynaPorousNetFoam.o: In function `main': dynaPorousNetFoam.C:(.text.startup+0x1408): undefined reference to `Foam::netPanel::~netPanel()' dynaPorousNetFoam.C:(.text.startup+0x1f01): undefined reference to `Foam::netPanel::netPanel(Foam::dictionary const&)' ...... ...... dynaPorousNetFoam.C:(.text.startup+0x68c5): undefined reference to `Foam::netPanel::~netPanel()' collect2: error: ld returned 1 exit status /opt/OpenFOAM/OpenFOAM-v1906/wmake/makefiles/general:140: recipe for target '/home/hui/OpenFOAM/hui-v1906/platforms/linux64GccDPInt32Opt/bin/dynaPorousNetFoam' failed make: *** [/home/hui/OpenFOAM/hui-v1906/platforms/linux64GccDPInt32Opt/bin/dynaPorousNetFoam] Error 1
下面说一下我编译的程序结构,我的dynaForousNetFoam 求解器是基于PisoFOAM 进行简单修改后编译的。这个新的求解器调用了我自己写的一个class创建了porousZones 对象,并利用相关的成员函数对U 方程进行修改。
这个class 名是netpanel,并且这个类可以单独用wmake编译成功,结果如下:. ├── platforms │ └── linux64GccDPInt32Opt │ ├── bin │ └── lib │ └── netPanel.so └── run
我求解器中部分相关的代码:
... netPanel porousZones(netDict); // constrcut net panel porousZones.updatePoroField(porosityField, mesh, structuralPositions,structuralElements); //- write the porosity field porosityField.write(); ... // add source term to U equation porousZones.addResistance(UEqn,nu,mesh,structuralPositions,structuralElements); ...
下面是我在编译dynaForousNetFoam 时用的file 和options 文件。从option中可以看出我在编译dynaForousNetFoam的时候已经链接到我之前写的那个class了,但是编译还是不通过。
File:dynaPorousNetFoam.C EXE = $(FOAM_USER_APPBIN)/dynaPorousNetFoam
Option:
EXE_INC = \ -I./Netpanels/lnInclude \ -I$ (LIB_SRC)/finiteVolume/lnInclude \ -I$(LIB_SRC)/meshTools/lnInclude \ -I$(LIB_SRC)/sampling/lnInclude \ -I$(LIB_SRC)/TurbulenceModels/turbulenceModels/lnInclude \ -I$(LIB_SRC)/TurbulenceModels/incompressible/lnInclude \ -I$(LIB_SRC)/transportModels \ -I$(LIB_SRC)/transportModels/incompressible/singlePhaseTransportModel EXE_LIBS = \ -L$(FOAM_USER_LIBBIN)\ -lnetPanel \ -lfiniteVolume \ -lfvOptions \ -lmeshTools \ -lsampling \ -lturbulenceModels \ -lincompressibleTurbulenceModels \ -lincompressibleTransportModels
所以有没有大神能够帮忙指点一下?
-
-
@yfclark
这个function, 我已经写到我的class中了,但是问题是在编译求解器时遇到问题“undefined reference”void Foam::netPanel::addResistance ( fvVectorMatrix& UEqn, const volScalarField& nu, const fvMesh& mesh_, const volVectorField& structuralPositions, const volVectorField& structuralElements ) { const vectorField& centres(mesh_.C()); forAll(structuralElements,Elementi) { dimensionedTensor d_(tensor::zero); dimensionedTensor f_(tensor::zero); transformCoeffs(D_,d_,structuralPositions,structuralElements[Elementi]); transformCoeffs(F_,f_,structuralPositions,structuralElements[Elementi]); tensor& dvalue = d_.value(); tensor& fvalue = f_.value(); const scalarField V = mesh_.V(); vectorField& Usource = UEqn.source(); const vectorField& U = UEqn.psi(); forAll(centres, cellI) { if(isInPorousZone(centres[cellI],structuralPositions,structuralElements[Elementi])) { tensor dragCoeff = nu[cellI]*dvalue + 0.5*mag(U[cellI])*fvalue; Usource[cellI] -=V[cellI]*dragCoeff & (U[cellI] ); } } } }
-
我在想是不是 我的这个option里买有格式错误。
我试过将EXE_LIBS = \ -L$(FOAM_USER_LIBBIN)\ -lnetPanel \
改为
EXE_LIBS = \ -L$(FOAM_USER_LIBBIN) -lnetPanel \
结果感觉更错啦
-lm -o /home/hui/OpenFOAM/hui-v1906/platforms/linux64GccDPInt32Opt/bin/dynaPorousNetFoam /usr/bin/ld: cannot find -lnetPanel collect2: error: ld returned 1 exit status /opt/OpenFOAM/OpenFOAM-v1906/wmake/makefiles/general:140: recipe for target '/home/hui/OpenFOAM/hui-v1906/platforms/linux64GccDPInt32Opt/bin/dynaPorousNetFoam' failed make: *** [/home/hui/OpenFOAM/hui-v1906/platforms/linux64GccDPInt32Opt/bin/dynaPorousNetFoam] Error 1
-
@wwzhao 赵教授,这两个函数我记得定义了,
// Constructors netPanel ( const dictionary& netDict ); //- Destructor ~netPanel();
但是我有一点不太明白,为什么有的函数后面有一个const,有的没有。例如:
这个虚函数是void funname() const;void addResistance ( fvVectorMatrix& UEqn, const volScalarField& nu, const fvMesh& mesh, const matrix& structuralPositions, const matrix& structuralElements )const;
而这个函数是 bool funname(); 就没有const了。
bool isInPorousZone ( const point x, const volVectorField& structuralPositions, const vector& structuralElementi );
const 在括号里面我知道是可以保证传入的参数不变,但是在外边是啥意思啊?
-
@wwzhao
定义也是有的。如下Foam::netPanel::netPanel ( const dictionary& netDict ) : // initial components netDict_(netDict), porousPropertiesDict_(netDict_.subDict("porousProperties")), porosity_(readScalar(porousPropertiesDict_.lookup("porosity"))), thickness_(readScalar(porousPropertiesDict_.lookup("halfthickness"))) // D_(readVector(porousPropertiesDict_.lookup("D"))), // initial as zeros // F_(readVector(porousPropertiesDict_.lookup("D"))) // initial as zeros { dimensionedVector D_(porousPropertiesDict_.lookup("D")); dimensionedVector F_(porousPropertiesDict_.lookup("F")); }
-
@huiCfd 把 netPanel.so 重命名成 libnetPanel.so 试试呢?
-
@wwzhao 是的,去掉何不去掉都试过了,
去掉后显示的错误是-lm -o /home/hui/OpenFOAM/hui-v1906/platforms/linux64GccDPInt32Opt/bin/dynaPorousNetFoam /usr/bin/ld: cannot find -llibnetPanel collect2: error: ld returned 1 exit status /opt/OpenFOAM/OpenFOAM-v1906/wmake/makefiles/general:140: recipe for target '/home/hui/OpenFOAM/hui-v1906/platforms/linux64GccDPInt32Opt/bin/dynaPorousNetFoam' failed make: *** [/home/hui/OpenFOAM/hui-v1906/platforms/linux64GccDPInt32Opt/bin/dynaPorousNetFoam] Error 1
没去掉的话跟原来的错误一样,都是undefined reference