东方耀AI技术分享

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz
查看: 5804|回复: 4
打印 上一主题 下一主题

[C/C++] 源码编译安装swig(超详细)Ubuntu18.04

[复制链接]

1366

主题

1857

帖子

1万

积分

管理员

Rank: 10Rank: 10Rank: 10

积分
14459
QQ
跳转到指定楼层
楼主
发表于 2020-10-19 11:37:09 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式




近来因为工作需要需要在需要在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安装完成



  1. jiang@jiang-Ubuntu:~/dfy_softwares/swig-4.0.2$ ./configure --prefix=/home/jiang/dfy_softwares/my_swig
  2. checking build system type... x86_64-pc-linux-gnu
  3. checking host system type... x86_64-pc-linux-gnu
  4. checking for a BSD-compatible install... /usr/bin/install -c
  5. checking whether build environment is sane... yes
  6. checking for a thread-safe mkdir -p... /bin/mkdir -p
  7. checking for gawk... gawk
  8. checking whether make sets $(MAKE)... yes
  9. checking whether make supports nested variables... yes
  10. checking for gcc... gcc
  11. checking whether the C compiler works... yes
  12. checking for C compiler default output file name... a.out
  13. checking for suffix of executables...
  14. checking whether we are cross compiling... no
  15. checking for suffix of object files... o
  16. checking whether we are using the GNU C compiler... yes
  17. checking whether gcc accepts -g... yes
  18. checking for gcc option to accept ISO C89... none needed
  19. checking whether gcc understands -c and -o together... yes
  20. checking for style of include used by make... GNU
  21. checking dependency style of gcc... gcc3
  22. checking for g++... g++
  23. checking whether we are using the GNU C++ compiler... yes
  24. checking whether g++ accepts -g... yes
  25. checking dependency style of g++... gcc3
  26. checking maximum warning verbosity option... -Wall -W -ansi -pedantic for C++ -Wall -W -ansi -pedantic for C
  27. checking how to run the C preprocessor... gcc -E
  28. checking for grep that handles long lines and -e... /bin/grep
  29. checking for egrep... /bin/grep -E
  30. checking for ANSI C header files... yes
  31. checking for popen... yes
  32. checking whether to enable PCRE support... yes
  33. checking whether to use local PCRE... no
  34. checking for a sed that does not truncate output... /bin/sed
  35. checking for pcre-config... /usr/bin/pcre-config
  36. checking whether to enable ccache-swig... yes

  37. Checking packages required for SWIG developers.
  38. Note : None of the following packages are required for users to compile and install SWIG from the distributed tarball

  39. checking for bison... bison -y

  40. Checking for installed target languages and other information in order to compile and run
  41. the examples and test-suite invoked by 'make check'.
  42. Note : None of the following packages are required for users to compile and install SWIG from the distributed tarball

  43. checking for boostlib >=  (102000)... yes
  44. checking SO... .so
  45. checking LDSHARED... gcc -shared
  46. checking CXXSHARED... gcc -shared
  47. checking TRYLINKINGWITHCXX... CXXSHARED= g++ -shared
  48. checking CCSHARED... -fpic
  49. checking RPATH... -Xlinker -rpath $(exec_prefix)/lib -Xlinker -rpath .
  50. checking LINKFORSHARED... -Xlinker -export-dynamic
  51. checking PLATCFLAGS...
  52. checking whether to enable C++11 testing... no
  53. checking if compiler supports pre-compiled headers... yes
  54. checking for dlopen in -ldl... yes
  55. checking for shl_load in -ldld... no
  56. checking for library containing t_open... no
  57. checking for library containing gethostbyname... none required
  58. checking for library containing socket... none required
  59. checking for swill_init in -lswill... no
  60. checking for main in -lieee... no
  61. checking for crypt in -lcrypt... yes
  62. checking for pkg-config... pkg-config
  63. checking for Tcl configuration... no
  64. checking for Tcl header files... not found
  65. checking for Tcl library... not found
  66. checking for python... python
  67. checking for python major version number... 2
  68. checking for Python os.name... posix
  69. checking for Python path separator... /
  70. checking for Python prefix... /usr
  71. checking for Python exec-prefix... /usr
  72. checking for Python version... python2.7
  73. checking for Python lib dir... lib
  74. checking for Python header files... -I/usr/include/python2.7 -I/usr/lib/python2.7/config
  75. checking for Python library directory... Not found
  76. checking for Python library... -lpython2.7
  77. checking for python3... python3
  78. checking for python3-config... python3-config
  79. checking for python3 major version number... 3
  80. checking for Python 3.x os.name... posix
  81. checking for Python 3.x path separator... /
  82. checking for Python 3.x prefix... /usr
  83. checking for Python 3.x exec-prefix... /usr
  84. checking for Python 3.x version... python3.6
  85. checking for Python 3.x lib dir... lib
  86. checking for Python 3.x header files... -I/usr/include/python3.6m -I/usr/include/python3.6m
  87. checking for Python 3.x library directory... Not found
  88. checking for Python 3.x library... -lpython3.6
  89. checking for pycodestyle... no
  90. checking for 2to3-3... no
  91. checking for 2to3... no
  92. checking for 2to3.py... Not found
  93. checking for perl... perl
  94. checking for Perl5 header files... /usr/lib/x86_64-linux-gnu/perl/5.26/CORE
  95. checking for Perl5 library... perl
  96. 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
  97. checking for Perl5 ccdlflags... -Wl,-E
  98. checking for Perl5 cccdlflags... -fPIC
  99. checking for Perl5 ldflags...  -fstack-protector-strong -L/usr/local/lib
  100. checking for Perl5 Test::More module... found
  101. checking for octave-cli... no
  102. checking for scilab... no
  103. checking for java JDK... found (in /home/jiang/dfy_softwares2/android-studio/jre)
  104. checking if java version is 9 or greater... no, disabling Doxygen tests
  105. checking for java include file jni.h... -I"/home/jiang/dfy_softwares2/android-studio/jre/include"
  106. checking for java include file jni_md.h... -I"/home/jiang/dfy_softwares2/android-studio/jre/include/linux"
  107. checking for nodejs... no
  108. checking for node... no
  109. checking for JavaScriptCore/JavaScript.h... not found
  110. checking for JavaScriptCore/Webkit library... not found
  111. checking for V8 Javascript v8.h... not found
  112. checking for V8 Javascript library... not found
  113. checking for android... no
  114. checking for adb... adb
  115. checking for ant... no
  116. checking for ndk-build... no
  117. checking for guile-config... no
  118. checking for mzscheme... no
  119. checking for mzc... no
  120. checking for ruby... no
  121. checking for Ruby header files... could not figure out how to run ruby
  122. checking for php7.3... no
  123. checking for php7.2... no
  124. checking for php7.1... no
  125. checking for php7.0... no
  126. checking for php... no
  127. checking for ocamlc... no
  128. checking for camlp4... no
  129. checking for ocamldlgen... no
  130. checking for ocamlfind... no
  131. checking for ocamlmktop... no
  132. checking for mono-csc... no
  133. checking for gmcs... no
  134. checking for mcs... no
  135. checking for cscc... no
  136. checking for lua5.4... no
  137. checking for lua5.3... no
  138. checking for lua5.2... no
  139. checking for lua5.1... no
  140. checking for lua... no
  141. checking for R... no
  142. checking for go... no
  143. checking for gccgo... no
  144. checking for dmd... no
  145. checking for ldmd... no
  146. checking for gdmd... no
  147. checking for dmd... no
  148. checking for gdmd... no
  149. checking that generated files are newer than configure... done
  150. configure: creating ./config.status
  151. config.status: creating Makefile
  152. config.status: creating swig.spec
  153. config.status: creating Examples/Makefile
  154. config.status: creating Examples/d/example.mk
  155. config.status: creating Examples/xml/Makefile
  156. config.status: creating Examples/test-suite/errors/Makefile
  157. config.status: creating Examples/test-suite/csharp/Makefile
  158. config.status: creating Examples/test-suite/d/Makefile
  159. config.status: creating Examples/test-suite/guile/Makefile
  160. config.status: creating Examples/test-suite/java/Makefile
  161. config.status: creating Examples/test-suite/javascript/Makefile
  162. config.status: creating Examples/test-suite/mzscheme/Makefile
  163. config.status: creating Examples/test-suite/ocaml/Makefile
  164. config.status: creating Examples/test-suite/octave/Makefile
  165. config.status: creating Examples/test-suite/perl5/Makefile
  166. config.status: creating Examples/test-suite/php/Makefile
  167. config.status: creating Examples/test-suite/python/Makefile
  168. config.status: creating Examples/test-suite/ruby/Makefile
  169. config.status: creating Examples/test-suite/scilab/Makefile
  170. config.status: creating Examples/test-suite/tcl/Makefile
  171. config.status: creating Examples/test-suite/lua/Makefile
  172. config.status: creating Examples/test-suite/r/Makefile
  173. config.status: creating Examples/test-suite/go/Makefile
  174. config.status: creating Source/Makefile
  175. config.status: creating Tools/javascript/Makefile
  176. config.status: creating preinst-swig
  177. config.status: creating CCache/ccache_swig_config.h
  178. config.status: creating Source/Include/swigconfig.h
  179. config.status: executing depfiles commands
  180. config.status: executing Examples commands
  181. === configuring in CCache (/home/jiang/dfy_softwares/swig-4.0.2/CCache)
  182. configure: running /bin/bash ./configure --disable-option-checking '--prefix=/home/jiang/dfy_softwares/my_swig'  --cache-file=/dev/null --srcdir=.
  183. configure: Configuring ccache
  184. checking for gcc... gcc
  185. checking whether the C compiler works... yes
  186. checking for C compiler default output file name... a.out
  187. checking for suffix of executables...
  188. checking whether we are cross compiling... no
  189. checking for suffix of object files... o
  190. checking whether we are using the GNU C compiler... yes
  191. checking whether gcc accepts -g... yes
  192. checking for gcc option to accept ISO C89... none needed
  193. checking how to run the C preprocessor... gcc -E
  194. checking for a BSD-compatible install... /usr/bin/install -c
  195. checking for dirent.h that defines DIR... yes
  196. checking for library containing opendir... none required
  197. checking whether time.h and sys/time.h may both be included... yes
  198. checking for sys/wait.h that is POSIX.1 compatible... yes
  199. checking for grep that handles long lines and -e... /bin/grep
  200. checking for egrep... /bin/grep -E
  201. checking for ANSI C header files... yes
  202. checking for sys/types.h... yes
  203. checking for sys/stat.h... yes
  204. checking for stdlib.h... yes
  205. checking for string.h... yes
  206. checking for memory.h... yes
  207. checking for strings.h... yes
  208. checking for inttypes.h... yes
  209. checking for stdint.h... yes
  210. checking for unistd.h... yes
  211. checking ctype.h usability... yes
  212. checking ctype.h presence... yes
  213. checking for ctype.h... yes
  214. checking for strings.h... (cached) yes
  215. checking for stdlib.h... (cached) yes
  216. checking for string.h... (cached) yes
  217. checking pwd.h usability... yes
  218. checking pwd.h presence... yes
  219. checking for pwd.h... yes
  220. checking sys/time.h usability... yes
  221. checking sys/time.h presence... yes
  222. checking for sys/time.h... yes
  223. checking for realpath... yes
  224. checking for snprintf... yes
  225. checking for vsnprintf... yes
  226. checking for vasprintf... yes
  227. checking for asprintf... yes
  228. checking for mkstemp... yes
  229. checking for gethostname... yes
  230. checking for getpwuid... yes
  231. checking for utimes... yes
  232. checking for compar_fn_t in stdlib.h... yes
  233. checking for C99 vsnprintf... yes
  234. checking zlib.h usability... yes
  235. checking zlib.h presence... yes
  236. checking for zlib.h... yes
  237. checking for gzdopen in -lz... yes
  238. configure: creating ./config.status
  239. config.status: creating config_win32.h
  240. config.status: creating Makefile
  241. config.status: creating config.h

  242. The SWIG test-suite and examples are configured for the following languages:
  243. java perl5 python

