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

Linking GSL to OpenFOAM

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 9, 2012, 18:17
Default Linking GSL to OpenFOAM
  #1
Senior Member
 
Hisham's Avatar
 
Hisham Elsafti
Join Date: Apr 2011
Location: Braunschweig, Germany
Posts: 257
Blog Entries: 10
Rep Power: 17
Hisham is on a distinguished road
Hi Foamers,

I need to use the GSL (Gnu Scientific Library) inside an OpenFOAM application to solve a system of complex linear equations. I want to use the GSL. I installed the libgsl0-dev as stated by the GSL manual. According to the manual one needs to link as:
Code:
$ gcc -L/usr/local/lib example.o -lgsl -lgslcblas -lm
So after including the needed header (a copy paste from a GSL example code from the manual), I added this to the options file:
Code:
EXE_INC = \
    -I$(LIB_SRC)/finiteVolume/lnInclude \
    -I$(LIB_SRC)/meshTools/lnInclude \
    -I/usr/local/include \
    -I/include

EXE_LIBS = -lfiniteVolume

LIB_LIBS = \
    -lOpenFOAM \
    -lmeshTools \
    -lgsl -lgslcblas -lm
I get the error:
Code:
Make/linux64GccDPOpt/seabed.o: In function `main':
seabed.C:(.text+0x14be): undefined reference to `gsl_matrix_view_array'
seabed.C:(.text+0x14d8): undefined reference to `gsl_vector_view_array'
seabed.C:(.text+0x14e2): undefined reference to `gsl_vector_alloc'
seabed.C:(.text+0x14ef): undefined reference to `gsl_permutation_alloc'
seabed.C:(.text+0x150a): undefined reference to `gsl_linalg_LU_decomp'
seabed.C:(.text+0x1525): undefined reference to `gsl_linalg_LU_solve'
seabed.C:(.text+0x1561): undefined reference to `gsl_permutation_free'
seabed.C:(.text+0x1569): undefined reference to `gsl_vector_free'
collect2: ld returned 1 exit status
make: *** [/home/hisham/OpenFOAM/hisham-2.0.1/platforms/linux64GccDPOpt/bin/seabed] Error 1
Which is according to Google most likely a linking problem.

Any ideas?

Best regards,
Hisham El Safti
Hisham is offline   Reply With Quote

Old   May 9, 2012, 19:10
Talking
  #2
New Member
 
Join Date: Apr 2010
Posts: 10
Rep Power: 16
Bandfrosch is on a distinguished road
Good evening Hisham,
my bet :
missing library search path :

Code:
..
..
..
LIB_LIBS = \
     -lOpenFOAM \
     -lmeshTools \
    -L/usr/local/lib \
    -lgsl -lgslcblas -lm
Regards,
Bandfrosch
Bandfrosch is offline   Reply With Quote

Old   May 9, 2012, 19:30
Default
  #3
Senior Member
 
Hisham's Avatar
 
Hisham Elsafti
Join Date: Apr 2011
Location: Braunschweig, Germany
Posts: 257
Blog Entries: 10
Rep Power: 17
Hisham is on a distinguished road
Hi Bandfrosch,

No .. It didn't work! I even tried different paths just to make sure! It gives the same error!
Hisham is offline   Reply With Quote

Old   May 10, 2012, 03:07
Default
  #4
Senior Member
 
Christian Lucas
Join Date: Aug 2009
Location: Braunschweig, Germany
Posts: 202
Rep Power: 18
Chris Lucas is on a distinguished road
Hi,

this worked for me without a problem.

options:

LIB_LIBS = \
-lgsl \
-lgslcblas

Did you compile gsl yourself?

Best Regards,
Christian
Chris Lucas is offline   Reply With Quote

Old   May 10, 2012, 03:22
Default
  #5
Senior Member
 
Hisham's Avatar
 
Hisham Elsafti
Join Date: Apr 2011
Location: Braunschweig, Germany
Posts: 257
Blog Entries: 10
Rep Power: 17
Hisham is on a distinguished road
Hi Christian

No I used the Ubuntu pre-installed GSL and installed only libgsl0-dev
Hisham is offline   Reply With Quote

Old   May 10, 2012, 03:38
Default
  #6
Senior Member
 
Christian Lucas
Join Date: Aug 2009
Location: Braunschweig, Germany
Posts: 202
Rep Power: 18
Chris Lucas is on a distinguished road
Hi,

I use the provided gsl library from Ubuntu as well. Works without a problem for my case.

I didn't need to define a path to the gsl library, the compiler found the it without the path.

I'm not sure if this works, but could you try the following lines in the option file:

-L/usr/local/lib -lgsl \
-L/usr/local/lib -lgslcblas \

Christian
Chris Lucas is offline   Reply With Quote

Old   May 10, 2012, 03:47
Default
  #7
Senior Member
 
Hisham's Avatar
 
Hisham Elsafti
Join Date: Apr 2011
Location: Braunschweig, Germany
Posts: 257
Blog Entries: 10
Rep Power: 17
Hisham is on a distinguished road
It did not work, the same error again. I think as you said the headers are in the default path ... I will just pack the files and post them!
Hisham is offline   Reply With Quote

Old   May 10, 2012, 03:56
Default
  #8
Senior Member
 
Hisham's Avatar
 
Hisham Elsafti
Join Date: Apr 2011
Location: Braunschweig, Germany
Posts: 257
Blog Entries: 10
Rep Power: 17
Hisham is on a distinguished road
Download the files from HERE
Hisham is offline   Reply With Quote

Old   May 10, 2012, 04:18
Default
  #9
Senior Member
 
Arne Stahlmann
Join Date: Nov 2009
Location: Hanover, Germany
Posts: 209
Rep Power: 17
Arnoldinho is on a distinguished road
Hi,

for me a simple
Quote:
EXE_INC = \
-I$(LIB_SRC)/OpenFOAM/lnInclude \

EXE_LIBS = \
-lgsl \
-lgslcblas \
in options worked without a problem. I'm using the pre-compiled Ubuntu 10.04. GSL version. But I can't remember if I had to install anything else besides libgsl0-dev.

Arne
Arnoldinho is offline   Reply With Quote

Old   May 10, 2012, 04:24
Default
  #10
Senior Member
 
Hisham's Avatar
 
Hisham Elsafti
Join Date: Apr 2011
Location: Braunschweig, Germany
Posts: 257
Blog Entries: 10
Rep Power: 17
Hisham is on a distinguished road
Hi Arne,

Thanks a lot! Your suggestion worked I didn't have to specify a path though

Thanks again to all!

Best regards,
Hisham El Safti
Hisham is offline   Reply With Quote

Old   May 10, 2012, 04:32
Default
  #11
Senior Member
 
Arne Stahlmann
Join Date: Nov 2009
Location: Hanover, Germany
Posts: 209
Rep Power: 17
Arnoldinho is on a distinguished road
You're welcome. Greetings to Braunschweig.
Arnoldinho is offline   Reply With Quote

Old   May 10, 2012, 05:39
Default
  #12
Senior Member
 
Hisham's Avatar
 
Hisham Elsafti
Join Date: Apr 2011
Location: Braunschweig, Germany
Posts: 257
Blog Entries: 10
Rep Power: 17
Hisham is on a distinguished road
Greetings to you too and to Hannover of course
Hisham is offline   Reply With Quote

Old   March 11, 2015, 08:51
Default
  #13
Member
 
Join Date: Feb 2015
Posts: 31
Rep Power: 11
Stefano Puggelli is on a distinguished road
Hi dear Foamers,
I am having a similar problem with the link between gsl and OpenFOAM. The error in my compilation is the following:
CombustionAddons/applications/generateILDM/Spline.C:70: undefined reference to `gsl_spline_free'
CombustionAddons/applications/generateILDM/Spline.C:71: undefined reference to `gsl_interp_accel_free'
on `Spline::interpolate(double)':
CombustionAddons/applications/generateILDM/Spline.C:83: undefined reference to `gsl_spline_eval'
on `Spline::create(int, std::map<double, double const*, std::less<double>, std::allocator<std:air<double const, double const*> > > const&)':
CombustionAddons/applications/generateILDM/Spline.C:51: undefined reference to `gsl_interp_accel_alloc'
CombustionAddons/applications/generateILDM/Spline.C:52: undefined reference to `gsl_interp_cspline'
CombustionAddons/applications/generateILDM/Spline.C:52: undefined reference to `gsl_spline_alloc'
CombustionAddons/applications/generateILDM/Spline.C:62: undefined reference to `gsl_spline_init'
on `Spline::secondDerivative(double)':
CombustionAddons/applications/generateILDM/Spline.C:108: undefined reference to `gsl_spline_eval_deriv2'

