Linux のほとんどすべてのオープンソース c++ プロジェクトには、ソース コードをビルドする前に Makefile を生成するための「configure」ファイルがあります。
プロジェクトをゼロから作成していますが、この「構成」ファイルのテンプレートはありますか?
ほとんどの場合、構成ファイルは手動で作成されるのではなく、autoconfなどのツールによって生成されます。ただし、より最新の代替手段があり、ほとんどが使いやすいです。cmake、Qt のqmake 、またはsconsを見てください。
C++ build systemsなどの以前の質問も参照してください。
Autoconfというプログラムによって生成されます。
このconfigure
ファイルは、ファイルから autoconf を介して生成されconfigure.ac
ます。configure.ac
C++を使用するための最小限のテンプレートを次に示します。
dnl Minimal autoconf version supported. 2.60 is quite a good bias.
AC_PREREQ([2.60])
dnl Set program name and version. It will be used in output,
dnl and then passed to program as #define PACKAGE_NAME and PACKAGE_VERSION.
AC_INIT([program-name], [program-version])
dnl Keep helpers in build-aux/ subdirectory to not leave too much junk.
AC_CONFIG_AUX_DIR([build-aux])
dnl Enable generation of Makefile.in by automake.
dnl Minimal automake version: 1.6 (another good bias IMO).
dnl foreign = disable GNU rules requiring files like NEWS, README etc.
dnl dist-bzip2 = generate .tar.bz2 archives by default (make dist).
dnl subdir-objects = keep .o files in subdirectories with source files.
AM_INIT_AUTOMAKE([1.6 foreign dist-bzip2 subdir-objects])
dnl Enable silent rules if supported (i.e. CC something.o instead of gcc call)
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES])
dnl Find a good C++ compiler.
AC_PROG_CXX
dnl Write #defines to config.h file.
dnl You need to generate config.h.in, for example using autoheader.
AC_CONFIG_HEADERS([config.h])
dnl Generate Makefile from Makefile.in.
AC_CONFIG_FILES([Makefile])
dnl This generates fore-mentioned files.
AC_OUTPUT
行はコメント (説明) であり、dnl
ファイルから削除できます。
automake を使用して生成することも想定してMakefile
います。それを望まない場合はMakefile.in
、手動で準備する必要があります (そして行を削除しAM_INIT_AUTOMAKE
ます)。
設定結果は に書き込まれconfig.h
ます。通常、次のように含めます。
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
そして私のテンプレートMakefile.am
(automakeで使用されます):
# Programs which will be compiled and installed to /usr/bin (or similar).
bin_PROGRAMS = myprogram
# Source files for program 'myprogram'.
myprogram_SOURCES = src/f1.cxx src/f2.cxx
# Linked libraries for program 'myprogram'.
myprogram_LDADD = -llib1 -llib2
これら 2 つのテンプレートを作成した後、通常autoreconf -vi
はランダムなツールではなく自分で実行します。これは、必要なものを推測して実行します。
さらに何か必要な場合は、お気軽にお知らせください。喜んで説明させていただきます。