g++の環境変数を介したパスの指定

g++について, ライブラリやイクルードパスの指定を環境変数を介して行いたい. インクルードパスであれば, CPLUS_INCLUDE_PATHに指定するとできる.

さて, ライブラリパスではLIBRARY_PATHとLD_LIBRARY_PATHがあっていまいち違いを理解していなかったので調べてみた.

LIBRARY_PATH is used by gcc before compilation to search for directories containing libraries that need to be linked to your program.

LD_LIBRARY_PATH is used by your program to search for directories containing the libraries after it has been successfully compiled and linked.

EDIT: As pointed below, your libraries can be static or shared. If it is static then the code is copied over into your program and you don't need to search for the library after your program is compiled and linked. If your library is shared then it needs to be dynamically linked to your program and that's when LD_LIBRARY_PATH comes into play.

http://stackoverflow.com/questions/4250624/ld-library-path-vs-library-path

ようするに, LIBRARY_PATHはプログラムのコンパイル時にリンクする必要のあるライブラリを探索するパスであり, LD_LIBRARY_PATHはそのプログラム実行時に必要となる動的なライブラリの位置を指定するものみたいです.

従って, プログラムのビルドだけであればLIBRARY_PATHだけで良さそうだが, テストまで同時にしているとLD_LIBRARY_PATHも指定しないと怒られる, のかな?