I have already tried to solve with the inclusion of /usr/local/lib but the error is the same... any ideas?
Stefano Puggelli is offline   Reply With Quote

Old   March 11, 2015, 09:29
Default
  #14
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,938
Rep Power: 39
alexeym has a spectacular aura aboutalexeym has a spectacular aura about
Send a message via Skype™ to alexeym
Hi,

Your error happens during compilation phase not during linking. Does your CombustionAddons/applications/generateILDM/Spline.C have the line

Code:
#include <gsl/gsl_spline.h>
?

Also maybe you should correct your options file to include -I flags pointing to include folder of GSL.
alexeym is offline   Reply With Quote

Old   March 11, 2015, 09:34
Default
  #15
Member
 
Join Date: Feb 2015
Posts: 31
Rep Power: 11
Stefano Puggelli is on a distinguished road
Hi,
in the header file that is included in Spline.C I have put the following include:
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include "gsl/gsl_math.h"
#include "gsl/gsl_errno.h"
#include "/usr/local/include/gsl/gsl_spline.h"

I think it is what you are thinking. Furthermore in the options file I have:

EXE_INC = \
..
..
-I/usr/local/include/gsl \

EXE_LIBS= \
..
..
-L/usr/local/lib
-lgsl \
-lgslcblas \
-lm \

