autotools和cmake
Makefile
https://muicoder.github.io/linux_basic/0520source_code_and_tarball.html
errno
打印错误信息
#include <errno.h> #include <string.h> printf("[error]read error: %s", strerror(errno));
Tutorial of gcc and gdb
https://cseweb.ucsd.edu/classes/fa09/cse141/tutorial_gcc_gdb.html
常见方法
nm -D xxx.so
##查看xxx.so有哪些方法
make distclean #clean掉configure生成的文件
make clean #clean掉make生成的文件
make uninstall #clean掉install到/usr或/usr/local的文件
PKG_CONFIG_PATH
https://www.cnblogs.com/cnland/archive/2013/02/08/2909273.html
cmake
https://www.baeldung.com/linux/cmake-cmake_install_prefix
cmake -DCMAKE_INSTALL_PREFIX=/path/to/subdir
auto tools
- The Autotools are tools that will create a GNU Build System for your package. Autoconf mostly focuses on configure and Automake on Makefiles.
- Note that running
autoreconf
is only needed initially when the GNU Build System does not exist. When you later change some instructions in a Makefile.am or configure.ac, the relevant part of the build system will be regenerated automatically when you executemake
. autoreconf
is a script that callsautoconf
,automake
, and a bunch of other commands in the right order. If you are beginning with these tools, it is not important to figure out in which order all of these tools should be invoked and why. However, because Autoconf and Automake have separate manuals, the important point to understand is thatautoconf
is in charge of creating configure from configure.ac, whileautomake
is in charge of creating Makefile.ins from Makefile.ams and configure.ac. This should at least direct you to the right manual when seeking answers.
configure.ac中部分instruction解释
Linux /usr/bin与/usr/local/bin使用区别
- 首先注意usr 指 Unix System Resource,而不是User
- /usr/bin下面的都是系统预装的可执行程序,会随着系统升级而改变。
- /usr/local/bin目录是给用户放置自己的可执行程序的地方,推荐放在这里,不会被系统升级而覆盖同名文件。
GCC用法
gcc -I/usr/local/include -L/usr/local/lib -lmylib -o hello
- -I 指定include目录 (注意是i的大写)
- -L 指定lib目录
- -l 指定link库名 (L的小写)
常见问题
当编译时,出现undefined reference to timer_create的报错,可能过在configure的时个加上lrt ,比如
./configure --prefix=/usr/local --with-init-dir=/etc/init.d CFLAGS=-lrt -L/root/usr/lib64 -I/root/usr/include
或者
export CFLAGS="-L/root -L/root"
加上编译选项,让它link到对应库
其他引用
https://www.chungkwong.cc/makefile.html
https://www.cnblogs.com/ishen/p/11993957.html