CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

Adding Libraries to OpenFOAM

Register Blogs Community New Posts Updated Threads Search

Like Tree5Likes
  • 1 Post By EdoardoCip
  • 1 Post By MCrossover97
  • 1 Post By Antimony
  • 1 Post By EdoardoCip
  • 1 Post By Dcn

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 20, 2020, 07:07
Default Adding Libraries to OpenFOAM
  #1
New Member
 
Mohammad Khojastehmehr
Join Date: Jul 2020
Posts: 20
Rep Power: 6
MCrossover97 is on a distinguished road
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.
MCrossover97 is offline   Reply With Quote

Old   October 20, 2020, 12:45
Default Put the source in the make folder
  #2
New Member
 
Mohammad Khojastehmehr
Join Date: Jul 2020
Posts: 20
Rep Power: 6
MCrossover97 is on a distinguished road
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.
MCrossover97 is offline   Reply With Quote

Old   October 21, 2020, 09:49
Default undefined reference to ...
  #3
New Member
 
Mohammad Khojastehmehr
Join Date: Jul 2020
Posts: 20
Rep Power: 6
MCrossover97 is on a distinguished road
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
I can't understand what I'm missing. I'm still wondering is there anything I should have done more? Does it have anything to do with .so files? I can't see any .so file in the source folder so that I can put them in the option under EXE_LIBS. Should I somehow create these .so files? I'm confused. any help would be greatly appreciated.
MCrossover97 is offline   Reply With Quote

Old   October 21, 2020, 18:46
Default
  #4
New Member
 
Join Date: Feb 2020
Posts: 3
Rep Power: 6
EdoardoCip is on a distinguished road
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
MCrossover97 likes this.
EdoardoCip is offline   Reply With Quote

Old   October 21, 2020, 20:17
Default error while loading shared libraries
  #5
New Member
 
Mohammad Khojastehmehr
Join Date: Jul 2020
Posts: 20
Rep Power: 6
MCrossover97 is on a distinguished road
Quote:
Originally Posted by EdoardoCip View Post
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
Dear EdoardoCip,

Thank you so much for your answer. I build the library using miniconda with this command:
Code:
conda install reaktoro
I followed your instructions and now I am able to make the solver without any error; but now when I want to call my solver (reaktoroFOAM), it gives me this error:
Code:
reaktoroFOAM.C: error while loading shared libraries: libReaktoro.so: cannot open shared object file: No such file or directory
Did I miss something?

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");
}
And this is what is in the option file:
Code:
EXE_INC = \
	-I/home/mcrossover97/miniconda3/include
	
	

EXE_LIBS = \
	-L/home/mcrossover97/miniconda3/lib \
	-lReaktoro
and make file:
Code:
reaktoroFOAM.C

EXE = $(FOAM_USER_APPBIN)/reaktoroFOAM.C
I appreciate your help so much,
Mohammad
SHUBHAM9595 likes this.
MCrossover97 is offline   Reply With Quote

Old   October 22, 2020, 02:22
Default
  #6
Senior Member
 
Join Date: Aug 2013
Posts: 407
Rep Power: 16
Antimony is on a distinguished road
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
MCrossover97 likes this.
Antimony is offline   Reply With Quote

Old   October 22, 2020, 02:54
Default
  #7
New Member
 
Join Date: Feb 2020
Posts: 3
Rep Power: 6
EdoardoCip is on a distinguished road
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
MCrossover97 likes this.
EdoardoCip is offline   Reply With Quote

Old   October 22, 2020, 07:33
Default Done!
  #8
New Member
 
Mohammad Khojastehmehr
Join Date: Jul 2020
Posts: 20
Rep Power: 6
MCrossover97 is on a distinguished road
Quote:
Originally Posted by Antimony View Post
You might also have to location of the folder containing libReaktoro.so to the environment variable LD_LIBRARY_PATH
Quote:
Originally Posted by EdoardoCip View Post
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>’
I tried to update LD_LIBRARY_PATH with the following command:
Code:
LD_LIBRARY_PATH=‘$LD_LIBRARY_PATH:</home/mcrossover97/miniconda3/lib>’
It didn't give me any error but apparently, nothing had happened as I checked it to make sure it is updated:
Code:
echo $LD_LIBRARY_PATH
but it wasn't.

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
Now it works! Thank you so much for your help and time!
MCrossover97 is offline   Reply With Quote

Old   November 6, 2020, 03:42
Default Problem adding in Ubuntu
  #9
New Member
 
Mohammad Khojastehmehr
Join Date: Jul 2020
Posts: 20
Rep Power: 6
MCrossover97 is on a distinguished road
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
The contents of the files are same as before:
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
And the LD_LIBRARY_PATH is updated:
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
What would possibly be different between WSL and Ubuntu on VirtualBox?
Thank you so much for your help again!
Mohammad
MCrossover97 is offline   Reply With Quote

Old   October 26, 2021, 07:37
Default
  #10
New Member
 
David Moravec
Join Date: Mar 2020
Posts: 1
Rep Power: 0
dmoravec is on a distinguished road
Im very late, but maybe it is because you seem to have double : before path to reaktoro library in your LD_LIBRARY_PATH
dmoravec is offline   Reply With Quote

Old   February 23, 2024, 03:34
Default
  #11
Dcn
New Member
 
Join Date: Aug 2022
Posts: 19
Rep Power: 4
Dcn is on a distinguished road
hi try changing your options as shown below

Quote:
EXE_INC = \
-I/home/mcrossover97/miniconda3/include



EXE_LIBS = \
-Wl,-rpath=/home/mcrossover97/miniconda3/lib \
-L/home/mcrossover97/miniconda3/lib \
-lReaktoro
it should work i think after this change
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>
aee likes this.
Dcn is offline   Reply With Quote

Reply

Tags
library


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


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


All times are GMT -4. The time now is 20:26.