LoginSignup
24
14

More than 5 years have passed since last update.

SWIGをビルドするときにハマッたこと

Posted at

SWIGとは、

SWIG (Simplified Wrapper and Interface Generator) は、 C/C++ で書かれたプログラムやライブラリを、Tcl/Tk、Perl、Python、Ruby、PHP、Lua などのスクリプト言語や、Java、C#、Scheme、Ocaml などの言語に接続するためのオープンソースのツールである。

さて、 "http://www.swig.org" からSWIGをダウンロードしてビルドすることは今までやっていましたが、
今回は GitHub から clone してきての作業でハマりました。

環境は Ubuntu 14.04 です。
(ほとんど初期状態)

configureが無い

./configure
make
make install

上記のいつものコマンドを実行したかったのですが、
configure が無い!( configure.ac はある模様)
※ちなみに通常ダウンロードしてきた圧縮ファイル内には configure ファイルが元々いらっしゃる。

google先生に確認してみると、 autoreconf コマンドで configure ファイルが生成されるとのこと。
参考URL: http://staffblog.yumemi.jp/autoconfconfigureスクリプトを使ってアプリケーションの設定-2

早速 autoreconf コマンドを打つとインストールされていなかった...orz
ということでAutotools群をインストールしました。

sudo apt-get install autoconf automake libtool

ってことで、改めて...

$ autoreconf
configure.ac:35: error: possibly undefined macro: AC_COMPILE_WARNINGS
      If this token and others are legitimate, please use m4_pattern_allow.
      See the Autoconf documentation.
configure.ac:53: error: possibly undefined macro: AC_DEFINE
configure.ac:69: error: possibly undefined macro: AC_MSG_RESULT
configure.ac:91: error: possibly undefined macro: AC_MSG_FAILURE
configure.ac:2821: error: possibly undefined macro: AC_DEFINE_DIR
autoreconf: /usr/bin/autoconf failed with exit status: 1

ちょっと違ったみたい。
autogen.sh なるものがあったので、そっちを実行。(中身みたらAutotoolsを実行するスクリプトだったので)

$ ./autogen.sh 
+ test -d Tools/config
+ aclocal -I Tools/config
+ autoheader
+ automake --add-missing --copy --force-missing
configure.ac:29: installing 'Tools/config/compile'
configure.ac:14: installing 'Tools/config/config.guess'
configure.ac:14: installing 'Tools/config/config.sub'
configure.ac:15: installing 'Tools/config/install-sh'
configure.ac:15: installing 'Tools/config/missing'
Source/Makefile.am: installing 'Tools/config/depcomp'
configure.ac: installing 'Tools/config/ylwrap'
+ autoconf
+ cd CCache
+ autoreconf

$ ls
aclocal.m4  appveyor.yml  autom4te.cache  CHANGES          configure     COPYRIGHT  Doc       INSTALL  LICENSE      LICENSE-UNIVERSITIES  preinst-swig.in  RELEASENOTES  swig.spec.in  Tools  Win
ANNOUNCE    autogen.sh    CCache          CHANGES.current  configure.ac  debian     Examples  Lib      LICENSE-GPL  Makefile.in   

configure 生まれた!

PCRE周りが無い

configure ファイルが出来上がったので早速いつものコマンドを。

$ ./configure
=略=
configure: error: in `/home/chibi/sources/swig':
configure: error: 
        Cannot find pcre-config script from PCRE (Perl Compatible Regular Expressions)
        library package. This dependency is needed for configure to complete,
        Either:
        - Install the PCRE developer package on your system (preferred approach).
        - Download the PCRE source tarball, build and install on your system
          as you would for any package built from source distribution.
        - Use the Tools/pcre-build.sh script to build PCRE just for SWIG to statically
          link against. Run 'Tools/pcre-build.sh --help' for instructions.
          (quite easy and does not require privileges to install PCRE on your system)
        - Use configure --without-pcre to disable regular expressions support in SWIG
          (not recommended).
See `config.log' for more details

今度はPCRE周りが無いとのこと。

ということでPCREをインストール。

$ sudo apt-get install libpcre3-dev

ってことで、改めて...

$ ./configure

$ ls
aclocal.m4    autogen.sh      CHANGES          config.status  COPYRIGHT  Examples  LICENSE               Makefile      preinst-swig.in  Source        TODO   Win
ANNOUNCE      autom4te.cache  CHANGES.current  configure      debian     INSTALL   LICENSE-GPL           Makefile.in   README           swig.spec     Tools
appveyor.yml  CCache          config.log       configure.ac   Doc        Lib       LICENSE-UNIVERSITIES  preinst-swig  RELEASENOTES     swig.spec.in  vms

無事に Makefile が生まれた。

yaccが無い

Makefileも無事に生成されたので make コマンドを叩きました。

$ make
mkdir -p Lib
echo "/* SWIG warning codes */" > Lib/swigwarn.swg
cat Source/Include/swigwarn.h | grep "^#define WARN\|/\*.*\*/\|^[ \t]*$" | sed 's/^#define \(WARN.*[0-9][0-9]*\)\(.*\)$/%define SWIG\1 %enddef\2/' >> Lib/swigwarn.swg
make[1]: Entering directory `/home/chibi/sources/swig/Source'
/bin/bash ../Tools/config/ylwrap CParse/parser.y y.tab.c CParse/parser.c y.tab.h `echo CParse/parser.c | sed -e s/cc$/hh/ -e s/cpp$/hpp/ -e s/cxx$/hxx/ -e s/c++$/h++/ -e s/c$/h/` y.output CParse/parser.output -- yacc -d 
../Tools/config/ylwrap: line 176: yacc: command not found
make[1]: *** [CParse/parser.c] Error 127
make[1]: Leaving directory `/home/chibi/sources/swig/Source'
make: *** [source] Error 2

yacc が無いよ。
yacc は以下のパッケージに含まれているそうな。

$ yacc
The program 'yacc' can be found in the following packages:
 * bison
 * byacc-j
 * bison++
 * btyacc
 * byacc
 * perl-byacc
Try: sudo apt-get install <selected package>
sudo apt-get install bison

最後に make で完了。
g++ コマンドすら入っていなかった場合は、 g++ をインストールして、
make clean して ./configure からやり直し。

まとめ

$ sudo apt-get install autoconf automake libtool
$ sudo apt-get install libpcre3-dev
$ sudo apt-get install bison
$ sudo apt-get install g++
$ git clone https://github.com/swig/swig.git
$ cd swig/
$ ./autogen.sh 
$ ./configure
$ make

たぶん、これですんなり行く。

24
14
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
24
14