build boost 1.46 and python3.2

本文解决了在使用 VC++2008 编译 Boost 1.46 与 Python 3.2 时出现的错误,并提供了配置文件 user-config.jam 的修改建议。此外还涉及了 Boost.Log 和 Boost.Filesystem 版本不匹配的问题及解决方案。

There is one build error when building boost 1.46 + python 3.2 via VC++ 2008:

libs/python/src/converter/builtin_converters.cpp(436) : error C2664: 'PyUnicodeUCS2_AsWideChar' : cannot convert parameter 1 from 'PyUnicodeObject *' to 'PyObject *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

 

Solution: change libs/python/src/converter/builtin_converters.cpp(436)

 

 

      static std::wstring extract(PyObject* intermediate)
      {
          std::wstring result(::PyObject_Length(intermediate), L' ');
          if (!result.empty())
          {
              int err = PyUnicode_AsWideChar(
                  /*(PyUnicodeObject *)*/intermediate     // change this line, comment out the C style cast!!!
                , &result[0]
                , result.size());

              if (err == -1)
                  throw_error_already_set();
          }
          return result;
      }

 

Note: I also append the following to D:/opensource/boost_1_46_0/tools/build/v2/user-config.jam

###########################################################
using python
    : 3.2                         # Version
    : C://Python32//python.exe    # Python Path
    : C://Python32//Include        # include path(s) -they may be not really needed here
    : C://Python32//libs        # lib path(s) - they may be not really needed here
    : <python-debugging>off <define>BOOST_ALL_NO_LIB=1
    ; 
using python
    : 3.2                         # Version
    : C://Python32//python.exe    # Python Path
    : C://Python32//Include        # include path(s) -they may be not really needed here
    : C://Python32//libs        # lib path(s) - they may be not really needed here
    : <python-debugging>on <define>BOOST_ALL_NO_LIB=1
    ; 
###########################################################

 

I also need to modify the following line in D:/src/boost_1_46_0/libs/python/src/module.cpp

BOOST_PYTHON_DECL PyObject* init_module(PyModuleDef& moduledef, void(*init_function)())

Otherwise there is a link error: 

error LNK2001: unresolved external symbol "__declspec(dllimport) struct _object * __cdecl boost::python::detail::init_module(struct PyModuleDef &,void (__cdecl*)(void))" (__imp_?init_module@detail@python@boost@@YAPAU_object@@AAUPyModuleDef@@P6AXXZ@Z)

 

boost.log is only compatible with boost.filesystem v2, but boost 1.46 is using boost.filesystem v3 by default.

 

compile-c-c++ bin.v2/libs/log/build/msvc-10.0/release/link-static/runtime-link-static/threading-multi/text_file_backend.obj

text_file_backend.cpp

./boost/log/detail/universal_path.hpp(46) : error C2039: 'external_string_type' : is not a member of 'boost::filesystem3::path'

 

The following command can be used to build boost.log.

bjam.exe --with-log --toolset=msvc stage --build-type=complete define=BOOST_FILESYSTEM_VERSION=2

 

I created a batch file to build the boost library.

 

rem call "%VS100COMNTOOLS%/../../vc/bin/vcvars32.bat"

call "%VS90COMNTOOLS%/../../VC/vcvarsall.bat"

cd /d D:/opensource/boost_1_46_0

echo Update D:/opensource/boost_1_46_0/tools/build/v2/user-config.jam

call bootstrap.bat

set ICU_PATH=D:/opensource/icu4c-4_6-src/icu

echo "build start" >> buildtime.txt

time /t  >> buildtime.txt

bjam.exe --toolset=msvc stage --build-type=complete -sBZIP2_SOURCE=D:/opensource/bzip2-1.0.5 -sZLIB_SOURCE=D:/opensource/zlib-1.2.5 -sICU_PATH="D:/opensource/icu4c-4_4_1-Win32-msvc9/icu" >> msvc10.log

time /t  >> buildtime.txt

echo "build finished" >> buildtime.txt

 

Use boost.log in DLL

When I am using boost.log in DLL, the Debug configuration will raise the following error:

 

---------------------------

Microsoft Visual C++ Debug Library

---------------------------

Debug Assertion Failed!

 

