Search Order
When environment variables and command-line options are used together the compiler searches the directories in the following order:
- Command-line options '-I' and '-L',from left to right.
- Directories specified by environment variables,such as C_INCLUDE_PATH and LIBRARY_PATH.
- Default system directories.
Note:In day-to-day usage,directories are usually added to the search paths with the options '-I' and '-L'.
Creating a Library with ar
The GNU archiver ar combines a collection of objects files into a single archive file,also know as a library.An archive file is simply a convenient way of distributing a large number of related object files together.
- You can use the following command to create a static library:
$ ar cr libNAME.a file1.o file2.o ... filen.o
- The archiver ar also provides a "table of contents" option 't' to list the object files in an existing library.
$ ar t libNAME.a
EX:
使用
gcc -Wall * -c
生成目標文件使用
ar cr
創(chuàng)建一個自己的庫文件:第三種方法较店,使用默認庫:
使用庫文件編譯程序,生成可執(zhí)行文件:
注意文件的編譯順序:
第一種方法:
第二種方法(通過環(huán)境變量):
注:添加:$LIBRARY_PATH是防止變量原有的的內容被沖掉,表示最佳環(huán)境變量
2020.11.18