CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (http://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Linking problems dynamic library (http://www.cfd-online.com/Forums/openfoam-programming-development/93238-linking-problems-dynamic-library.html)

Van de Leur October 9, 2011 12:24

Linking problems dynamic library
 
Dear all,

Using Ubuntu 11.04 I recently upgraded to OF 2.0.1.

I have created a custom library without problems. However, the following error message keeps appearing when I try to use this new library (libfvMotionSolversNew.so):

--> FOAM Warning :
From function dlLibraryTable::open(const fileName&, const bool)
in file db/dynamicLibrary/dlLibraryTable/dlLibraryTable.C at line 96
could not load "libfvMotionSolversNew.so"

For some reason OF cannot find the library, although I did add the line libs ("libfvMotionSolversNew.so"); to the file controlDict.

The new library is placed in the folder $FOAM_USER_LIBBIN, copying it to $FOAM_LIBBIN does not solve the problem.

Does anyone have a suggestion to solve this?

Regards,

Kevin

Bernhard October 10, 2011 11:13

This is normally how it should work afaik.

Probably the solution is simple, no typo somewhere? Compilation problems? Did you compile with "wmake libso"? Do you have such a problem with other libraries (I guess not)?

Van de Leur October 10, 2011 12:42

Compiling using "wmake libso" works without problems.
Using the standard libraries provided with OF is also no problem.

The only thing is that OF cannot find the newly created library.

Maybe my 'options' file contains an error in the linking?
Please see below:

EXE_INC = \
-I$(LIB_SRC)/triSurface/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude \
-I$(LIB_SRC)/dynamicMesh/lnInclude \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/postProcessing/functionObjects/forces/lnInclude \
-I$(LIB_SRC)/fvMotionSolver/lnInclude \

LIB_LIBS = \
-L$(FOAM_USER_LIBBIN) \
-ltriSurface \
-lmeshTools \
-ldynamicMesh \
-lfiniteVolume \
/*-lforces include in controlDict if needed */

ata October 11, 2011 03:22

Hi
I think you must remove the "back slash"(\) from the last lines:
EXE_INC = \
-I$(LIB_SRC)/triSurface/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude \
-I$(LIB_SRC)/dynamicMesh/lnInclude \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/postProcessing/functionObjects/forces/lnInclude \
-I$(LIB_SRC)/fvMotionSolver/lnInclude

LIB_LIBS = \
-L$(FOAM_USER_LIBBIN) \
-ltriSurface \
-lmeshTools \
-ldynamicMesh \
-lfiniteVolume

Fransje October 21, 2011 09:18

If you add the options you specified in:
  • The original "options" file of the library you based your code on
  • AND in the "options" file of your use Make directory
it should work out of the box.
As a matter of fact, your library should then be usable even without adding the line:
Code:

libs("libfvMotionSolversNew.so");
in the controlDict file.

Hope this helps.

Kind regards,

Francois.

Fransje October 21, 2011 09:20

Of course, don't forget to recompile the original library once you changed the "options" file... ;)

marupio October 21, 2011 09:37

I've encountered linking problems trying to compile it in Ubuntu 11.10. See this thread: http://www.cfd-online.com/Forums/ope...tml#post328779

It could be related, and it could be a compiler issue.

Van de Leur October 21, 2011 10:51

Dear all,

Thanks for the replies.

I just found another message running OF 2.0.1, it says to disallow user-supplied system cal operations, see below:

(...)
nProcs : 1
sigFpe : Enabling floating point exception trapping (FOAM_SIGFPE).
fileModificationChecking : Monitoring run-time modified files using timeStampMaster
allowSystemOperations : Disallowing user-supplied system call operations

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

Create time

(...)

I guess OF doesn't allow me to access my new library?

Secondly, it seems that the new library does work when using OF 1.7.1. That is, there are no problems accessing the library and I can start debugging.

Although I'm a bit short on time (who isn't?) I'll get back on this.

Regards,

Kevin

Fransje October 21, 2011 11:13

No, it shouldn't matter.

The
Quote:

allowSystemOperations : Disallowing user-supplied system call operations
quote is output during my runs as well, but doesn't block the loading of my extra libraries.

Kind regards,

Francois.

boger October 22, 2011 08:26

I ran into a problem loading a library in 2.0.x yesterday, and a colleague suggested this solution, which helped a lot. I added the following lines to OpenFOAM-2.0.x/src/OSspecific/POSIX/POSIX.C. In that file, around line 1138, you'll find this line:
Code:

