PDA

View Full Version : Unable to find gmp's shared libraries using g++



JamesBowen
March 2nd, 2009, 11:08 PM
(note beforehand that if you know an easy-to-use bigint type library that you can give me step by step instruction on how to set up, you have done far more for me than solving this problem would. That'd be great. :D)

Here's what's happening:

I am trying to compile this C++ program:


#include <iostream>
#include <gmpxx.h>

int Ackermann(int m, int n);

using namespace std;

int main(void)
{
mpz_class a;
a = 1;
a = a*a; a = a*a;
cout<< a;
/*
int m = 4, n = 4;
cout <<"\n\nAckermann's function for (" << m << "," << n << ") is " << Ackermann(m,n);
return 0;*/
}

int Ackermann(int m, int n)
{
if (m == 0)
{
return (n+1);
}
else if (n == 0)
{
return (Ackermann(m-1,1));
}
else
{
return (Ackermann(m-1,Ackermann(m,n-1)));
}
}


However, when I compile it like this:


g++ ackermann.cpp -o ackermann -lgmpxx -lgmp

And then run it, I get this error:

./ackermann: error while loading shared libraries: libgmpxx.so.4: cannot open shared object file: No such file or directory

Now, it is fairly obvious that it can't find the shared libraries. I figured I'd see what I could do to fix it, and came across this rather interesting file: /home/james/gmp-4.2.4/libgmpxx.la

Here are the contents:


# libgmpxx.la - a libtool library file
# Generated by ltmain.sh - GNU libtool 1.5.24 (1.1220.2.455 2007/06/24 02:13:29)
#
# Please DO NOT delete this file!
# It is necessary for linking the library.

# The name that we can dlopen(3).
dlname='libgmpxx.so.4'

# Names of this library.
library_names='libgmpxx.so.4.0.4 libgmpxx.so.4 libgmpxx.so'

# The name of the static archive.
old_library='libgmpxx.a'

# Libraries that this one depends upon.
dependency_libs=' /home/james/gmp-4.2.4/libgmp.la'

# Version information for libgmpxx.
current=4
age=0
revision=4

# Is this an already installed library?
installed=no

# Should we warn about portability when linking against -modules?
shouldnotlink=no

# Files to dlopen/dlpreopen
dlopen=''
dlpreopen=''

# Directory that this library needs to be installed in:
libdir='/usr/local/lib'
relink_command="(cd /home/james/gmp-4.2.4; /bin/bash ./libtool --mode=relink g++ -m32 -O2 -fomit-frame-pointer -mtune=core2 -march=core2 -o libgmpxx.la -rpath /usr/local/lib -version-info 4:4:0 dummy.lo cxx/isfuns.lo cxx/ismpf.lo cxx/ismpq.lo cxx/ismpz.lo cxx/ismpznw.lo cxx/osdoprnti.lo cxx/osfuns.lo cxx/osmpf.lo cxx/osmpq.lo cxx/osmpz.lo libgmp.la @inst_prefix_dir@) "


It looks to me like if g++ could make use of the information in this file, it might be happy. I'm not entirely sure, however.

Now, I've done a fair bit of Linux and command-line related work, as well as C++ programming, but I haven't done much of the two together. Maybe it's as simple as setting an environment variable. Any help would be much appreciate, however, and I would think of you when I finish this assignment.

dwhitney67
March 2nd, 2009, 11:19 PM
The gmpxx header file is located in /usr/include. The libraries are in /usr/lib.

If you do not have these on your system, then perhaps you need to install the appropriate development package for these. If I knew the name of the package I would cheerfully provide it here, but unfortunately I do not know it.

JamesBowen
March 2nd, 2009, 11:24 PM
The gmpxx header file is located in /usr/include. The libraries are in /usr/lib.

If you do not have these on your system, then perhaps you need to install the appropriate development package for these. If I knew the name of the package I would cheerfully provide it here, but unfortunately I do not know it.

Wow, yeah, that actually fairly obvious reading the last 1/3 of the file or so. I can't believe I missed that.

UPDATE:
Yeah, that did the trick. Huge thanks, man!

Abhishek4563
September 2nd, 2009, 04:14 PM
I am having the same problem ... cannot really understand how did you fix it .. I checked my usr/lib and it is present there .. do i need to set PATH or LD_LIBRARY_PATH .. and if yes then how to ??

Thx

dwhitney67
September 2nd, 2009, 04:59 PM
I am having the same problem ... cannot really understand how did you fix it .. I checked my usr/lib and it is present there .. do i need to set PATH or LD_LIBRARY_PATH .. and if yes then how to ??

Thx

Could you please be more specific, wrt which library is in /usr/lib, and also please provide the gcc/g++ command that you are using to link your application?

Typically GCC is able to locate libraries in /usr/lib. You can verify this by running the following command and examining the output for the "libraries".


gcc -print-search-dirs

Abhishek4563
September 2nd, 2009, 05:12 PM
vindhya@Vindhya-desktop:~/DDP$ g++ trymain_p1.C -lgmpxx -lgmp
vindhya@Vindhya-desktop:~/DDP$ ./a.out
./a.out: error while loading shared libraries: libgmpxx.so.4: cannot open shared object file: No such file or directory
vindhya@Vindhya-desktop:~/DDP$ ls /usr/local/lib
libgmp.a libgmp.so.3 libgmpxx.la libgmpxx.so.4.1.0
libgmp.la libgmp.so.3.5.0 libgmpxx.so python2.6
libgmp.so libgmpxx.a libgmpxx.so.4
vindhya@Vindhya-desktop:~/DDP$ ls /usr/local/include
gmp.h gmpxx.h
vindhya@Vindhya-desktop:~/DDP$ g++ -print-search-dirs
install: /usr/lib/gcc/x86_64-linux-gnu/4.3.3/
programs: =/usr/lib/gcc/x86_64-linux-gnu/4.3.3/:/usr/lib/gcc/x86_64-linux-gnu/4.3.3/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.3.3/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/libexec/gcc/x86_64-linux-gnu/4.3.3/:/usr/libexec/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.3.3/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.3.3/../../../../x86_64-linux-gnu/bin/x86_64-linux-gnu/4.3.3/:/usr/lib/gcc/x86_64-linux-gnu/4.3.3/../../../../x86_64-linux-gnu/bin/
libraries: =/usr/lib/gcc/x86_64-linux-gnu/4.3.3/:/usr/lib/gcc/x86_64-linux-gnu/4.3.3/:/usr/lib/gcc/x86_64-linux-gnu/4.3.3/../../../../x86_64-linux-gnu/lib/x86_64-linux-gnu/4.3.3/:/usr/lib/gcc/x86_64-linux-gnu/4.3.3/../../../../x86_64-linux-gnu/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/4.3.3/../../../x86_64-linux-gnu/4.3.3/:/usr/lib/gcc/x86_64-linux-gnu/4.3.3/../../../../lib/:/lib/x86_64-linux-gnu/4.3.3/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/4.3.3/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/4.3.3/../../../../x86_64-linux-gnu/lib/:/usr/lib/gcc/x86_64-linux-gnu/4.3.3/../../../:/lib/:/usr/lib/

in the above I 1. compiled the program.. no prob 2. Ran it ...prob 3. contents of usr/local/lib and usr/local/include 4. output of the command you asked

Thanx

johnl
September 2nd, 2009, 05:24 PM
Hi,

My suspicion is that you need to tell the runtime linker where it can find libgmpxx.so.4.

I would give this a shot:



vindhya@Vindhya-desktop:~/DDP$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib

vindhya@Vindhya-desktop:~/DDP$ ./a.out

Abhishek4563
September 2nd, 2009, 05:29 PM
I think it worked ..not really sure though ..I am getting floating point exception ..may be something in the code is doing it.. by the way is the LD_LIbrary_pah permanently changed or I will have to change it every time i start the computer?
Thanx a lot

dwhitney67
September 2nd, 2009, 05:34 PM
The suggestion provided by johnl should work.

An alternative is to augment your ldconfig search paths by inserting a new file in /etc/ld.so.conf.d (or something similar).

Create a file (you must have root privileges) within this directory, and within it place the following statement:


/usr/local/lib

After saving the file, run "ldconfig".


sudo ldconfig

If all goes well, you should not need to specify the LD_LIBRARY_PATH again.

johnl
September 2nd, 2009, 05:38 PM
I think it worked ..not really sure though ..I am getting floating point exception ..may be something in the code is doing it.. by the way is the LD_LIbrary_pah permanently changed or I will have to change it every time i start the computer?
Thanx a lot

Sounds to me like it worked. I would debug your code to find where the FPE is coming from :)