复制代码



swig01.png (140.41 KB, 下载次数: 193)

swig01.png

swig02.png (22.08 KB, 下载次数: 196)

swig02.png

swig_3.0.8.png (15.22 KB, 下载次数: 188)

swig_3.0.8.png

swig_3.0.8_terminal.png (21.82 KB, 下载次数: 185)

swig_3.0.8_terminal.png

swig-4.0.2.tar.gz

7.72 MB, 阅读权限: 10, 下载次数: 0

swig-3.0.8.tar.gz

7.57 MB, 阅读权限: 10, 下载次数: 0

让天下人人学会人工智能!人工智能的前景一片大好!
回复

使用道具 举报

0

主题

100

帖子

236

积分

2W人工智能培训

Rank: 10Rank: 10Rank: 10

积分
236
沙发
发表于 2020-11-10 19:52:46 | 只看该作者
积分积分积分
回复

使用道具 举报

1366

主题

1857

帖子

1万

积分

管理员

Rank: 10Rank: 10Rank: 10

积分
14459
QQ
板凳
 楼主| 发表于 2021-4-20 16:01:29 | 只看该作者
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已经没有任何优势了
让天下人人学会人工智能!人工智能的前景一片大好!
回复

使用道具 举报

1366

主题

1857

帖子

1万

积分

管理员

Rank: 10Rank: 10Rank: 10

积分
14459
QQ
地板
 楼主| 发表于 2021-4-20 21:01:10 | 只看该作者
CMAKE_INSTALL_PREFIX变量类似于configure脚本的 –prefix
让天下人人学会人工智能!人工智能的前景一片大好!
回复

使用道具 举报

0

主题

1

帖子

4

积分

新手上路

Rank: 1

积分
4
5#
发表于 2022-5-4 22:00:15 | 只看该作者

评论会有积分嘛
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|人工智能工程师的摇篮 ( 湘ICP备2020019608号-1 )

GMT+8, 2024-6-24 20:34 , Processed in 0.195465 second(s), 21 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表