如何使用 Visual Studio 2015 构建 PJSUA2 (swig) [英] How to build PJSUA2 (swig) with Visual Studio 2015
问题描述
我尝试为 Python 编译 PJSUA2.我可以设法使用 Visual Studio 2015 社区版编译源代码.
我的问题是,我现在如何安装 Python 模块?
指南建议使用 make 和 make install.我也尝试安装 minwg,但它不起作用,因为该项目是用 VS 编译的.
<块引用>我也尝试过使用 minwg 进行编译,但由于未定义的要求,我永远无法成功.PJSUA 官方指南也推荐使用 VS for Windows.
以下设置已应用于从源代码构建:
- Swig 位置已添加到路径
- JAVA_home 系统变量已添加
- Java 位置已添加到路径
- 已创建空的 pjlib/include/pj/config_site.h
- 在 VS 2015 社区中开源(已安装所有建议的 VS 包和模块)
- 将以下项目设置为不编译:
- pjsua_cli_uwp_comp
- pjsua_cli_wp8
- pjsua_cli_wp8_comp
- 将 swig_java_pjsua2 设置为构建.
- 将以下文件夹添加到 swig_java_pjsua2 VC++ 包含目录
- c:\Program Files\Java\jdk-11.0.2\include
- c:\Program Files\Java\jdk-11.0.2\include\win32
- 构建解决方案
我可以制定一个解决方法来为 Python 3.7 编译 pjsua2.如果您有更好的解决方案或对此解决方法的建议,请告诉我
前提:
- 列表项
- 下载并解压 swig (swigwin 4.0.0)
- 下载并安装JDK
- 下载并安装 Python (Python 3.7.3 x64) 并在自定义安装时进行设置:
- 勾选将 Python 添加到环境变量"
- 勾选预编译标准库"
- 勾选下载调试符号"
- 勾选下载调试二进制文件(需要 VS 2015 或更高版本)"
- 根据需要设置自定义路径
- 将 swigwin 位置添加到系统路径
- 将 Python 位置添加到系统路径
- 添加JAVA_HOME系统变量
- 将 %JAVA_HOME%\bin 添加到系统路径
- 安装 Visual Studio 2015 社区版
步骤:
- 下载并解压 pjsip 2.8
- 在 pjlib/inlclude/pj/文件夹下创建空的 config_site.h
- 在VS中打开pjproject-vs14.sln
- 将出现一个不受支持的警告窗口,按确定
- 在安装缺少的功能"窗口中,按安装
- 将启动 VS 安装程序,必须关闭 VS 才能完成安装.
- 我还在安装中添加了Windows 10 SDK (10.0.10586)".
- 我还在 Windows 10 上启用了开发者模式,但这可能是可选的
- 在 VS 中再次打开项目
- 在顶部下拉菜单中将项目设置为 Release 和 x64
- 右键单击解决方案,然后转到配置属性">配置"
- 从选择中删除所有与 uwp 和 wp8 相关的项目,例如 pjsua_cli_uwp_comp、pjsua_cli_wp8_comp
- 按确定,然后构建解决方案
- 构建后我有 34 个成功的解决方案和 0 个失败的解决方案.
将以下几行添加到 pjsip-apps/src/swig 文件夹中的 pjsua2.i
%inline %{pj_ssize_t new_pj_ssize_t(int s) {返回 (pj_ssize_t) s;}%}
<块引用>
这个额外的内联 swig 函数为创建记录器提供了解决方法 问题
- 打开命令行(powershell 不支持此功能)
- 转到 pjsip-apps/src/swig/python
执行以下命令:
swig -I../../../../pjlib/include -I../../../../pjlib-util/include -I../../../../pjmedia/include -I../../../../pjsip/include -I../../../../pjnath/include -py3 -c++ -python-线程../pjsua2.i
使用 swig_python_pjsua2 名称将新的空项目"(Visual C++)添加到解决方案
- 添加 libpjproject 和 pjsua2_lib 作为对这个新项目的引用
- 右键单击头文件>添加>现有项目...
- 添加 pjsip-apps\src\swig\pjsua2_wrapp.h
- 向名为生成的代码"的项目添加新过滤器"
- 右键单击生成的代码"并添加新的现有项目.
- 添加 pjsip-apps\src\swig\pjsua2_wrapp.cxx
- 右键单击项目和链接器>输入
- 将Ws2_32.Lib"添加到附加依赖项"
- 转到VC++ 目录"
- 添加以下文件夹以包含路径(我使用了完整路径!):
- c:\python37\include
- pjnath\include
- pjsip\include
- pjmedia\include
- pjlib-util\include
- pjlib\include
- 将以下文件夹添加到库目录:
- C:\Python36\libs
- 设置为常规:
- 目标名称:_$(ProjectName)
- 目标扩展名:.pyd
- 配置类型:动态库 (.dll)
- 转到解决方案的属性,然后选择 swig_python_pjsua2 来构建
- 右键单击 swig_python_pjsua2 并构建
- 构建应该成功完成
- 您需要提交文件才能在 python 中使用 pjsua2 库.
- pjsua.py 位于 pjsip-apps/src/swig/python 下
- x64/Release/_swig_python_pjsua2.pyd(将其重命名为 _pjsua2.pyd)
- 要测试,将这些文件复制到一个文件夹中,从同一文件夹启动 python 并键入:
- 导入 pjsua2
I try to compile PJSUA2 for Python. I could manage to compile the source with Visual Studio 2015 Community edition.
My question is, how can I install the Python module now?
The guide suggests to use make and make install. I tried to install also minwg, but it is not working as the project was compiled with VS.
I have also tried to compile with minwg, but I never could succeed due to undefined requirements. Also official PJSUA guide recommend to use VS for Windows.
Following settings have been applied to build from source:
- Swig location has been added to path
- JAVA_home system variable has been added
- Java location has been added to path
- Empty pjlib/include/pj/config_site.h has been created
- Opened source in VS 2015 Community (all suggested VS package and module has been installed)
- Set following project to do not compile:
- pjsua_cli_uwp_comp
- pjsua_cli_wp8
- pjsua_cli_wp8_comp
- Set swig_java_pjsua2 to build.
- Add following folders to swig_java_pjsua2 VC++ include directories
- c:\Program Files\Java\jdk-11.0.2\include
- c:\Program Files\Java\jdk-11.0.2\include\win32
- Build solution
I could make a workaround to compile pjsua2 for Python 3.7. If you have a better solution or just suggestion to this workaround, let me know
Preconditions:
- List item
- Download and extract swig (swigwin 4.0.0)
- Download and install JDK
- Download and install Python (Python 3.7.3 x64) and set at custom installation:
- tick "Add Python to environment variables"
- tick "Precompile standard library"
- tick "Download debugging symbols"
- tick "Download debug binaries (requires VS 2015 or later)"
- set custom path if you want
- add swigwin location to system path
- add Python location to system path
- add JAVA_HOME system variable
- add %JAVA_HOME%\bin to system path
- Install Visual Studio 2015 Community edition
Steps:
- Download and extract pjsip 2.8
- Create empty config_site.h under pjlib/inlclude/pj/ folder
- Open pjproject-vs14.sln in VS
- There will be an unsupported warning window, press OK
- At the "Install Missing Features" windows, press install
- VS installer will be started, and VS has to be closed to complete installation.
- I have also added "Windows 10 SDK (10.0.10586)" to the installation.
- I have also enabled developer mode on my Windows 10, but this could be optional
- Open project again in VS
- Set project to Release and x64 on the top dropdown
- Right click on the solution, and go to Configuration Properties> Configuration
- Remove all uwp and wp8 related projects from selection, like pjsua_cli_uwp_comp, pjsua_cli_wp8_comp
- press OK, and build solution
- I have had 34 succeeded and 0 failed solution after build.
Add following lines to pjsua2.i in pjsip-apps/src/swig folder
%inline %{ pj_ssize_t new_pj_ssize_t(int s) { return (pj_ssize_t) s; } %}
this extra inline swig function provides workaround for create recorder issue
- Open a command line (powershell did not work for this)
- go to pjsip-apps/src/swig/python
Execute following command:
swig -I../../../../pjlib/include -I../../../../pjlib-util/include -I../../../../pjmedia/include -I../../../../pjsip/include -I../../../../pjnath/include -py3 -c++ -python -threads ../pjsua2.i
Add new "Empty Project" (Visual C++) to solution with swig_python_pjsua2 name
- Add libpjproject and pjsua2_lib as reference to this new project
- Right click on the Header Files>Add>Existing Item...
- Add pjsip-apps\src\swig\pjsua2_wrapp.h
- Add a "new filter" to the project with name "Generated Code"
- Right click on "Generated code" and add new existing item.
- Add pjsip-apps\src\swig\pjsua2_wrapp.cxx
- Right click on the project and Linker>Input
- Add "Ws2_32.Lib" to "Additional Dependencies"
- Go to "VC++ Directories"
- Add following folder to include path(I have used full path!):
- c:\python37\include
- pjnath\include
- pjsip\include
- pjmedia\include
- pjlib-util\include
- pjlib\include
- Add following folder to Library Directories:
- C:\Python36\libs
- Set at General:
- Target Name: _$(ProjectName)
- Target Extension: .pyd
- Configuration Type: Dynamic Library (.dll)
- Go to properties of the solution, and select swig_python_pjsua2 to build
- Right click on swig_python_pjsua2 and build
- Build should complete successfully
- You will need to file to use pjsua2 library in python.
- pjsua.py located under pjsip-apps/src/swig/python
- x64/Release/_swig_python_pjsua2.pyd (rename this to _pjsua2.pyd)
- To test, copy those to file into a folder, start python from same folder and type:
- import pjsua2
这篇关于如何使用 Visual Studio 2015 构建 PJSUA2 (swig)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!