Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: Unable to find gmp's shared libraries using g++

  1. #1
    Join Date
    Dec 2007
    Beans
    12

    Unable to find gmp's shared libraries using g++

    (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. )

    Here's what's happening:

    I am trying to compile this C++ program:
    Code:
    	#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.

  2. #2
    Join Date
    Jun 2007
    Location
    Maryland, US
    Beans
    6,240
    Distro
    Kubuntu

    Re: Unable to find gmp's shared libraries using g++

    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.

  3. #3
    Join Date
    Dec 2007
    Beans
    12

    Re: Unable to find gmp's shared libraries using g++

    Quote Originally Posted by dwhitney67 View Post
    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!

  4. #4
    Join Date
    Aug 2009
    Beans
    35

    Re: Unable to find gmp's shared libraries using g++

    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

  5. #5
    Join Date
    Jun 2007
    Location
    Maryland, US
    Beans
    6,240
    Distro
    Kubuntu

    Re: Unable to find gmp's shared libraries using g++

    Quote Originally Posted by Abhishek4563 View Post
    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".
    Code:
    gcc -print-search-dirs

  6. #6
    Join Date
    Aug 2009
    Beans
    35

    Re: Unable to find gmp's shared libraries using g++

    Code:
    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

  7. #7
    Join Date
    Apr 2006
    Location
    Atlanta, USA
    Beans
    427

    Re: Unable to find gmp's shared libraries using g++

    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:

    Code:
    vindhya@Vindhya-desktop:~/DDP$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
    
    vindhya@Vindhya-desktop:~/DDP$ ./a.out
    Here we are, trapped in the amber of the moment. There is no why.

  8. #8
    Join Date
    Aug 2009
    Beans
    35

    Re: Unable to find gmp's shared libraries using g++

    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

  9. #9
    Join Date
    Jun 2007
    Location
    Maryland, US
    Beans
    6,240
    Distro
    Kubuntu

    Re: Unable to find gmp's shared libraries using g++

    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:
    Code:
    /usr/local/lib
    After saving the file, run "ldconfig".
    Code:
    sudo ldconfig
    If all goes well, you should not need to specify the LD_LIBRARY_PATH again.

  10. #10
    Join Date
    Apr 2006
    Location
    Atlanta, USA
    Beans
    427

    Re: Unable to find gmp's shared libraries using g++

    Quote Originally Posted by Abhishek4563 View Post
    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.
    Here we are, trapped in the amber of the moment. There is no why.

Page 1 of 2 12 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •