how to link an external library with YADE

Asked by Tao

Hi all,
I'm trying to link an external library with YADE, but I don't know how to do that. In fact, I need one external library to calculate fluid dynamics and this library is a .so file, named libIcoFoam.so. Now, in my YADE folder, I create a corresponding engine named fluidDragForce.cpp. I'm trying to use one function in the external library libIcoFoam.so in this engine. The issue is that I need the engine know where to find this library to process its calculation.

Could anyone help me with that?

Cheers,
Tao

Question information

Language:
English Edit question
Status:
Solved
For:
Yade Edit question
Assignee:
No assignee Edit question
Solved by:
Tao
Solved:
Last query:
Last reply:
Revision history for this message
Bruno Chareyre (bruno-chareyre) said :
#1

It should be enough to add the library in your scons.profile.
You can just compile with "scons SHCCFLAGS="-lIcoFoam", then it will be added into the profile (and next time, you just type "scons"), else you edit the profile and include it manually.
If it needs a path, you add it to LIBPATH, the same way.
Do you plan to commit this coupling code one day? It would be a very interesting development.

Bruno

Revision history for this message
Tao (aaronztao) said :
#2

Hi Bruno,
Thanks a lot for your reply. Yes, I plan to commit this coupling code one day.
I tried your suggestion to link the library, but one more problem still exists when I use the engine. Please see bellow:

