信譽(yù)好的天津網(wǎng)站建設(shè)全球疫情最新消息
一、前言
文章目的:針對各種開源項(xiàng)目,由于部分項(xiàng)目文檔寫的不夠詳細(xì),(或者是我太菜了),沒有進(jìn)行詳細(xì)的介紹怎么編譯該項(xiàng)目,導(dǎo)致花費(fèi)過多時(shí)間在查找如何編譯該項(xiàng)目上。因此該篇文章針對目前遇到的編譯項(xiàng)目問題進(jìn)行匯總。
文章參考:gpt
注:目前遇到的編譯問題更多是嵌入式的交叉編譯上,如果有本文章沒提及的編譯方式,也可以發(fā)項(xiàng)目連接到評論,我會(huì)抽空補(bǔ)充。
目錄
一、前言
二、Makefile
2.1 【what】什么是Makefile
2.2 【how】包含Makefile的項(xiàng)目如何編譯
三、configure
3.1 【what】什么是configure
3.2【how】包含configure的項(xiàng)目如何編譯
3.3 configure支持的配置項(xiàng)
四、autogen.sh
4.1 什么是autogen.sh
4.2 包含autogen.sh的項(xiàng)目如何編譯
五、configure.ac、Makefile.am
5.1?什么是configure.ac、Makefile.am
5.2 包含configure.ac、Makefile.am文件的項(xiàng)目如何編譯
二、Makefile
2.1 【what】什么是Makefile
Makefile是一種文本文件,用于告訴make(一個(gè)Linux/Unix工具)如何編譯和鏈接源代碼文件以生成可執(zhí)行文件。Makefile通常包括編譯選項(xiàng)、源文件列表、目標(biāo)文件、依賴關(guān)系和生成可執(zhí)行文件的命令等信息。它是自動(dòng)化構(gòu)建和編譯程序的基礎(chǔ),并且通常是大型軟件項(xiàng)目的必備組成部分。
2.2 【how】包含Makefile的項(xiàng)目如何編譯
針對項(xiàng)目中存在Makefile文件,只需要檢查Makefile中工具鏈的配置,平臺的配置,需要鏈接庫的庫和頭文件路徑是否正確即可。
編譯指令:
make / make -jN
三、configure
3.1 【what】什么是configure
configure是一個(gè)用于自動(dòng)生成Makefile的腳本,它通常是由autoconf工具自動(dòng)生成的。當(dāng)項(xiàng)目的源代碼需要在不同的操作系統(tǒng)或不同的硬件平臺上編譯時(shí),需要根據(jù)目標(biāo)平臺的特點(diǎn)進(jìn)行適當(dāng)?shù)恼{(diào)整和優(yōu)化,因此就需要使用configure來檢測目標(biāo)平臺的環(huán)境和特性,并生成相應(yīng)的Makefile。通過執(zhí)行./configure命令,會(huì)根據(jù)系統(tǒng)環(huán)境自動(dòng)配置項(xiàng)目的編譯選項(xiàng),并生成Makefile文件,從而方便進(jìn)行項(xiàng)目的編譯和安裝。? ??
3.2【how】包含configure的項(xiàng)目如何編譯
針對項(xiàng)目中只存在configure文件的,可以通過命令行參數(shù)配置,最終生成Makefile文件
編譯指令
./configure --host=...
make
3.3 configure支持的配置項(xiàng)
不同項(xiàng)目支持的配置項(xiàng)不同可以通過下面的指令進(jìn)行查看
./configure --help
? 下面是motion項(xiàng)目,生成的configure,支持的配置項(xiàng)列表
~/git_code/motion$ ./configure --help
`configure' configures motion 4.5.1+git20230416-c28d41b to adapt to many kinds of sy stems.Usage: ./configure [OPTION]... [VAR=VALUE]...To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE. See below for descriptions of some of the useful variables.Defaults for the options are specified in brackets.Configuration:-h, --help display this help and exit--help=short display options specific to this package--help=recursive display the short help of all the included packages-V, --version display version information and exit-q, --quiet, --silent do not print `checking ...' messages--cache-file=FILE cache test results in FILE [disabled]-C, --config-cache alias for `--cache-file=config.cache'-n, --no-create do not create output files--srcdir=DIR find the sources in DIR [configure dir or `..']Installation directories:--prefix=PREFIX install architecture-independent files in PREFIX[/usr/local]--exec-prefix=EPREFIX install architecture-dependent files in EPREFIX[PREFIX]By default, `make install' will install all the files in
`/usr/local/bin', `/usr/local/lib' etc. You can specify
an installation prefix other than `/usr/local' using `--prefix',
for instance `--prefix=$HOME'.For better control, use the options below.Fine tuning of the installation directories:--bindir=DIR user executables [EPREFIX/bin]--sbindir=DIR system admin executables [EPREFIX/sbin]--libexecdir=DIR program executables [EPREFIX/libexec]--sysconfdir=DIR read-only single-machine data [PREFIX/etc]--sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]--localstatedir=DIR modifiable single-machine data [PREFIX/var]--runstatedir=DIR modifiable per-process data [LOCALSTATEDIR/run]--libdir=DIR object code libraries [EPREFIX/lib]--includedir=DIR C header files [PREFIX/include]--oldincludedir=DIR C header files for non-gcc [/usr/include]--datarootdir=DIR read-only arch.-independent data root [PREFIX/share]--datadir=DIR read-only architecture-independent data [DATAROOTDIR]--infodir=DIR info documentation [DATAROOTDIR/info]--localedir=DIR locale-dependent data [DATAROOTDIR/locale]--mandir=DIR man documentation [DATAROOTDIR/man]--docdir=DIR documentation root [DATAROOTDIR/doc/motion]--htmldir=DIR html documentation [DOCDIR]--dvidir=DIR dvi documentation [DOCDIR]--pdfdir=DIR pdf documentation [DOCDIR]--psdir=DIR ps documentation [DOCDIR]Program names:--program-prefix=PREFIX prepend PREFIX to installed program names--program-suffix=SUFFIX append SUFFIX to installed program names--program-transform-name=PROGRAM run sed PROGRAM on installed program namesSystem types:--build=BUILD configure for building on BUILD [guessed]--host=HOST cross-compile to build programs to run on HOST [BUILD]Optional Features:--disable-option-checking ignore unrecognized --enable/--with options--disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no)--enable-FEATURE[=ARG] include FEATURE [ARG=yes]--enable-silent-rules less verbose build output (undo: "make V=1")--disable-silent-rules verbose build output (undo: "make V=0")--disable-maintainer-modedisable make rules and dependencies not useful (andsometimes confusing) to the casual installer--enable-dependency-trackingdo not reject slow dependency extractors--disable-dependency-trackingspeeds up one-time build--disable-nls do not use Native Language Support--disable-rpath do not hardcode runtime library pathsOptional Packages:--with-PACKAGE[=ARG] use PACKAGE [ARG=yes]--without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no)--with-gnu-ld assume the C compiler uses GNU ld [default=no]--with-libiconv-prefix[=DIR] search for libiconv in DIR/include and DIR/lib--without-libiconv-prefix don't search for libiconv in includedir and libdir--with-libintl-prefix[=DIR] search for libintl in DIR/include and DIR/lib--without-libintl-prefix don't search for libintl in includedir and libdir--without-bktr Disable bktr devices--without-v4l2 Disable V4L2 devices--with-webp Compile with Webp image support--with-mmal=DIR Compile with RasperryPi mmal camera support--with-ffmpeg=DIR Build with FFMPEG support--with-mariadb=DIR Build with MariaDB support--with-mysql=DIR Build with MySQL support--with-pgsql=DIR Build with PostgreSQL support--without-sqlite3 Disable sqlite3 support.--without-optimizecpu Exclude autodetecting platform and cpu type. Thiswill disable the compilation of gcc optimizing codeby platform and cpu.--with-developer-flags Causes practically all of the possible gcc warningflags to be set. This may produce a large amount ofwarnings.--with-prototype-flags Causes practically all of the possible gcc warningflags to be set except missing prototypes.Some influential environment variables:CC C compiler commandCFLAGS C compiler flagsLDFLAGS linker flags, e.g. -L<lib dir> if you have libraries in anonstandard directory <lib dir>LIBS libraries to pass to the linker, e.g. -l<library>CPPFLAGS (Objective) C/C++ preprocessor flags, e.g. -I<include dir> ifyou have headers in a nonstandard directory <include dir>CXX C++ compiler commandCXXFLAGS C++ compiler flagsCPP C preprocessorKILL the 'kill' program to use to send signals to motionUse these variables to override the choices made by `configure' or to help
it to find libraries and programs with nonstandard names/locations.
四、autogen.sh
4.1 什么是autogen.sh
autogen.sh是一個(gè)腳本文件,通常用于生成configure腳本和Makefile。在許多開源項(xiàng)目中,開發(fā)者使用autogen.sh來簡化項(xiàng)目的構(gòu)建過程,特別是當(dāng)項(xiàng)目使用了autoconf、automake和libtool等自動(dòng)化工具時(shí)。
該腳本的作用是使用autoconf、automake和libtoolize等工具生成configure腳本、Makefile.in文件和其他必要的文件。autogen.sh腳本還負(fù)責(zé)檢查必要的依賴項(xiàng),例如特定版本的autoconf和automake等。
使用autogen.sh腳本的好處是可以使整個(gè)構(gòu)建過程更加自動(dòng)化和簡單,開發(fā)人員只需運(yùn)行一個(gè)腳本即可生成必要的構(gòu)建文件。
4.2 包含autogen.sh的項(xiàng)目如何編譯
針對項(xiàng)目中只存在autogen.sh腳本文件的,該腳本會(huì)自動(dòng)檢查系統(tǒng)環(huán)境和依賴庫是否滿足項(xiàng)目要求,并生成 configue 文件.
編譯指令:
./autogen.sh
./configure --host=.... #指定
make
五、configure.ac、Makefile.am
5.1?什么是configure.ac、Makefile.am
configure.ac和Makefile.am是Autoconf和Automake工具的輸入文件。它們通常與configure和Makefile.in文件一起使用,這些文件是Autoconf和Automake工具生成的。在GNU構(gòu)建系統(tǒng)中,這些工具可以自動(dòng)化地生成與目標(biāo)平臺和操作系統(tǒng)兼容的Makefile文件和可執(zhí)行文件。
configure.ac文件是Autoconf的輸入文件,其中包含檢查系統(tǒng)的程序。
Makefile.am文件是Automake的輸入文件,其中包含Makefile的規(guī)則。它使用AUTOMAKE_OPTIONS、AM_INIT_AUTOMAKE等宏來定義Makefile的規(guī)則。此文件通常包含文件的列表、目標(biāo)和依賴項(xiàng)以及要執(zhí)行的命令。
configure和Makefile.in文件由Autoconf和Automake工具生成,并根據(jù)目標(biāo)平臺和操作系統(tǒng)生成符合標(biāo)準(zhǔn)的Makefile文件和可執(zhí)行文件。configure文件通常包含源代碼的配置選項(xiàng),而Makefile.in文件包含Makefile的規(guī)則。configure和Makefile.in文件的生成過程是通過運(yùn)行./configure腳本完成的,該腳本將根據(jù)系統(tǒng)環(huán)境和用戶定義的選項(xiàng)生成符合目標(biāo)平臺和操作系統(tǒng)的Makefile文件和可執(zhí)行文件。
5.2 包含configure.ac、Makefile.am文件的項(xiàng)目如何編譯
針對項(xiàng)目中只存在configure.ac、Makefile.am文件,可以根據(jù)下面的指令一步步生成對應(yīng)的Makefile
編譯指令:
autoreconf -i
./configure
make