void* handle = ::dlopen(lib.c_str(), RTLD_LAZY|RTLD_GLOBAL);
Just below that line, add the following:
Code:

// find error (if any)
    Info << "Checking for error" << endl;
    char *error = ::dlerror();

    if (error)
    {
        WarningIn("dlOpen(const fileName&)")
            << "dlopen error : " << error
            << endl;
    }

You'll then need to recompile by typing ./Allwmake in the POSIX directory, then I would suggest "rm $FOAM_LIBBIN/libOpenFOAM.so", then go to src/OpenFOAM and type "wmake libso".

With that, you should get more information on why the .so file wouldn't load. (In my case, I found that I forgot that I also needed to first load a second .so file.)

I've submitted this as a "feature request" to OpenCFD, so maybe future versions will give better feedback.

Hope it helps!

David

mm.abdollahzadeh July 30, 2012 22:19

Dear All

I have also created my custom library without problems. However, I am also getting the following error message when I try to use this new library (libfvMotionSolversNew.so):

--> FOAM Warning :
From function dlLibraryTable::open(const fileName&, const bool)
in file db/dynamicLibrary/dlLibraryTable/dlLibraryTable.C at line 96

Could you help me please?

Best
Mahdi

ata July 31, 2012 01:19

Hi
Did you add the library name to the controldict?

wyldckat July 31, 2012 04:02

Greetings to all!

Mahdi, I got the private message you sent me. You should have also indicated the thread where you asked your question as well.

Either way, this isn't sufficient information:
Quote:

Originally Posted by mm.abdollahzadeh (Post 374447)
I have also created my custom library without problems. However, I am also getting the following error message when I try to use this new library (libfvMotionSolversNew.so):

--> FOAM Warning :
From function dlLibraryTable::open(const fileName&, const bool)
in file db/dynamicLibrary/dlLibraryTable/dlLibraryTable.C at line 96

Ata is right in asking about whether you added the library to "controlDict", but there is more information I believe is necessary for properly diagnosing the problem, namely:
  • What steps did you take for creating the new library?
  • How are you making the library load? Did you directly link or specify it in "controlDict"?
  • What did you do to get that warning message?
  • That message probably isn't alone, therefore it would be very useful to see the surrounding text to that message!
Best regards,
Bruno

mm.abdollahzadeh July 31, 2012 05:50

Dear Bruno and Ata

Thanks for your kind reply. I am working with OpenFOAM-2.0.x on Ubuntu 10.04 LTS. to create my boundary condition I did that :

1- I have copied the turbulentTemperatureCoupledBaffleMixed boundary condition and renamed it to myturbulentTemperatureCoupledBaffleMixed
2-secondly I have done my changes
3- I complied it as a dynamic library with wmake libso.

then I have tested two things.
1-first I just added a libs ("mylibfinvoll.so"); to the controldict and start running and then I got the following message.

Code:


/*---------------------------------------------------------------------------*\
| =========                |                                                |
| \\      /  F ield        | OpenFOAM: The Open Source CFD Toolbox          |
|  \\    /  O peration    | Version:  2.0.x                                |
|  \\  /    A nd          | Web:      www.OpenFOAM.com                      |
|    \\/    M anipulation  |                                                |
\*---------------------------------------------------------------------------*/
Build  : 2.0.x
Exec  : ppplasmaFoam
Date  : Jul 31 2012
Time  : 10:26:01
Host  : octopus100.ubi.pt
PID    : 30164
Case  : /home/mahdi/OpenFOAM/mahdi-2.0.x/run/mmunfer
nProcs : 1
sigFpe : Enabling floating point exception trapping (FOAM_SIGFPE).
fileModificationChecking : Monitoring run-time modified files using timeStampMaster
allowSystemOperations : Disallowing user-supplied system call operations

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Create time

--> FOAM Warning :
    From function dlLibraryTable::open(const fileName&)
    in file db/dynamicLibrary/dlLibraryTable/dlLibraryTable.C at line 99
    could not load "mylibfinvoll.so"
Create fluid mesh for region MainAir for time = 0

Create solid mesh for region Dielectric for time = 0

Reading field p

Reading field U



--> FOAM FATAL IO ERROR:
Unknown patchField type compressible::myturbulentTemperatureCoupledBaffleMixed for patch type directMappedWall

Valid patchField types are :

