details link: https://zhuanlan.zhihu.com/p/77813702
Most frequently used to compile and install cpp program commands are as follows:
cd /path/to/source
./configure
make
make install
./configure
: make sure c compiler and dependent packages(dpkgs) needed have been installed in system. And generate Makefile from Makefile.in(Makefile Template) for compiling.
make
: compile the source code according to Makefile. Pls read make && Makefile Tutorial below for futher information.
make install
: install the program to system, by copying:
- the executable file usually to /usr/local/bin
- shared object files(.so) usually to /usr/local/lib
- header file usually to /usr/local/include
- static library(.a) usually to /usr/local/lib.
btw: Files configure and Makefile.in are generated by autotools
most often.
details links: https://www.baeldung.com/linux/library_path-vs-ld_library_path; https://man7.org/linux/man-pages/man1/ld.1.html; https://www.man7.org/linux/man-pages/man8/ld.so.8.html
System will search for all shared object files at runtime. However, in linux, compiler only searches /usr/local/lib, /usr/lib(sometimes /usr/local/lib is not included) and env variable:$LD_LIBRARY_PATH
by default.
Hence, export $LD_LIBRARY_PATH=/path/to/lib:$LD_LIBRARY_PATH
is recommended.
btw:
defines:
ld
: GNU linker;id.so
: GNU dynamic linker
$LIBRARY_PATH
: In addition to the standard default directories like /usr/lib or /usr/local/lib,ld
, also uses the directories in LIBRARY_PATH while searching for libraries in the linking phase.$LD_LIBRARY_PATH
: Same as$LIBARAY_PATH
, but it's used at runtime.- "LD" in
$$LD_LIBRARY_PATH
shorts for "Load". $PATH
is the env variable that tells system where to find executable files.