131 FATAL yade.Omega /home/tao/trunk/core/Omega.cpp:204 loadPlugins: /home/tao/YADE/lib/yade-bzr2866/plugins/libplugins.so: undefined symbol `icoFoam(..........)'

Actually, 'icoFoam' is just the function I want to use in the fluidDragForce engine. I'm not sure why YADE cannot locate the engine. Do I need to explicitly write the library path in the fluidDragForce.cpp?

Thanks.

Cheers,
Tao

Revision history for this message
Bruno Chareyre (bruno-chareyre) said :
#3

The libpath is for the linker. You don't type it in any cpp usually, but
add the path to linker flags.
What is the output of "scons -h"? and in which directory is the library
on your system?
Sorry to ask basic questions, but, you recompiled right?

Revision history for this message
Tao (aaronztao) said :
#4

Hi Bruno,
The information in scons.profile-default is:

PREFIX = '/home/tao/YADE'
features = 'gts,log4cxx,opengl,openmp,qt4,vtk'
CPPPATH = '/usr/include/vtk-5.0:/usr/include/vtk-5.2:/usr/include/vtk-5.4:/usr/include/vtk-5.6:/usr/include/vtk:/home/tao/yadeopenfoam:/usr/include/eigen2'
LIBPATH = '/home/tao/yadefluid'
CXXFLAGS = []
SHCCFLAGS = ['-lIcoFoam', '-fPIC']

As for the last line, I have to add '-fPIC' to process the compilation. If not, some problems will occur. The compilation is correct with the message: "scons: done building targets." However, when I tried to test this engine in my script, problems as posted before occur.

The output of "scons -h" are listed as bellow:

tao@ubuntu:~/trunk$ scons -h
scons: Reading SConscript files ...
@@@ Using profile default (scons.profile-default) @@@
Eigen 2 math library will be used
Yade version is `bzr2866' (bzr2866), installed files will be suffixed with `-bzr2866'.
All intermediary files will be in `/home/tao/build-bzr2866'.
Checking whether c++ compiler "g++" works...(cached) yes
Finding libstdc++ library... (cached) /usr/lib/libstdc++.so.6
Checking for pthread_exit(NULL) in C library pthread... (cached) yes
Checking for Python development files... (cached) ok
Checking for C++ header file numpy/ndarrayobject.h... (cached) yes
Checking for required python modules... (cached) all ok
Checking boost libraries... (cached) all ok
Checking for C++ header file boost/foreach.hpp... (cached) yes
Checking for C++ header file Eigen/Core... (cached) yes
Checking for C++ header file loki/NullType.h... (cached) yes
Checking for glutGetModifiers() in C++ library glut... (cached) yes
Checking for QGLViewer() in C++ library qglviewer-qt4... (cached) yes
Checking for vtkInstantiator::New() in C++ library vtkCommon... (cached) yes
Checking for gts_object_class() in C++ library gts... (cached) yes
Checking for log4cxx::Logger::getLogger("") in C++ library log4cxx... (cached) yes
scons: done reading SConscript files.

PREFIX: Install path prefix
    default: /usr/local
    actual: /home/tao/YADE

runtimePREFIX: Runtime path prefix; DO NOT USE, inteded for packaging only.
    default: None
    actual: /home/tao/YADE

variant: Build variant, will be suffixed to all files, along with version.
    default:
    actual:

debug: Enable debugging information (yes|no)
    default: 0
    actual: False

gprof: Enable profiling information for gprof (yes|no)
    default: 0
    actual: False

optimize: Turn on optimizations (-1, 0 or 1); negative value sets optimization based on debugging: not optimize with debugging and vice versa.
    default: -1
    actual: True

PGO: Whether to "gen"erate or "use" Profile-Guided Optimization (|gen|use)
    default:
    actual:

features: Optional features that are turned on
    (all|none|comma-separated list of names)
    allowed names: opengl log4cxx cgal openmp gts vtk gl2ps qt4 sphere-padder never_use_this_one subdomains
    default: log4cxx,opengl,gts,openmp,vtk,qt4
    actual: gts log4cxx opengl openmp qt4 vtk

jobs: Number of jobs to run at the same time (same as -j, but saved)
    default: 2
    actual: 2

buildPrefix: Where to create build-[version][variant] directory for intermediary files
    default: ..
    actual: ..

hotPlugins: Files (without the .cpp extension) that will be compiled separately even in the monolithic build (use for those that you modify frequently); comma-separated.
    default:
    actual:

chunkSize: Maximum files to compile in one translation unit when building plugins. (unlimited if <= 0, per-file linkage is used if 1)
    default: 7
    actual: 7

version: Yade version (if not specified, guess will be attempted)
    default: None
    actual: None

realVersion: Revision (usually bzr revision); guessed automatically unless specified
    default: None
    actual: None

CPPPATH: Additional paths for the C preprocessor (colon-separated)
    default: /usr/include/vtk-5.0:/usr/include/vtk-5.2:/usr/include/vtk-5.4:/usr/include/vtk-5.6:/usr/include/vtk
    actual: /usr/include/vtk-5.0 /usr/include/vtk-5.2 /usr/include/vtk-5.4 /usr/include/vtk-5.6 /usr/include/vtk /home/tao/yadeopenfoam /usr/include/eigen2

LIBPATH: Additional paths for the linker (colon-separated)
    default: None
    actual: /home/tao/yadefluid

libstdcxx: Specify libstdc++ location by hand (opened dynamically at startup), usually not needed
    default: None
    actual: None

QT4CXX: Specify a different compiler for files including qt4; this is necessary for older qt version (<=4.7) which don't compile with clang
    default: None
    actual: None

QT4DIR: Directory where Qt4 is installed
    default: /usr/share/qt4
    actual: /usr/share/qt4

PATH: Path (not imported automatically from the shell) (colon-separated)
    default: None
    actual: None

CXX: The c++ compiler
    default: g++
    actual: g++

CXXFLAGS: Additional compiler flags for compilation (like -march=core2).
    default: None
    actual:

march: Architecture to use with -march=... when optimizing
    default: native
    actual: native

execCheck: Name of the main script that should be installed; if the current one differs, an error is raised (do not use directly, only intended for --rebuild
    default: None
    actual: None

defThreads: No longer used, specify -j each time yade is run (defaults to 1 now)
    default: -1
    actual: -1

SHCCFLAGS: Additional compiler flags for linking (for plugins).
    default: None
    actual: -lIcoFoam -fPIC

QUAD_PRECISION: typedef Real as long double (=quad) (yes|no)
    default: 0
    actual: False

brief: Don't show commands being run, only what files are being compiled/linked/installed (yes|no)
    default: True
    actual: True

Use scons -H for help about command-line options.

Thanks a lot.

Cheers,
Tao

Revision history for this message
Bruno Chareyre (bruno-chareyre) said :
#5

> > and in which directory is the library
> on your system?

Revision history for this message
Tao (aaronztao) said :
#6

Hi Bruno,
The directory of the library is $HOME/yadefluid and the directory of yade is $HOME/trunk on my computer system.
I'm not sure if there is something wrong with the link or the library itself. I will try to check it.

Thanks a lot.

Cheers,
Tao

Revision history for this message
Bruno Chareyre (bruno-chareyre) said :
#7

Ok thanks, I was not sure if it was yade dir or lib dir.
Can you can compile/run a small example programs using this lib?
Is it better if you add "-licoFoam" to CXXFLAGS instead of of SHCCFLAGS
(or both, it can't hurt)?

Revision history for this message
Tao (aaronztao) said :
#8

Hi,
Now I can link the library "-licoFoam" with YADE by editing the line "env.Append(CPPPATH='',LIBPATH='/home/tao/YADE/lib/yade-0.11.1/pkg-dem',LIBS='IcoFoam',CXXFLAGS='',SHCCFLAGS='')" in $HOME/trunk/SConstruct and the line in $HOME/trunk/scons.profile-default.
Actually, this libIcoFoam.so links YADE with one CFD software OpenFOAM and it will call one library named libparMetisDecomp.so in OpenFOAM. When I try to run YADE, one error occurs that indicates as bellow:

Welcome to Yade bzr2857
Traceback (most recent call last):
  File "/home/tao/YADE/bin/yade-bzr2857", line 118, in <module>
    import yade
  File "/home/tao/YADE/lib/yade-bzr2857/py/yade/__init__.py", line 58, in <module>
    import boot
ImportError: /home/tao/OpenFOAM/OpenFOAM-1.7.1/lib/linux64GccDPOpt/dummy/libparMetisDecomp.so: undefined symbol: _ZN4Foam10FatalErrorE

I'm not sure if it's just a problem with the link or with the library libparMetisDecomp.so.

Thanks a lot for your help.

Cheers,
Tao

Revision history for this message
Bruno Chareyre (bruno-chareyre) said :
#9

1/ You should really try to compile a simple program out of yade first,
with a simple makefile, so you know where problems come from.
This error means (I think) that libparMetisDecomp has other dependencies
(e.g. blas, lapack, or whatever it can be), you would have find this
with a simple "helloOFoamWorld" program.
2/ Don't modify $HOME/trunk/SConstruct or profile.default. They are root
system files that you will (almost) never commit. Create user-defined
profile:
"scons profile='name' CXXFLAGS=... SHCCFLAGS=... ". It has the same
result, except that it will be easier for you and us to understand what
you are doing (e.g. by asking the output of "scons -h", I know what's in
your profile, but I can't tell if you messed up the SConstruct :-)).

Bruno

Revision history for this message
Feng Chen (fchen3-gmail) said :
#10

Hi, Tao:

Linking OpenFOAM libraries are not that simple, your libIcoFoam need additional libraries to operate, I will post additional information about YADE and OpenFOAM coupling shortly.

Feng

Revision history for this message
Tao (aaronztao) said :
#11

Hi Feng,
That's good to hear from you. Thanks a lot.

Cheers,
Tao

Revision history for this message
Yade Guide (yade-guide) said :
#12

Hey there! As an automated bot, I've read your question and scanned through some related threads to provide a summary for you here. Feel free to explore further by clicking on the links provided.

Title: ""Problem on a third party library using within YADE""
Burak is having issues with libgmsh when using YADE, specifically with importing mesh files. He has created a class that uses GModel to load mesh files but it doesn't work properly when used with YADE. The 'gmshModel' variable does not load the mesh file without error and Burak wonders if his code is being compiled during YADE compilation. Anton suggests setting 'checkpoints' to define where it stops and asks why an absolute path is used.
https://answers.launchpad.net/yade/+question/240117

Title: "yade from source on Ubuntu 16.04"
A user was having issues with installing Yade from source code on Ubuntu 16.04 due to 'python-scientific' package problems, despite successful compilation and creation of an executable resulting in a runtime error. The user considered switching back to 14.04 for better compatibility. After reinstalling pyqt5-dev-tools, the user successfully compiled Yade and it is now running without issues.
https://answers.launchpad.net/yade/+question/293576

Revision history for this message
Yade Guide (yade-guide) said :
#13

Hey there! As an automated bot, I've scanned through some relevant threads and condensed their content for your convenience. Feel free to explore these topics further by clicking on the links provided.

Title: "Debugging a .py script using gdb: "not in executable format""
A user faced issues with gdb on a Python script due to the non-executable format of Yade. Anton suggested compiling with -DDEBUG=1 option for more information during runtime, but the issue persisted without providing additional details. The user successfully compiled Yade in debug mode during 'cmake-command'. The user expressed gratitude towards Anton Gladky for solving their question.
https://answers.launchpad.net/yade/+question/254361

Title: "TypeError: No registered converter was able to produce a C++ rvalue of type std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > from this Python object of type str"
A user is experiencing an error while running a script on a cluster due to a TypeError related to boost. They've been able to run similar scripts on their personal computer but not on the cluster. The user suspects that the version of Boost in the cluster may be incompatible with the version of YADE currently installed (2019.01a). They have provided a script creating a simulation using spheres and walls, applying gravity of -9.8, seeking help to resolve the issue.
https://answers.launchpad.net/yade/+question/679762

Title: "I have problem with figuring out installation by source code and package. I am new to yade. can anyone tell me explictly what should i do for installation ?"
Hemanta is facing issues with Yade 0.80.1 installation, seeking advice on correct procedure for full installation and differences between installing from source and package. Anton Gladky suggests adding PPA repositories in Ubuntu. Hemanta asks if there's anything else to do after copying code from tutorials-examples/bouncing sphere.
https://answers.launchpad.net/yade/+question/225911

Revision history for this message
Yade Guide (yade-guide) said :
#14

Hey there! As an automated bot, I've gone through your question and found a few relevant threads that I've summarized for you below. Feel free to explore further by clicking on the links.

Title: "Creation of a new engine"
A user is having trouble with an engine they're trying to create, despite successful compilation. They need help identifying the specific issue. Anton asked if the engine should be added to an existing file or a new one.
https://answers.launchpad.net/yade/+question/153255

Title: "Cylindrical triaxial test using Pfacet"
Kyle is seeking help with simulating cylindrical triaxial tests in Yade, particularly for servo control and understanding 'triax.py' code. He wants a minimal working example for this simulation and desires to achieve quasi-equilibrium compression by defining a velocity value. Kyle is puzzled about the meaning of 'the triangle facets will break' when running 'triax' py without any changes, especially regarding whether it means particles do not touch each other. He has created flexible membranes using Pfacet and is unsure about how to proceed after this.
https://answers.launchpad.net/yade/+question/707148