|
[Sponsors] |
October 20, 2020, 07:07 |
Adding Libraries to OpenFOAM
|
#1 |
New Member
Mohammad Khojastehmehr
Join Date: Jul 2020
Posts: 20
Rep Power: 6 |
Hi everybody, hope you are doing fine!
There is a library that I wanted to add to OpenFOAM called "Reaktoro". Here is a link to the source: https://github.com/reaktoro/reaktoro Unfortunately, I don't know much about C++ so I would be very appreciative if someone can help me with this in detail. I know it has something to do with options in the make folder but I don't know exactly how I can add this library in this case; since there are a bunch of folders in the source file. I've read somethings about libraries in OpenFOAM but I'm a little bit confused; perhaps because I don't know the basics. https://cfd.direct/openfoam/user-gui...-applications/ Thank you so much. |
|
October 20, 2020, 12:45 |
Put the source in the make folder
|
#2 |
New Member
Mohammad Khojastehmehr
Join Date: Jul 2020
Posts: 20
Rep Power: 6 |
I realized all you have to do is to create a folder named lnInclude in your solver folder. Then put the whole source into this lnInclude.
Last edited by MCrossover97; October 21, 2020 at 09:42. |
|
October 21, 2020, 09:49 |
undefined reference to ...
|
#3 |
New Member
Mohammad Khojastehmehr
Join Date: Jul 2020
Posts: 20
Rep Power: 6 |
Now I'm getting some errors making the solver:
Code:
g++ -std=c++11 -m64 -Dlinux64 -DWM_ARCH_OPTION=64 -DWM_DP -DWM_LABEL_SIZE=32 -Wall -Wextra -Wold-style-cast -Wnon-virtual-dtor -Wno-unused-parameter -Wno-invalid-offsetof -Wno-attributes -O3 -DNoRepository -ftemplate-depth-100 -I/opt/openfoam8/src/finiteVolume/lnInclude -I/opt/openfoam8/src/meshTools/lnInclude -IlnInclude -I. -I/opt/openfoam8/src/OpenFOAM/lnInclude -I/opt/openfoam8/src/OSspecific/POSIX/lnInclude -fPIC -fuse-ld=bfd -Xlinker --add-needed -Xlinker --no-as-needed Make/linux64GccDPInt32Opt/reaktoroFOAM.o -L/opt/openfoam8/platforms/linux64GccDPInt32Opt/lib \ -lfiniteVolume -lmeshTools -lOpenFOAM -ldl \ -lm -o /home/mcrossover97/OpenFOAM/mcrossover97-8/platforms/linux64GccDPInt32Opt/bin/reaktoroFOAM.C Make/linux64GccDPInt32Opt/reaktoroFOAM.o: In function `main': reaktoroFOAM.C:(.text.startup+0x60): undefined reference to `Reaktoro::ChemicalEditor::ChemicalEditor()' reaktoroFOAM.C:(.text.startup+0x6f): undefined reference to `Reaktoro::StringList::StringList(char const*)' reaktoroFOAM.C:(.text.startup+0x7a): undefined reference to `Reaktoro::ChemicalEditor::addAqueousPhaseWithElementsOf(Reaktoro::StringList const&)' reaktoroFOAM.C:(.text.startup+0x82): undefined reference to `Reaktoro::StringList::~StringList()' reaktoroFOAM.C:(.text.startup+0x91): undefined reference to `Reaktoro::StringList::StringList(char const*)' reaktoroFOAM.C:(.text.startup+0x9c): undefined reference to `Reaktoro::ChemicalEditor::addGaseousPhase(Reaktoro::StringList const&)' reaktoroFOAM.C:(.text.startup+0xa4): undefined reference to `Reaktoro::StringList::~StringList()' reaktoroFOAM.C:(.text.startup+0xb3): undefined reference to `Reaktoro::StringList::StringList(char const*)' reaktoroFOAM.C:(.text.startup+0xbe): undefined reference to `Reaktoro::ChemicalEditor::addMineralPhase(Reaktoro::StringList const&)' reaktoroFOAM.C:(.text.startup+0xc6): undefined reference to `Reaktoro::StringList::~StringList()' reaktoroFOAM.C:(.text.startup+0xd1): undefined reference to `Reaktoro::ChemicalEditor::operator Reaktoro::ChemicalSystem() const' reaktoroFOAM.C:(.text.startup+0xe1): undefined reference to `Reaktoro::EquilibriumProblem::EquilibriumProblem(Reaktoro::ChemicalSystem const&)' reaktoroFOAM.C:(.text.startup+0x11f): undefined reference to `Reaktoro::EquilibriumProblem::add(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)' reaktoroFOAM.C:(.text.startup+0x179): undefined reference to `Reaktoro::EquilibriumProblem::add(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)' reaktoroFOAM.C:(.text.startup+0x1d3): undefined reference to `Reaktoro::EquilibriumProblem::add(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)' reaktoroFOAM.C:(.text.startup+0x22d): undefined reference to `Reaktoro::EquilibriumProblem::add(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)' reaktoroFOAM.C:(.text.startup+0x263): undefined reference to `Reaktoro::equilibrate(Reaktoro::EquilibriumProblem const&)' reaktoroFOAM.C:(.text.startup+0x282): undefined reference to `Reaktoro::ChemicalState::output(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int) const' reaktoroFOAM.C:(.text.startup+0x29d): undefined reference to `Reaktoro::ChemicalState::~ChemicalState()' reaktoroFOAM.C:(.text.startup+0x2a5): undefined reference to `Reaktoro::EquilibriumProblem::~EquilibriumProblem()' reaktoroFOAM.C:(.text.startup+0x2ad): undefined reference to `Reaktoro::ChemicalSystem::~ChemicalSystem()' reaktoroFOAM.C:(.text.startup+0x2b5): undefined reference to `Reaktoro::ChemicalEditor::~ChemicalEditor()' reaktoroFOAM.C:(.text.startup+0x305): undefined reference to `Reaktoro::ChemicalState::~ChemicalState()' reaktoroFOAM.C:(.text.startup+0x310): undefined reference to `Reaktoro::EquilibriumProblem::~EquilibriumProblem()' reaktoroFOAM.C:(.text.startup+0x318): undefined reference to `Reaktoro::ChemicalSystem::~ChemicalSystem()' reaktoroFOAM.C:(.text.startup+0x320): undefined reference to `Reaktoro::ChemicalEditor::~ChemicalEditor()' reaktoroFOAM.C:(.text.startup+0x381): undefined reference to `Reaktoro::StringList::~StringList()' collect2: error: ld returned 1 exit status /opt/openfoam8/wmake/makefiles/general:140: recipe for target '/home/mcrossover97/OpenFOAM/mcrossover97-8/platforms/linux64GccDPInt32Opt/bin/reaktoroFOAM.C' failed make: *** [/home/mcrossover97/OpenFOAM/mcrossover97-8/platforms/linux64GccDPInt32Opt/bin/reaktoroFOAM.C] Error 1 |
|
October 21, 2020, 18:46 |
|
#4 |
New Member
Join Date: Feb 2020
Posts: 3
Rep Power: 6 |
Did you build the Reaktoro library? Following the guide for building Reaktoro you should end up with a directory called "build" that probably contains a folder with the .so files and another one with the headers (.H files).
Once you built Reaktoro you can use it in OpenFOAM by adding to the Make/options: - The positions of the headers in EXE_INC - The positions of the .so files and the name of the built libraries that you are using in EXE_LIBS. For example, if you build the boost libraries you end up with a folder containing two other folders: include and lib. "include" contains the headers, while "lib" contains the compiled libraries in .so files. One of these files is libboost_system.so. To add this file to the Make/options file you should write something like: EXE_INC = \ ... -I<path/to/include> \ ... EXE_LIBS = \ ... -L<path/to/lib> \ -lboost_system \ ... The folder lnInclude is automatically generated when you use wmake to compile, you sould not create it |
|
October 21, 2020, 20:17 |
error while loading shared libraries
|
#5 | |
New Member
Mohammad Khojastehmehr
Join Date: Jul 2020
Posts: 20
Rep Power: 6 |
Quote:
Thank you so much for your answer. I build the library using miniconda with this command: Code:
conda install reaktoro Code:
reaktoroFOAM.C: error while loading shared libraries: libReaktoro.so: cannot open shared object file: No such file or directory This is the body of the solver: Code:
#include <Reaktoro/Reaktoro.hpp> using namespace Reaktoro; int main() { ChemicalEditor editor; editor.addAqueousPhaseWithElementsOf("H2O NaCl CaCO3 CO2"); editor.addGaseousPhase("CO2(g)"); editor.addMineralPhase("Calcite"); ChemicalSystem system(editor); EquilibriumProblem problem(system); problem.add("H2O", 1, "kg"); problem.add("CO2", 1, "mol"); problem.add("NaCl", 0.7, "mol"); problem.add("CaCO3", 1, "g"); ChemicalState state = equilibrate(problem); state.output("result.txt"); } Code:
EXE_INC = \ -I/home/mcrossover97/miniconda3/include EXE_LIBS = \ -L/home/mcrossover97/miniconda3/lib \ -lReaktoro Code:
reaktoroFOAM.C EXE = $(FOAM_USER_APPBIN)/reaktoroFOAM.C Mohammad |
||
October 22, 2020, 02:22 |
|
#6 |
Senior Member
Join Date: Aug 2013
Posts: 407
Rep Power: 16 |
Hi,
You might also have to location of the folder containing libReaktoro.so to the environment variable LD_LIBRARY_PATH Hope this helps. Cheers, Antimony |
|
October 22, 2020, 02:54 |
|
#7 |
New Member
Join Date: Feb 2020
Posts: 3
Rep Power: 6 |
You can update LD_LIBRARY_PATH with the position of libReaktoro.so. with the following command:
LD_LIBRARY_PATH=‘$LD_LIBRARY_PATH:<path/to/folder-with-libReaktoro.so>’ Also, you are missing return 0; at the end of the main. int main() { ... state.output("result.txt"); return 0; } While the Make/file shuld be like this: reaktoroFOAM.C EXE = $(FOAM_USER_APPBIN)/reaktoroFOAM Otherwise your exe would be called reaktoroFOAM.C |
|
October 22, 2020, 07:33 |
Done!
|
#8 | ||
New Member
Mohammad Khojastehmehr
Join Date: Jul 2020
Posts: 20
Rep Power: 6 |
Quote:
Quote:
Code:
LD_LIBRARY_PATH=‘$LD_LIBRARY_PATH:</home/mcrossover97/miniconda3/lib>’ Code:
echo $LD_LIBRARY_PATH Then I tried to update the LD_LIBRARY_PATH with the following command: Code:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/mcrossover97/miniconda3/lib |
|||
November 6, 2020, 03:42 |
Problem adding in Ubuntu
|
#9 |
New Member
Mohammad Khojastehmehr
Join Date: Jul 2020
Posts: 20
Rep Power: 6 |
Hey Sorry to bother you guys again.
Now I want to do all the procedure in Ubuntu 18.04 (not WSL). I have done exactly the same things; but I cannot even make the solver, because it gives me this error: Code:
(base) mohammad@mohammad-VirtualBox:~/OpenFOAM/mohammad-8/applications/solvers/reaktoroFoam$ wmake g++ -std=c++11 -m64 -Dlinux64 -DWM_ARCH_OPTION=64 -DWM_DP -DWM_LABEL_SIZE=32 -Wall -Wextra -Wold-style-cast -Wnon-virtual-dtor -Wno-unused-parameter -Wno-invalid-offsetof -Wno-attributes -O3 -DNoRepository -ftemplate-depth-100 -I/opt/openfoam8/src/finiteVolume/lnInclude -I/opt/openfoam8/src/meshTools/lnInclude -I/home/mohammad/miniconda3/include -IlnInclude -I. -I/opt/openfoam8/src/OpenFOAM/lnInclude -I/opt/openfoam8/src/OSspecific/POSIX/lnInclude -fPIC -fuse-ld=bfd -Xlinker --add-needed -Xlinker --no-as-needed Make/linux64GccDPInt32Opt/reaktoroFoam.o -L/opt/openfoam8/platforms/linux64GccDPInt32Opt/lib \ -L/home/mohammad/miniconda3/lib -lfiniteVolume -lmeshTools -lreaktoro -lOpenFOAM -ldl \ -lm -o /home/mohammad/OpenFOAM/mohammad-8/platforms/linux64GccDPInt32Opt/bin/reaktoroFoam /usr/bin/ld.bfd: cannot find -lreaktoro collect2: error: ld returned 1 exit status /opt/openfoam8/wmake/makefiles/general:140: recipe for target '/home/mohammad/OpenFOAM/mohammad-8/platforms/linux64GccDPInt32Opt/bin/reaktoroFoam' failed make: *** [/home/mohammad/OpenFOAM/mohammad-8/platforms/linux64GccDPInt32Opt/bin/reaktoroFoam] Error 1 Code:
EXE_INC = \ -I$(LIB_SRC)/finiteVolume/lnInclude \ -I$(LIB_SRC)/meshTools/lnInclude \ -I/home/mohammad/miniconda3/include EXE_LIBS = \ -L/home/mohammad/miniconda3/lib \ -lfiniteVolume \ -lmeshTools \ -lreaktoro Code:
(base) mohammad@mohammad-VirtualBox:~/OpenFOAM/mohammad-8/applications/solvers/reaktoroFoam$ echo $LD_LIBRARY_PATH ‘/opt/ThirdParty-8/platforms/linux64Gcc/gperftools-svn/lib:/opt/paraviewopenfoam56/lib:/opt/openfoam8/platforms/linux64GccDPInt32Opt/lib/openmpi-system:/opt/ThirdParty-8/platforms/linux64GccDPInt32/lib/openmpi-system:/usr/lib/x86_64-linux-gnu/openmpi/lib:/home/mohammad/OpenFOAM/mohammad-8/platforms/linux64GccDPInt32Opt/lib:/opt/site/8/platforms/linux64GccDPInt32Opt/lib:/opt/openfoam8/platforms/linux64GccDPInt32Opt/lib:/opt/ThirdParty-8/platforms/linux64GccDPInt32/lib:/opt/openfoam8/platforms/linux64GccDPInt32Opt/lib/dummy::/home/mohammad/miniconda3/lib Thank you so much for your help again! Mohammad |
|
October 26, 2021, 07:37 |
|
#10 |
New Member
David Moravec
Join Date: Mar 2020
Posts: 1
Rep Power: 0 |
Im very late, but maybe it is because you seem to have double : before path to reaktoro library in your LD_LIBRARY_PATH
|
|
February 23, 2024, 03:34 |
|
#11 | |
New Member
Join Date: Aug 2022
Posts: 19
Rep Power: 4 |
hi try changing your options as shown below
Quote:
libReaktoro.so is a dynamically link so OS need to know its location at runtime an this can be done using -Wl,-rpath=<location of your library> |
||
Tags |
library |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
OpenFOAM v3.0+ ?? | SBusch | OpenFOAM | 22 | December 26, 2016 15:24 |
chtMultiRegionSimpleFoam | samiam1000 | OpenFOAM Running, Solving & CFD | 39 | March 31, 2016 09:43 |
New OpenFOAM Forum Structure | jola | OpenFOAM | 2 | October 19, 2011 07:55 |
Adding Radiation Sub-models into OpenFOAM 1.5 | shajitah | OpenFOAM | 0 | September 13, 2010 22:26 |
OpenFOAM Training and Workshop Zagreb 2628Jan2006 | hjasak | OpenFOAM | 1 | February 2, 2006 22:07 |