LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 01-20-2012, 05:43 PM   #1
quadpixels
LQ Newbie
 
Registered: Dec 2011
Posts: 3

Rep: Reputation: Disabled
Compilation error - GSL library + MPI Benchmark Library = undefined reference


Hi,

I'm compiling a program (MPI Benchmark Library 1.20) that depends on libGSL (GNU Scientific Library).
The libGSL contains two static library archive files: libgsl and libgslcblas.

Upon typing these commands:
$ ./configure
$ ./make
The system complains an error saying that
libtool: link: mpic++ -g -O2 -o .libs/collective_test collective_test.o mpib_test.o ../collectives/.libs/libmpib_coll.so ../benchmarks/libmpib.a ../p2p/libmpib_p2p.a -lboost_graph -lgsl -lgslcblas -ldl -lm -pthread
/usr/local/lib/libgsl.so: undefined reference to `cblas_ctrmv'
/usr/local/lib/libgsl.so: undefined reference to `cblas_zswap'
/usr/local/lib/libgsl.so: undefined reference to `cblas_zsymm'
......

It's obvious that all functions named "cblas_****" is located in "-lgslcblas". And it can be proved by compiling a much simpler test case:
$ gcc test.c -I /home/nitroglycerine/Downloads/gsl-1.14/ -lgsl -lgslcblas -o test_gsl
In this case, the program will compile without a hitch.

So...
If there is no answer to this specific question, is there a post/document/article to start with to find where I am in the universe of compilation and linking,
thanks
 
Old 01-20-2012, 11:58 PM   #2
John VV
Guru
 
Registered: Aug 2005
Posts: 13,051

Rep: Reputation: 1741Reputation: 1741Reputation: 1741Reputation: 1741Reputation: 1741Reputation: 1741Reputation: 1741Reputation: 1741Reputation: 1741Reputation: 1741Reputation: 1741
what version of gcc are you using ?
4.6 is stricter than 4.5
4.5 was stricter than 4.4
and so on

the gcc group is forcing devs to build secure software

so software built for the older versions of gcc might not build on the current
i have 3.4 ,4.3 and 4.5 installed this solves most issues ( except the needed *.h includes from gcc 4.1 )

this is Ubuntu ? right
so you installed gsl from the repo ? right ?
"apt-get gsl "

or did you install it manually
if manually did you build it from source and install from the source
or
copy/paste the two files to /usr/local/lib
if so IS /usr/local/lib in the system file path
is it in
Code:
 echo $PATH
and did you ALSO put the header files in
/usr/local/include/GSL

Last edited by John VV; 01-21-2012 at 12:10 AM.
 
Old 01-21-2012, 10:09 PM   #3
quadpixels
LQ Newbie
 
Registered: Dec 2011
Posts: 3

Original Poster
Rep: Reputation: Disabled
Post

I am using GCC 4.6.1 which comes from Xubuntu 11.10
I could check with command "nm -D /usr/local/lib/libgsl.so" and see that "libgsl.so" has many cblas_***** functions marked as "U" (meaning undefined symbol, reference here)
Finally I had to add "-static" compiler flag into the makefile, so that when these programs are linked, the linker does not have to search libgsl.so; instead it can find the desired functions in the intermediate output files.

Not a perfect solution though but it made the compilation errors disappear (:

Whether installing libgsl using apt or compiling it from source code does not affect the error; the error persists if I don't add "-static" flag;
Whether or not libgsl is located in /usr/local/bin or in some custom folders specified by --prefix=XXXXXXX does not affect the erorr; the error persists if I don't add "-static" flag.

Quote:
Originally Posted by John VV View Post
what version of gcc are you using ?
4.6 is stricter than 4.5
4.5 was stricter than 4.4
and so on

the gcc group is forcing devs to build secure software

so software built for the older versions of gcc might not build on the current
i have 3.4 ,4.3 and 4.5 installed this solves most issues ( except the needed *.h includes from gcc 4.1 )

this is Ubuntu ? right
so you installed gsl from the repo ? right ?
"apt-get gsl "

or did you install it manually
if manually did you build it from source and install from the source
or
copy/paste the two files to /usr/local/lib
if so IS /usr/local/lib in the system file path
is it in
Code:
 echo $PATH
and did you ALSO put the header files in
/usr/local/include/GSL
 
1 members found this post helpful.
Old 07-04-2012, 09:08 AM   #4
c2happle
LQ Newbie
 
Registered: Jul 2012
Posts: 3

Rep: Reputation: Disabled
Question GSL:undefined reference

Hello,I am a new one here.I Have similar problems.
When I'm compiling a program that uses libGSL (GNU Scientific Library),the error occurs as follows:

-lvx_cal \
-lvx_log \
-lm -lnetcdf_c++ -lnetcdf -lgsl \
/usr/local/lib/libgsl.so: undefined reference to `cblas_ctrmv'
/usr/local/lib/libgsl.so: undefined reference to `cblas_zswap'
/usr/local/lib/libgsl.so: undefined reference to `cblas_zsymm'
/usr/local/lib/libgsl.so: undefined reference to `cblas_cgeru'
/usr/local/lib/libgsl.so: undefined reference to `cblas_sgemm'
/usr/local/lib/libgsl.so: undefined reference to `cblas_daxpy'
/usr/local/lib/libgsl.so: undefined reference to `cblas_csyrk'
collect2: ld returned 1 exit status
make[4]: *** [gen_poly_mask] Error 1
make[3]: *** [all] Error 2
make[2]: *** [all] Error 2
make[1]: *** [all] Error 2
make: *** [all] Error 2

