Thread: /usr/bin/ld: cannot find -lgmp

  1. #1
    Registered User JM1082's Avatar
    Join Date
    Mar 2011
    Posts
    51

    /usr/bin/ld: cannot find -lgmp

    Hi all,

    I'm interested in using the GNU Multiple Precision library so I can work with big numbers however after a successful installation I can't run an example code.

    My code is as follows:
    Code:
    #include <stdio.h>								/* for printf */
    #include </state/partition1/home/mcdonnellj/assignmentB/gmp-5.0.5/gmp.h>
    
    int main( int argc, char *argv[] )
    {
    	mpz_t a, b;                 				/* working numbers */
    	if( argc < 3 )
    	{											/* not enough words */
    		printf( "Please supply two numbers to add.\n" );
    		return 1;
    	}
    	mpz_init_set_str( a, argv[1], 10 );			/* Assume decimal integers */
    	mpz_init_set_str( b, argv[2], 10 );			/* Assume decimal integers */
    	mpz_add( a, a, b );							/* a=a+b */
    
    	printf( "%s + %s => %s\n", argv[1], argv[2], mpz_get_str ( NULL, 10, a ) );
    }
    But when I run it using the 'gcc -o test test.c -lgmp -lm' command as specified I get the following error:
    /usr/bin/ld: cannot find -lgmp

    Does anybody know where I'm going wrong?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Given the strange path for your #include, you didn't install gmp in the usual place.

    So perhaps you need
    gcc -L/state/partition1/home/mcdonnellj/assignmentB/gmp-5.0.5/lib -o test test.c -lgmp -lm

    Well, the -L option should be the directory where libgmp.a resides.

    Likewise, you should have
    #include <gmp.h>

    And use the -I/path/to/somewhere option to tell the compiler where to find the header file.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help for find some api in C
    By desimoos in forum C Programming
    Replies: 8
    Last Post: 05-24-2012, 06:25 PM
  2. Can't find where the value changes
    By nirvana619 in forum C Programming
    Replies: 4
    Last Post: 08-10-2010, 12:22 PM
  3. std::string::find vs std::find
    By petry in forum C++ Programming
    Replies: 17
    Last Post: 07-08-2009, 05:26 PM
  4. How to find the???
    By Shidlingayya in forum C Programming
    Replies: 8
    Last Post: 12-12-2007, 11:32 AM
  5. Can you find the bug? 'Cause we can't
    By incognito in forum C++ Programming
    Replies: 5
    Last Post: 11-29-2001, 04:28 PM

Tags for this Thread