I don't realy know which could be the problem!
Stefano Puggelli is offline   Reply With Quote

Old   March 11, 2015, 09:41
Default
  #16
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,938
Rep Power: 39
alexeym has a spectacular aura aboutalexeym has a spectacular aura about
Send a message via Skype™ to alexeym
Hi,

This

Code:
#include "gsl/gsl_math.h"
#include "gsl/gsl_errno.h"
#include "/usr/local/include/gsl/gsl_spline.h"
should be

Code:
#include "gsl/gsl_math.h"
#include "gsl/gsl_errno.h"
#include "gsl/gsl_spline.h"
and this

Code:
EXE_INC = \
..
..
-I/usr/local/include/gsl \
should be

Code:
EXE_INC = \
..
..
-I/usr/local/include \
Though in general this is redundant as gcc and clang usually look for includes in /usr/local/include.
alexeym is offline   Reply With Quote

Old   March 11, 2015, 09:43
Default
  #17
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,938
Rep Power: 39
alexeym has a spectacular aura aboutalexeym has a spectacular aura about
Send a message via Skype™ to alexeym
And post whole compilation log, maybe you are looking for the error in the wrong place.
alexeym is offline   Reply With Quote

Old   March 11, 2015, 10:14
Default
  #18
Member
 
Join Date: Feb 2015
Posts: 31
Rep Power: 11
Stefano Puggelli is on a distinguished road
Hi and thanks for your answer.
I am trying your suggestions but i am having the same problems.
As attachment you will find the resulting log file.
Attached Files
File Type: zip log.txt.zip (13.8 KB, 4 views)
Stefano Puggelli is offline   Reply With Quote

Old   March 11, 2015, 11:12
Default
  #19
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,938
Rep Power: 39
alexeym has a spectacular aura aboutalexeym has a spectacular aura about
Send a message via Skype™ to alexeym
Hi,

I guess you have got general problem with linking. GSL is just a tip of an iceberg, if you scroll log-file, you see there are errors while linking Cantera and gfortran libraries. As linking command is stuffed with this nice blob:

Code:
-L/usr/local/cantera/lib:/usr/local/lib/octave-3.2.4:/usr/local/cantera/lib:/home/user/S
oftware/sundials-2.3.0/installSundials/lib:/usr/local/cantera/lib:/home/foam/OpenFOAM-1.6-ext/OpenFO
AM/OpenFOAM-1.6-ext/ThirdParty/cantera-1.7.0/installCantera/lib:/lib:/home/foam/OpenFOAM-1.6-ext/Ope
nFOAM/OpenFOAM-1.6-ext/ThirdParty/packages/ParaView-3.12.0/platforms/linux64GccDPOpt/lib/paraview-3.
12:/home/foam/OpenFOAM-1.6-ext/OpenFOAM/OpenFOAM-1.6-ext/ThirdParty/packages/qt-everywhere-opensourc
e-src-4.7.4/platforms/linux64GccDPOpt/lib:/home/foam/OpenFOAM-1.6-ext/OpenFOAM/OpenFOAM-1.6-ext/Thir
dParty/packages/scotch-5.1.10b/platforms/linux64GccDPOpt/lib:/home/foam/OpenFOAM-1.6-ext/OpenFOAM/Op
enFOAM-1.6-ext/ThirdParty/packages/libccmio-2.6.1/platforms/linux64GccDPOpt/lib:/home/foam/OpenFOAM-
1.6-ext/OpenFOAM/OpenFOAM-1.6-ext/ThirdParty/packages/ParMGridGen-1.0/platforms/linux64GccDPOpt/lib:
/home/foam/OpenFOAM-1.6-ext/OpenFOAM/OpenFOAM-1.6-ext/ThirdParty/packages/ParMetis-3.1.1/platforms/l
inux64GccDPOpt/lib:/home/foam/OpenFOAM-1.6-ext/OpenFOAM/OpenFOAM-1.6-ext/ThirdParty/packages/metis-5
.0pre2/platforms/linux64GccDPOpt/lib:/home/foam/OpenFOAM-1.6-ext/OpenFOAM/OpenFOAM-1.6-ext/ThirdPart
y/packages/mesquite-2.1.2/platforms/linux64GccDPOpt/lib:/home/foam/OpenFOAM-1.6-ext/OpenFOAM/OpenFOA
M-1.6-ext/lib/linux64GccDPOpt/openmpi-1.4.3:/home/foam/OpenFOAM-1.6-ext/OpenFOAM/OpenFOAM-1.6-ext/Th
irdParty/packages/openmpi-1.4.3/platforms/linux64GccDPOpt/lib:/home/user/OpenFOAM/user-1.6-ext/lib/l
inux64GccDPOpt:/home/foam/OpenFOAM-1.6-ext/OpenFOAM/site/1.6-ext/lib/linux64GccDPOpt:/home/foam/Open
FOAM-1.6-ext/OpenFOAM/OpenFOAM-1.6-ext/lib/linux64GccDPOpt:/home/foam/OpenFOAM-1.6-ext/OpenFOAM/Open
FOAM-1.6-ext/lib/linux64GccDPOpt/dummy;/usr/local/lib
It is rather difficult to figure out the real problem (also are you quite sure about your installation paths? Include flags reference installation in /home/user/... linker flags point to /usr/local/lib)
alexeym is offline   Reply With Quote

Old   March 11, 2015, 11:32
Default
  #20
Member
 
Join Date: Feb 2015
Posts: 31
Rep Power: 11
Stefano Puggelli is on a distinguished road
Hi,
I perfectly agree with you. I am trying to compile the FGM code by Kroger but I am having strong problems both with cantera and gsl..
I don't know if you have any suggestions on these points!
Thank you
Stefano Puggelli is offline   Reply With Quote

Reply

Tags
complex, gnu, gsl, openfoam, scientific

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Superlinear speedup in OpenFOAM 13 msrinath80 OpenFOAM Running, Solving & CFD 18 March 3, 2015 05:36
Linking ALGLIB to OpenFOAM Phicau OpenFOAM Programming & Development 6 January 12, 2012 16:15
How to Install OpenFOAM on 64 Ubuntu 9.04 hansel OpenFOAM Installation 62 March 19, 2010 14:43
Modified OpenFOAM Forum Structure and New Mailing-List pete Site News & Announcements 0 June 29, 2009 05:56
Adventure of fisrst openfoam installation on Ubuntu 710 jussi OpenFOAM Installation 0 April 24, 2008 14:25


All times are GMT -4. The time now is 11:12.