LD_LIBRARY_PATH 와 LIBRARY_PATH
외부 C 라이브러리를 사용하는 Python 패키지를 빌드 하는데 참조하는 라이브러리가 표준 라이브러리 디렉터리에 있지 않아 검색할 라이브러리의 위치를 LD_LIBRARY_PATH 환경변수를 이용하여 지정하였으나 빌드가 계속 실패 한다.
/usr/bin/ld: cannot find -ltest
빌드 할대 -L 옵션을 사용하면 라이브러리를 검색할 디렉터리를 지정하고 -l 옵션으로는 특정 라이브러리 피일을 지정할 수 있다.
gcc -o test.o -L/path/to/custom/lib -ltest
Makefile 같은 빌드 설정파일을 변경하면 되지만 직접 관리하는 소스가 아닌경우 소스코드가 업데이트 되어 적용 할때 마다 매번 같은 작업을 해주어야 하기 때문에 불편하다.
환경 변수로 검색 라이브러리 경로를 설정 하는 방법이 있으면 좋을 것 같다.
메뉴얼을 읽어 보자
GCC manual 페이지를 읽어 보면 컴파일 타임에 라이브러리(링커 파일)검색 할 때는 LIBRARY_PATH 변수를 설정해 주면 된다.
-L옵션에서 지정한 디렉터리가 우선순위를 갖는다.
LD_LIBRARY_PATH
LD_LIBRARY_PATH는 프로그램 실행 타임에 동적 링커가 라이브러리를 조회 할때 사용된다.
A list of directories in which to search for ELF libraries at execution time. The items in the list are separated by either colons or semicolons, and there is no support for escaping either separator. A zero-length directory name indicates the current working directory.
LIBRARY_PATH
컴파일 타임에서 라이브러리(링커 파일) 검색 하기 위해 사용된다.
The value of LIBRARY_PATH is a colon-separated list of directories, much like PATH . When configured as a native compiler, GCC tries the directories thus specified when searching for special linker files, if it can't find them using GCC_EXEC_PREFIX . Linking using GCC also uses these directories when searching for ordinary libraries for the -l option (but directories specified with -L come first).