Follow dwhitney67's post to make the LD_LIBRARY_PATH change permanent.

Abhishek4563
September 2nd, 2009, 06:36 PM
The suggestion provided by johnl should work.


Create a file (you must have root privileges) within this directory, and within it place the following statement:

.
Pardon my ignorance dude .. but I assume I have to create a file foo.conf in /etc/ld.so.conf.d and write /usr/local/lib in it ?? or did you mean something else

BTW
temporarily changing LD_path worked!!!
Thanx a LOTTTT!!! you people are great

dwhitney67
September 2nd, 2009, 07:09 PM
Pardon my ignorance dude .. but I assume I have to create a file foo.conf in /etc/ld.so.conf.d and write /usr/local/lib in it ?? or did you mean something else
...

Yep, that's all there is to it. You can name the file whatever you please; on my system I have a "libc.conf". But "foo.conf" is just as good of a name.

Todamont
April 12th, 2013, 09:53 AM
Yep, that's all there is to it. You can name the file whatever you please; on my system I have a "libc.conf". But "foo.conf" is just as good of a name.

Hey, guys, please. I don't have libgmxx in my /usr/lib or /usr/local/lib folders and I don't have the header in my /usr/includes folder. Where is the package / repo for this library? Where is the source, please?

r-senior
April 12th, 2013, 10:12 AM
Development libraries have package names like libxxx-dev, so you can generally find them using the regex search of apt-cache as follows:


apt-cache search "libgmp.*-dev" --names-only

To confirm the contents of the packages that it suggests:


apt-file list libgmp-dev

Try "man apt-cache" and "man apt-file" for more information. If you want sources, you'll need source repositories enabled in your software sources list.

If you have other questions, you should start a new thread. Things may have changed since 2009.

Todamont
April 12th, 2013, 10:49 AM
Yep, that's all there is to it. You can name the file whatever you please; on my system I have a "libc.conf". But "foo.conf" is just as good of a name.

I don't have a libgmpxx in my /usr/local/lib or /usr/lib folders, and I don't have the header in my /usr/include. Can anyone link to the source / repos for this package, please?

ah nevermind, found them with the above 'apt-cache search "libgmp.*-dev" --names-only' command. Thanks R-Senior~