东方耀AI技术分享
标题:
源码编译安装swig(超详细)Ubuntu18.04
[打印本页]
作者:
东方耀
时间:
2020-10-19 11:37
标题:
源码编译安装swig(超详细)Ubuntu18.04
近来因为工作需要需要在需要在python中调用c/c++代码的方式 *.i文件为swig的接口文件
swig它可以用来连接(包装)其它的语言,以便发挥它们各自的特性
适用swig进行该方法的处理。
步骤:
1、下载swig源码包
http://www.swig.org/survey.html
当前最新版本:swig-4.0.2.tar.gz
2、检查系统的环境,没有则安装好
g++ -version
gcc -version
sudo apt-get install libpcre3 libpcre3-dev
3、解压:tar -xvf swig-4.0.2.tar.gz
cd swig-4.0.2/ 后ll 注意configure的权限
4、配置、编译和安装 swig
./configure --prefix=/home/jiang/dfy_softwares/my_swig(此处指定安装目录,不指定默认直接默认系统路径/usr/local)
make // 编译
make install // 安装
最后一行显示: Installation complete
5、配置环境变量
vim .bashrc
加上下面二行:
export SWIG_HOME=/home/jiang/dfy_softwares/my_swig/bin
export PATH=${SWIG_HOME}: ${PATH}
这样,在其他路径下就可以执行 swig 命令
6、重新打开终端 验证swig是否安装成功
swig -version
至此,swig安装完成
jiang@jiang-Ubuntu:~/dfy_softwares/swig-4.0.2$ ./configure --prefix=/home/jiang/dfy_softwares/my_swig
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking whether gcc understands -c and -o together... yes
checking for style of include used by make... GNU
checking dependency style of gcc... gcc3
checking for g++... g++
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking dependency style of g++... gcc3
checking maximum warning verbosity option... -Wall -W -ansi -pedantic for C++ -Wall -W -ansi -pedantic for C
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for ANSI C header files... yes
checking for popen... yes
checking whether to enable PCRE support... yes
checking whether to use local PCRE... no
checking for a sed that does not truncate output... /bin/sed
checking for pcre-config... /usr/bin/pcre-config
checking whether to enable ccache-swig... yes
Checking packages required for SWIG developers.
Note : None of the following packages are required for users to compile and install SWIG from the distributed tarball
checking for bison... bison -y
Checking for installed target languages and other information in order to compile and run
the examples and test-suite invoked by 'make check'.
Note : None of the following packages are required for users to compile and install SWIG from the distributed tarball
checking for boostlib >= (102000)... yes
checking SO... .so
checking LDSHARED... gcc -shared
checking CXXSHARED... gcc -shared
checking TRYLINKINGWITHCXX... CXXSHARED= g++ -shared
checking CCSHARED... -fpic
checking RPATH... -Xlinker -rpath $(exec_prefix)/lib -Xlinker -rpath .
checking LINKFORSHARED... -Xlinker -export-dynamic
checking PLATCFLAGS...
checking whether to enable C++11 testing... no
checking if compiler supports pre-compiled headers... yes
checking for dlopen in -ldl... yes
checking for shl_load in -ldld... no
checking for library containing t_open... no
checking for library containing gethostbyname... none required
checking for library containing socket... none required
checking for swill_init in -lswill... no
checking for main in -lieee... no
checking for crypt in -lcrypt... yes
checking for pkg-config... pkg-config
checking for Tcl configuration... no
checking for Tcl header files... not found
checking for Tcl library... not found
checking for python... python
checking for python major version number... 2
checking for Python os.name... posix
checking for Python path separator... /
checking for Python prefix... /usr
checking for Python exec-prefix... /usr
checking for Python version... python2.7
checking for Python lib dir... lib
checking for Python header files... -I/usr/include/python2.7 -I/usr/lib/python2.7/config
checking for Python library directory... Not found
checking for Python library... -lpython2.7
checking for python3... python3
checking for python3-config... python3-config
checking for python3 major version number... 3
checking for Python 3.x os.name... posix
checking for Python 3.x path separator... /
checking for Python 3.x prefix... /usr
checking for Python 3.x exec-prefix... /usr
checking for Python 3.x version... python3.6
checking for Python 3.x lib dir... lib
checking for Python 3.x header files... -I/usr/include/python3.6m -I/usr/include/python3.6m
checking for Python 3.x library directory... Not found
checking for Python 3.x library... -lpython3.6
checking for pycodestyle... no
checking for 2to3-3... no
checking for 2to3... no
checking for 2to3.py... Not found
checking for perl... perl
checking for Perl5 header files... /usr/lib/x86_64-linux-gnu/perl/5.26/CORE
checking for Perl5 library... perl
checking for Perl5 ccflags... -D_REENTRANT -D_GNU_SOURCE -DDEBIAN -fwrapv -fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
checking for Perl5 ccdlflags... -Wl,-E
checking for Perl5 cccdlflags... -fPIC
checking for Perl5 ldflags... -fstack-protector-strong -L/usr/local/lib
checking for Perl5 Test::More module... found
checking for octave-cli... no
checking for scilab... no
checking for java JDK... found (in /home/jiang/dfy_softwares2/android-studio/jre)
checking if java version is 9 or greater... no, disabling Doxygen tests
checking for java include file jni.h... -I"/home/jiang/dfy_softwares2/android-studio/jre/include"
checking for java include file jni_md.h... -I"/home/jiang/dfy_softwares2/android-studio/jre/include/linux"
checking for nodejs... no
checking for node... no
checking for JavaScriptCore/JavaScript.h... not found
checking for JavaScriptCore/Webkit library... not found
checking for V8 Javascript v8.h... not found
checking for V8 Javascript library... not found
checking for android... no
checking for adb... adb
checking for ant... no
checking for ndk-build... no
checking for guile-config... no
checking for mzscheme... no
checking for mzc... no
checking for ruby... no
checking for Ruby header files... could not figure out how to run ruby
checking for php7.3... no
checking for php7.2... no
checking for php7.1... no
checking for php7.0... no
checking for php... no
checking for ocamlc... no
checking for camlp4... no
checking for ocamldlgen... no
checking for ocamlfind... no
checking for ocamlmktop... no
checking for mono-csc... no
checking for gmcs... no
checking for mcs... no
checking for cscc... no
checking for lua5.4... no
checking for lua5.3... no
checking for lua5.2... no
checking for lua5.1... no
checking for lua... no
checking for R... no
checking for go... no
checking for gccgo... no
checking for dmd... no
checking for ldmd... no
checking for gdmd... no
checking for dmd... no
checking for gdmd... no
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating swig.spec
config.status: creating Examples/Makefile
config.status: creating Examples/d/example.mk
config.status: creating Examples/xml/Makefile
config.status: creating Examples/test-suite/errors/Makefile
config.status: creating Examples/test-suite/csharp/Makefile
config.status: creating Examples/test-suite/d/Makefile
config.status: creating Examples/test-suite/guile/Makefile
config.status: creating Examples/test-suite/java/Makefile
config.status: creating Examples/test-suite/javascript/Makefile
config.status: creating Examples/test-suite/mzscheme/Makefile
config.status: creating Examples/test-suite/ocaml/Makefile
config.status: creating Examples/test-suite/octave/Makefile
config.status: creating Examples/test-suite/perl5/Makefile
config.status: creating Examples/test-suite/php/Makefile
config.status: creating Examples/test-suite/python/Makefile
config.status: creating Examples/test-suite/ruby/Makefile
config.status: creating Examples/test-suite/scilab/Makefile
config.status: creating Examples/test-suite/tcl/Makefile
config.status: creating Examples/test-suite/lua/Makefile
config.status: creating Examples/test-suite/r/Makefile
config.status: creating Examples/test-suite/go/Makefile
config.status: creating Source/Makefile
config.status: creating Tools/javascript/Makefile
config.status: creating preinst-swig
config.status: creating CCache/ccache_swig_config.h
config.status: creating Source/Include/swigconfig.h
config.status: executing depfiles commands
config.status: executing Examples commands
=== configuring in CCache (/home/jiang/dfy_softwares/swig-4.0.2/CCache)
configure: running /bin/bash ./configure --disable-option-checking '--prefix=/home/jiang/dfy_softwares/my_swig' --cache-file=/dev/null --srcdir=.
configure: Configuring ccache
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking how to run the C preprocessor... gcc -E
checking for a BSD-compatible install... /usr/bin/install -c
checking for dirent.h that defines DIR... yes
checking for library containing opendir... none required
checking whether time.h and sys/time.h may both be included... yes
checking for sys/wait.h that is POSIX.1 compatible... yes
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking ctype.h usability... yes
checking ctype.h presence... yes
checking for ctype.h... yes
checking for strings.h... (cached) yes
checking for stdlib.h... (cached) yes
checking for string.h... (cached) yes
checking pwd.h usability... yes
checking pwd.h presence... yes
checking for pwd.h... yes
checking sys/time.h usability... yes
checking sys/time.h presence... yes
checking for sys/time.h... yes
checking for realpath... yes
checking for snprintf... yes
checking for vsnprintf... yes
checking for vasprintf... yes
checking for asprintf... yes
checking for mkstemp... yes
checking for gethostname... yes
checking for getpwuid... yes
checking for utimes... yes
checking for compar_fn_t in stdlib.h... yes
checking for C99 vsnprintf... yes
checking zlib.h usability... yes
checking zlib.h presence... yes
checking for zlib.h... yes
checking for gzdopen in -lz... yes
configure: creating ./config.status
config.status: creating config_win32.h
config.status: creating Makefile
config.status: creating config.h
The SWIG test-suite and examples are configured for the following languages:
java perl5 python
复制代码
作者:
bixintao
时间:
2020-11-10 19:52
积分积分积分
作者:
东方耀
时间:
2021-4-20 16:01
Tensorflow已经从SWIG切到pybind11了
个人比较喜欢/偏向于pybind11,有以下几个原因1. 灵活性:pybind11本质上还是在C API外面包了一层C++(或者说利用C++的元编程能力批量产生binding)所以可定制性很好,尤其是面向我这种有非主流需求的用户。2. 抽象能力:cython这种Python的补丁抽象能力没有完整的C++好,对于一个倾向于只让Python成为傻瓜式接口的人,我更希望能够同时在C++层面有丰富的抽象来方便developer。3. 生态:pybind11现在有很多基于它的生态,例如xtensor,Python/C++里最好的多维数组没有之一。然后还有pythran这个transpiler,可以把Python的prototype转到C++,一定程度上减轻编写C++的蛋疼点。PS. 我觉得有了pythran以后cython已经没有任何优势了
作者:
东方耀
时间:
2021-4-20 21:01
CMAKE_INSTALL_PREFIX变量类似于configure脚本的 –prefix
作者:
Rachel
时间:
2022-5-4 22:00
bixintao 发表于 2020-11-10 19:52
积分积分积分
评论会有积分嘛
欢迎光临 东方耀AI技术分享 (http://ai111.vip/)
Powered by Discuz! X3.4