Compiling Library Errors

I compiled my program successfully but when I try to run the executable I get a library error similar to: a.out: fatal: open failed: No such file or directory.

GCC no longer specifies a runpath so that the dynamic linker can find dynamic libraries at runtime. Please see the GCC FAQ for more information about this. You will need to do one of the following. Please note, these examples refer to the case where your program needs a library found in /usr/local/lib, if the library is in some other location you must adjust accordingly.

  1. Set your LD_LIBRARY_PATH environment variable either at the command line or permanently in your .cshrc with the following (for csh users): setenv LD_LIBRARY_PATH /usr/local/lib
  2. Write a small wrapper script that first sets the LD_LIBRARY_PATH environment variable then executes the program. This is especially useful if you need to set other environment variables too.
  3. Read the "Linker Options" section of the gcc man page along with the ld man page for information on adding a directory to the runtine library search path with something like "-Wl,-R /usr/local/lib".