quadpixels said that 'I had to add "-static" compiler flag into the makefile'.
So here what does 'makefile' means? for GSL or my program?
and where should I add "-static"?
Thank you a lot.






Quote:
Originally Posted by quadpixels View Post
I am using GCC 4.6.1 which comes from Xubuntu 11.10
I could check with command "nm -D /usr/local/lib/libgsl.so" and see that "libgsl.so" has many cblas_***** functions marked as "U" (meaning undefined symbol, reference here)
Finally I had to add "-static" compiler flag into the makefile, so that when these programs are linked, the linker does not have to search libgsl.so; instead it can find the desired functions in the intermediate output files.

Not a perfect solution though but it made the compilation errors disappear (:

Whether installing libgsl using apt or compiling it from source code does not affect the error; the error persists if I don't add "-static" flag;
Whether or not libgsl is located in /usr/local/bin or in some custom folders specified by --prefix=XXXXXXX does not affect the erorr; the error persists if I don't add "-static" flag.
 
Old 07-04-2012, 10:14 AM   #5
quadpixels
LQ Newbie
 
Registered: Dec 2011
Posts: 3

Original Poster
Rep: Reputation: Disabled
Hello c2happle,

In your command line you are linking library "gsl" but not "gslcblas" (-lgsl means link a library and its name is "gsl", hence "-l gsl", it doesnt matter whether or not you insert a space between "l" and "gsl")
You would wish to append "-lgslcblas" after "-lgsl", that is

Code:
        -lvx_cal \
        -lvx_log \
        -lm -lnetcdf_c++ -lnetcdf -lgsl -lgslcblas \
For static compiling I vaguely remembered it could be appended anywhere in the linker flags (in between any of the -l flags), or you could add libgsl.a to the source files (that is equivalent to static linking for you could see those symbols being inserted into the final object file).

Hope this helps (:

Quote:
Originally Posted by c2happle View Post
Hello,I am a new one here.I Have similar problems.
When I'm compiling a program that uses libGSL (GNU Scientific Library),the error occurs as follows:

-lvx_cal \
-lvx_log \
-lm -lnetcdf_c++ -lnetcdf -lgsl \
/usr/local/lib/libgsl.so: undefined reference to `cblas_ctrmv'
/usr/local/lib/libgsl.so: undefined reference to `cblas_zswap'
/usr/local/lib/libgsl.so: undefined reference to `cblas_zsymm'
/usr/local/lib/libgsl.so: undefined reference to `cblas_cgeru'
/usr/local/lib/libgsl.so: undefined reference to `cblas_sgemm'
/usr/local/lib/libgsl.so: undefined reference to `cblas_daxpy'
/usr/local/lib/libgsl.so: undefined reference to `cblas_csyrk'
collect2: ld returned 1 exit status
make[4]: *** [gen_poly_mask] Error 1
make[3]: *** [all] Error 2
make[2]: *** [all] Error 2
make[1]: *** [all] Error 2
make: *** [all] Error 2

quadpixels said that 'I had to add "-static" compiler flag into the makefile'.
So here what does 'makefile' means? for GSL or my program?
and where should I add "-static"?
Thank you a lot.
 
Old 07-08-2012, 03:33 AM   #6
c2happle
LQ Newbie
 
Registered: Jul 2012
Posts: 3

Rep: Reputation: Disabled
Question gsl lib problems

Hello,quadpixels,
Thanks for your kind suggestion. But it seems more complex. When I run a software called'MET' using gsl, it should creat some useful tools. The log file is as follow:

-lvx_cal \
-lvx_util \
-lvx_math \
-lvx_color \
-lvx_log \
-lm -lnetcdf_c++ -lnetcdf -lgsl -lgslcblas \

cp ensemble_stat /home/WRF/MET/METv4.0/bin

*** Finished Making the ensemble_stat Tool ***

-lvx_grid \
-lvx_config \
-lvx_util \
-lvx_math \
-lvx_cal \
-lvx_log \
-lm -lnetcdf_c++ -lnetcdf -lgsl \

/home/WRF/MET/gsl/lib/libgsl.so: undefined reference to `cblas_ctrmv'
/home/WRF/MET/gsl/lib/libgsl.so: undefined reference to `cblas_zswap'

collect2: ld returned 1 exit status
make[4]: *** [gen_poly_mask] Error 1


As above,when it creates ensemble_stat Tool,it seems to have -lgslcblas,but when for gen_poly_mask, it breaks down.

Then I found something seems wrong with my compile.log for gsl,as follows:
/usr/bin/arch -k = unknown
/usr/convex/getsysinfo = unknown

configure:10417: checking ieeefp.h usability
configure:10434: gcc -c -g -O2 conftest.c >&5
conftest.c:56:20: error: ieeefp.h: No such file or directory
configure:10440: $? = 1
configure: failed program was:

configure:10707: gcc -o conftest -g -O2 conftest.c >&5
/tmp/cc6SkJDu.o: In function `main':
/home/chencuihong/WRF/MET/gsl110/gsl-1.10/conftest.c:58: undefined reference to `_doprnt'
collect2: ld returned 1 exit status
configure:10713: $? = 1

conftest.c: In function 'main':
conftest.c:39: error: 'fesettrapenable' undeclared (first use in this function)
conftest.c:39: error: (Each undeclared identifier is reported only once
conftest.c:39: error: for each function it appears in.)
configure:11073: $? = 1
configure: failed program was:

ac_cv_host=x86_64-unknown-linux-gnu


So,I don't know exactly whether it is the problem of compile process or -lgslcblas,as something works while others doesnot work.

For what you said about libgsl.a, I have this file in my gsl/lib.

I am very confused with this. Look forward to your reply. Thanks very much.





Quote:
Originally Posted by quadpixels View Post
Hello c2happle,

In your command line you are linking library "gsl" but not "gslcblas" (-lgsl means link a library and its name is "gsl", hence "-l gsl", it doesnt matter whether or not you insert a space between "l" and "gsl")
You would wish to append "-lgslcblas" after "-lgsl", that is

Code:
        -lvx_cal \
        -lvx_log \
        -lm -lnetcdf_c++ -lnetcdf -lgsl -lgslcblas \
For static compiling I vaguely remembered it could be appended anywhere in the linker flags (in between any of the -l flags), or you could add libgsl.a to the source files (that is equivalent to static linking for you could see those symbols being inserted into the final object file).

Hope this helps (:
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How to debug undefined reference to library function (yad 0.5.1)? catkin Linux - Software 3 10-17-2010 07:08 AM
error: GSL CBLAS library not found tony_lincon Linux - Newbie 5 06-18-2010 02:14 PM
Shared Library error : undefined reference xs2harpreet Programming 6 03-11-2009 05:55 PM
Linking own library: undefined reference to otosigo Programming 1 12-02-2004 08:05 AM
undefined reference to a function included in a library i made!!! keos Programming 5 02-21-2004 04:02 PM


All times are GMT -5. The time now is 10:54 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration