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 GSL to OpenFOAM (http://www.cfd-online.com/Forums/openfoam-programming-development/101647-linking-gsl-openfoam.html)

Hisham May 9, 2012 18:17

Linking GSL to OpenFOAM
 
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

Bandfrosch May 9, 2012 19:10

Good evening Hisham,
my bet :
missing library search path :

Code:

..
..
..
LIB_LIBS = \
    -lOpenFOAM \
    -lmeshTools \
    -L/usr/local/lib \
    -lgsl -lgslcblas -lm

Regards,
Bandfrosch

Hisham May 9, 2012 19:30

Hi Bandfrosch,

No .. It didn't work! I even tried different paths just to make sure! It gives the same error!

Chris Lucas May 10, 2012 03:07

Hi,

this worked for me without a problem.

options:

LIB_LIBS = \
-lgsl \
-lgslcblas

Did you compile gsl yourself?

Best Regards,
Christian

Hisham May 10, 2012 03:22

Hi Christian

No I used the Ubuntu pre-installed GSL and installed only libgsl0-dev

Chris Lucas May 10, 2012 03:38

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

Hisham May 10, 2012 03:47

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 May 10, 2012 03:56

Download the files from HERE

Arnoldinho May 10, 2012 04:18

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

Hisham May 10, 2012 04:24

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

Arnoldinho May 10, 2012 04:32

You're welcome. Greetings to Braunschweig.

Hisham May 10, 2012 05:39

Greetings to you too and to Hannover of course :)

Stefano Puggelli March 11, 2015 09:51

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::pair<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?

alexeym March 11, 2015 10:29

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.

Stefano Puggelli March 11, 2015 10:34

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!

alexeym March 11, 2015 10:41

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 March 11, 2015 10:43

And post whole compilation log, maybe you are looking for the error in the wrong place.

Stefano Puggelli March 11, 2015 11:14

1 Attachment(s)
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.

alexeym March 11, 2015 12:12

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)

Stefano Puggelli March 11, 2015 12:32

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


All times are GMT -4. The time now is 07:32.