98
(
MarshakRadiation
MarshakRadiationFixedT
advective
alphatJayatillekeWallFunction
alphatWallFunction
atmBoundaryLayerInletEpsilon
buoyantPressure
calculated
codedFixedValue
compressible::epsilonWallFunction
compressible::kqRWallFunction
compressible::omegaWallFunction
compressible::temperatureThermoBaffle1D<constSolidThermoPhysics>
compressible::temperatureThermoBaffle1D<expoSolidThermoPhysics>
compressible::turbulentHeatFluxTemperature
compressible::turbulentMixingLengthDissipationRateInlet
compressible::turbulentMixingLengthFrequencyInlet
compressible::turbulentTemperatureCoupledBaffle
compressible::turbulentTemperatureCoupledBaffleMixed
compressible::turbulentTemperatureRadCoupledMixed
cyclic
cyclicSlip
directMapped
directMappedField
directMappedFixedInternalValue
directMappedFixedPushedInternalValue
directionMixed
empty
epsilonWallFunction
fan
fanPressure
fixedEnthalpy
fixedFluxPressure
fixedGradient
fixedInternalEnergy
fixedInternalValue
fixedPressureCompressibleDensity
fixedValue
freestream
freestreamPressure
gradientEnthalpy
gradientInternalEnergy
greyDiffusiveRadiation
greyDiffusiveRadiationViewFactor
htcConvection
inletOutlet
inletOutletTotalTemperature
kappatJayatillekeWallFunction
kqRWallFunction
mixed
mixedEnthalpy
mixedInternalEnergy
mutLowReWallFunction
mutURoughWallFunction
mutUSpaldingWallFunction
mutUWallFunction
mutkRoughWallFunction
mutkWallFunction
nonuniformTransformCyclic
nuSgsUSpaldingWallFunction
nutLowReWallFunction
nutTabulatedWallFunction
nutURoughWallFunction
nutUSpaldingWallFunction
nutUWallFunction
nutkRoughWallFunction
nutkWallFunction
omegaWallFunction
oscillatingFixedValue
outletInlet
outletMappedUniformInlet
partialSlip
processor
processorCyclic
rotatingTotalPressure
selfContainedDirectMapped
sliced
slip
symmetryPlane
syringePressure
timeVaryingMappedFixedValue
timeVaryingTotalPressure
timeVaryingUniformFixedValue
totalFlowRateAdvectiveDiffusive
totalPressure
totalTemperature
turbulentHeatFluxTemperature
turbulentInlet
turbulentIntensityKineticEnergyInlet
turbulentMixingLengthDissipationRateInlet
turbulentMixingLengthFrequencyInlet
uniformDensityHydrostaticPressure
uniformFixedValue
wallHeatTransfer
waveTransmissive
wedge
wideBandDiffusiveRadiation
zeroGradient
)


file: /home/mahdi/OpenFOAM/mahdi-2.0.x/run/mmunfer/0/MainAir/phielec::boundaryField::interfaceA from line 27 to line 31.

    From function fvPatchField<Type>::New(const fvPatch&, const DimensionedField<Type, volMesh>&, const dictionary&)
    in file /home/mahdi/centFOAM//OpenFOAM/OpenFOAM-2.0.x/src/finiteVolume/lnInclude/fvPatchFieldNew.C at line 135.

FOAM exiting



2- secondly instead of adding the libentry in controldict i add the library to Option file my solver which looks like:

Code:


EXE_INC = \
    -Iinclude \
    -Ifluid \
    -Isolid \
    -I$(LIB_SRC)/meshTools/lnInclude \
    -I$(LIB_SRC)/turbulenceModels/incompressible/turbulenceModel \
    -I$(LIB_SRC)/transportModels \
    -I$(LIB_SRC)/transportModels/incompressible/singlePhaseTransportModel \
    -I$(LIB_SRC)/finiteVolume/lnInclude \
    -I$(LIB_SRC)/turbulenceModels \
    -I$(LIB_SRC)/thermophysicalModels/basicSolidThermo/lnInclude \
    -I$(LIB_SRC)/thermophysicalModels/specie/lnInclude \
    -I$(LIB_SRC)/turbulenceModels/compressible/turbulenceModel/lnInclude

EXE_LIBS = \
    -lincompressibleTurbulenceModel \
    -lincompressibleRASModels \
    -lincompressibleLESModels \
    -lincompressibleTransportModels \
    -lfiniteVolume \
    -lcompressibleRASModels \
    -lmeshTools \
    -lspecie \
    -L$(FOAM_USER_LIBBIN)/ \
    -lbasicSolidThermo