Program: E:/svn/trunk/Debug/Onegad.exe

File: f:/dd/vctools/vc7libs/ship/atlmfc/src/mfc/dllinit.cpp

Line: 587

 

For information on how your program can cause an assertion

failure, see the Visual C++ documentation on asserts.

 

(Press Retry to debug the application)

---------------------------

Abort   Retry   Ignore   

---------------------------

The problem is fixed by adding BOOST_THREAD_DYN_LINK preprocessor to my DLL project. 

 

 

 

compile with Intel C++ compiler

 

C:/tmp/boost_1_35_0/libs/program_options/build>../../../bjam.exe --toolset=intel release

C:/tmp/boost_1_35_0/libs/program_options/build>../../../bjam.exe --toolset=intel 

C:/tmp/boost_1_35_0/libs/program_options/build>../../../bjam.exe --toolset=intel link=static debug release 

 

<think>嗯,用户想在Ubuntu 22.04上安装Python 3.2。首先,我需要确认Python 3.2是否适用于这个系统版本。Ubuntu 22.04默认的Python版本通常是3.10或更高,而Python 3.2已经很老了,可能不被官方仓库支持。 我记得APT仓库通常不会保留非常旧的版本,所以用户可能需要通过其他方式安装。比如从源码编译或者使用第三方PPA。不过,Python 3.2已经停止维护,可能存在兼容性问题,特别是与较新的库和系统依赖项之间。 接下来,我需要检查是否有PPA提供Python 3.2。搜索一下,发现常用的PPA如deadsnakes可能没有3.2版本,他们通常支持较新的版本。这时候可能需要用户自己下载源码编译。 源码编译的话,需要安装必要的构建工具,比如gcc、make,以及开发库如libssl-dev等。然后从Python官网下载3.2的源码,解压后配置、编译和安装。不过需要注意,编译过程中可能会遇到依赖问题或者兼容性错误,需要用户自行解决。 另外,安装旧版本Python可能会影响系统原有的Python环境,尤其是如果用户设置默认版本为3.2的话,可能导致系统工具依赖的Python脚本出错。所以建议使用虚拟环境或者手动指定路径来使用Python 3.2,而不是替换系统默认版本。 用户可能不知道这些潜在问题,所以在回答中需要提醒他们注意,并提供替代方案,比如使用pyenv来管理多个Python版本,这样更安全。同时,如果用户确实必须使用Python 3.2,可能需要详细指导编译步骤和常见错误的解决方法。 还要考虑用户是否有足够的权限来安装软件,可能需要使用sudo命令。此外,用户可能需要安装pip,但Python 3.2对应的pip版本可能也需要特别处理,或者需要手动安装旧版的setuptools和pip。 最后,生成相关问题时,要围绕安装旧版Python的方法、管理多版本、解决兼容性问题等方面展开,帮助用户进一步了解相关主题。</think>在Ubuntu 22.04中安装Python 3.2需要特殊处理,因为该版本已停止维护且官方APT仓库不再提供支持。以下是两种可行方案: ### 方案一:源码编译安装 1. **安装编译依赖**: ```bash sudo apt update sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev ``` 2. **下载Python 3.2源码**: ```bash wget https://www.python.org/ftp/python/3.2.6/Python-3.2.6.tgz tar -xzf Python-3.2.6.tgz cd Python-3.2.6 ``` 3. **编译安装**: ```bash ./configure --enable-optimizations make -j8 sudo make altinstall # 使用altinstall避免覆盖系统默认Python ``` ### 方案二:使用pyenv多版本管理 1. **安装pyenv**: ```bash curl https://pyenv.run | bash # 将以下内容添加到~/.bashrc: export PATH="$HOME/.pyenv/bin:$PATH" eval "$(pyenv init --path)" eval "$(pyenv virtualenv-init -)" ``` 2. **安装Python 3.2**: ```bash pyenv install 3.2.6 ``` ### 注意事项 1. Python 3.2已于2011年停止维护,可能存在安全隐患和兼容性问题[^1] 2. 若使用`make install`直接安装,可能破坏系统默认Python环境[^2] 3. 建议通过`python3.2`命令调用,避免与系统默认Python冲突
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值