Runtime error

Marc Glisse marc.glisse at inria.fr
Tue Jun 29 17:09:40 CEST 2010


On Tue, 29 Jun 2010, Federico Stra wrote:

> I compile it with the following command:
>   gcc main.c -o main -lgmp
>
> On execution, the program exits with the following error:
>   federico at federico-laptop:~$ ./main
>   ./main: error while loading shared libraries: libgmp.so.10: cannot open shared object file: No such file or directory
>
> That seems to me a bit strange...
> Anyway, if I compile the program with
>    gcc main.c -o main -lgmp -static
> instead, then it runs properly, because it doesn't need to link them upon runtime.
> Is there any reason for this behavior? Shall I try to copy the libraries to /usr/lib, maybe?

This is a general programming question, nothing specific to GMP, you want 
to read on RPATH.

In practice, you are missing:
-I/usr/local/include (where can gcc/cpp find gmp.h)
-L/usr/local/lib (where can gcc/ld find libgmp.so/.a)
-Wl,-R/usr/local/lib (where can the system find libgmp.so.10 when the 
program is executed)

Some of those are implicit on some systems.

-- 
Marc Glisse


More information about the gmp-discuss mailing list