then I started running but I have got the following error:

Code:


*---------------------------------------------------------------------------*\
| =========                |                                                |
| \\      /  F ield        | OpenFOAM: The Open Source CFD Toolbox          |
|  \\    /  O peration    | Version:  2.0.x                                |
|  \\  /    A nd          | Web:      www.OpenFOAM.com                      |
|    \\/    M anipulation  |                                                |
\*---------------------------------------------------------------------------*/
Build  : 2.0.x
Exec  : ppplasmaFoam
Date  : Jul 31 2012
Time  : 10:45:33
Host  : octopus100.ubi.pt
PID    : 1158
Case  : /home/mahdi/OpenFOAM/mahdi-2.0.x/run/mmunfer
nProcs : 1
sigFpe : Enabling floating point exception trapping (FOAM_SIGFPE).
fileModificationChecking : Monitoring run-time modified files using timeStampMaster
allowSystemOperations : Disallowing user-supplied system call operations

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Create time

Create fluid mesh for region MainAir for time = 0

Create solid mesh for region Dielectric for time = 0

Reading field p

Reading field U



--> FOAM FATAL IO ERROR:
Unknown patchField type compressible::myturbulentTemperatureCoupledBaffleMixed for patch type directMappedWall

Valid patchField types are :

98
(
MarshakRadiation
MarshakRadiationFixedT
advective
alphatJayatillekeWallFunction
alphatWallFunction
atmBoundaryLayerInletEpsilon
buoyantPressure
calculated
codedFixedValue
compressible::epsilonWallFunction
compressible::kqRWallFunction
compressible::omegaWallFunction
compressible::temperatureThermoBaffle1D<constSolidThermoPhysics>
compressible::temperatureThermoBaffle1D<expoSolidThermoPhysics>
compressible::turbulentHeatFluxTemperature
compressible::turbulentMixingLengthDissipationRateInlet
compressible::turbulentMixingLengthFrequencyInlet
compressible::turbulentTemperatureCoupledBaffle
compressible::turbulentTemperatureCoupledBaffleMixed
compressible::turbulentTemperatureRadCoupledMixed
cyclic
cyclicSlip
directMapped
directMappedField
directMappedFixedInternalValue
directMappedFixedPushedInternalValue
directionMixed
empty
epsilonWallFunction
fan
fanPressure
fixedEnthalpy
fixedFluxPressure
fixedGradient
fixedInternalEnergy
fixedInternalValue
fixedPressureCompressibleDensity
fixedValue
freestream
freestreamPressure
gradientEnthalpy
gradientInternalEnergy
greyDiffusiveRadiation
greyDiffusiveRadiationViewFactor
htcConvection
inletOutlet
inletOutletTotalTemperature
kappatJayatillekeWallFunction
kqRWallFunction
mixed
mixedEnthalpy
mixedInternalEnergy
mutLowReWallFunction
mutURoughWallFunction
mutUSpaldingWallFunction
mutUWallFunction
mutkRoughWallFunction
mutkWallFunction
nonuniformTransformCyclic
nuSgsUSpaldingWallFunction
nutLowReWallFunction
nutTabulatedWallFunction
nutURoughWallFunction
nutUSpaldingWallFunction
nutUWallFunction
nutkRoughWallFunction
nutkWallFunction
omegaWallFunction
oscillatingFixedValue
outletInlet
outletMappedUniformInlet
partialSlip
processor
processorCyclic
rotatingTotalPressure
selfContainedDirectMapped
sliced
slip
symmetryPlane
syringePressure
timeVaryingMappedFixedValue
timeVaryingTotalPressure
timeVaryingUniformFixedValue
totalFlowRateAdvectiveDiffusive
totalPressure
totalTemperature
turbulentHeatFluxTemperature
turbulentInlet
turbulentIntensityKineticEnergyInlet
turbulentMixingLengthDissipationRateInlet
turbulentMixingLengthFrequencyInlet
uniformDensityHydrostaticPressure
uniformFixedValue
wallHeatTransfer
waveTransmissive
wedge
wideBandDiffusiveRadiation
zeroGradient
)


file: /home/mahdi/OpenFOAM/mahdi-2.0.x/run/mmunfer/0/MainAir/phielec::boundaryField::interfaceA from line 27 to line 31.

    From function fvPatchField<Type>::New(const fvPatch&, const DimensionedField<Type, volMesh>&, const dictionary&)
    in file /home/mahdi/centFOAM//OpenFOAM/OpenFOAM-2.0.x/src/finiteVolume/lnInclude/fvPatchFieldNew.C at line 135.

FOAM exiting


Do you think that it it could be related to DL_LIBrary_PATH?
I have readed in some of the threads in forum.

Best
Mahdi

wyldckat July 31, 2012 06:24

In a nutshell:
  • It should be "libmyfinvoll.so", not "mylibfinvoll.so".
  • In your solver you don't have "-lmyfinvoll".

mm.abdollahzadeh July 31, 2012 07:07

Dear Burno

Thanks for your kind reply

I have corrected the name. but it didn't solved. if i don't add in the solver I will receive the same message.
but if add it it will gives the follwing error:
Code:

g++ -m64 -Dlinux64 -DWM_DP -Wall -Wextra -Wno-unused-parameter -Wold-style-cast -O3  -DNoRepository -ftemplate-depth-100 -Iinclude -Ifluid -Isolid -I/home/mahdi/centFOAM//OpenFOAM/OpenFOAM-2.0.x/src/meshTools/lnInclude -I/home/mahdi/centFOAM//OpenFOAM/OpenFOAM-2.0.x/src/turbulenceModels/incompressible/turbulenceModel -I/home/mahdi/centFOAM//OpenFOAM/OpenFOAM-2.0.x/src/transportModels -I/home/mahdi/centFOAM//OpenFOAM/OpenFOAM-2.0.x/src/transportModels/incompressible/singlePhaseTransportModel -I/home/mahdi/centFOAM//OpenFOAM/OpenFOAM-2.0.x/src/finiteVolume/lnInclude -I/home/mahdi/centFOAM//OpenFOAM/OpenFOAM-2.0.x/src/turbulenceModels -I/home/mahdi/OpenFOAM/mahdi-2.0.x/src/MultiRegionBound/lnInclude -I/home/mahdi/centFOAM//OpenFOAM/OpenFOAM-2.0.x/src/thermophysicalModels/basicSolidThermo/lnInclude -I/home/mahdi/centFOAM//OpenFOAM/OpenFOAM-2.0.x/src/thermophysicalModels/specie/lnInclude -I/home/mahdi/centFOAM//OpenFOAM/OpenFOAM-2.0.x/src/turbulenceModels/compressible/turbulenceModel/lnInclude  -IlnInclude -I. -I/home/mahdi/centFOAM//OpenFOAM/OpenFOAM-2.0.x/src/OpenFOAM/lnInclude -I/home/mahdi/centFOAM//OpenFOAM/OpenFOAM-2.0.x/src/OSspecific/POSIX/lnInclude  -fPIC -Xlinker --add-needed Make/linux64Gcc45DPOpt/incompressibleCourantNo.o Make/linux64Gcc45DPOpt/solidRegionDiffNo.o Make/linux64Gcc45DPOpt/ppplasmaFoam.o -L/home/mahdi/centFOAM//OpenFOAM/OpenFOAM-2.0.x/platforms/linux64Gcc45DPOpt/lib \
        -lincompressibleTurbulenceModel -lincompressibleRASModels -lincompressibleLESModels -lincompressibleTransportModels -lfiniteVolume -lcompressibleRASModels -lmeshTools -lspecie -lmyfinvoll -lbasicSolidThermo  -lOpenFOAM -ldl  -lm -o /home/mahdi/OpenFOAM/mahdi-2.0.x/platforms/linux64Gcc45DPOpt/bin/ppplasmaFoam
/usr/bin/ld: cannot find -lmyfinvoll
collect2: ld returned 1 exit status
make: *** [/home/mahdi/OpenFOAM/mahdi-2.0.x/platforms/linux64Gcc45DPOpt/bin/ppplasmaFoam] Error 1

best mahdi

wyldckat July 31, 2012 16:45

Hi Mahdi,

I'm too tired right now to guess was going on wrong... well, I can guess that you removed the last "-L*" line and replaced it with the "-lmyfinvoll", when you should have added the last one.

Either way, here are a few tutorials on how to modify OpenFOAM code for personal modifications, for you to study and draw ideas from:
Best regards,
Bruno

mm.abdollahzadeh August 2, 2012 10:52

Dear Buruno

Thanks for your kind reply.... the first problem as you mwntioned was with the name of library.
and the second was that I didnt add the correct libralry when compiling my own library ...( but it was compiling correctly and without any waring or error!!!)...

When I add that library and changed the name, it works :)...

Thanks for your help.


All times are GMT -4. The time now is 10:01.