## 2011-04-26

### 路径环境变量中的陷阱 | Traps in path related environment variables

CFLAGS="-I#/include"
LDFLAGS="-L#/lib"
PATH="#/bin"
LD_LIBRARY_PATH="#/lib"
LIBRARY_PATH="#/lib"
MANPATH="#/man"
C_INCLUDE_PATH="#/include"
CPLUS_INCLUDE_PATH="#/include"
PKG_CONFIG_PATH="#/lib/pkgconfig"

It was all because of C_INCLUDE_PATH, usually it is empty, so if I prepend something in the way mentioned above, it'll become "#/include:". The trailing ':' will actually be interpreted as a 'current directory' in the end, that is '.'. And it also happen for a staring ':' and a '::' in the middle.

On the other hand, for programs utilizing automake, we often see a parameter '-I.', which is often appears in the beginning in order to make '.' the first searched directory for header files. However if '.' appears in C_INCLUDE_PATH, gcc will then consider it a 'system standard path', and therefore ignore the parameter '-I.'. In this way the order of searching directories is changed, then issues may appear.
I found this when I was compiling binutils, where the file 'config.h' appears in many directories, such that the order of searching directories is quite important.

To resolve it, simple but trouble, just to check whether the original variable is empty before prepend anything, in order to avoid a trouble-making ':'.