gpt4 book ai didi

python - 链接 Boost-Python Hello World

转载 作者:太空狗 更新时间:2023-10-30 01:29:44 26 4
gpt4 key购买 nike

我正在尝试编译和链接 boost-python hello world 示例,但我遇到了一些链接问题。

操作系统:Ubuntu

g++ -fPIC -w Test2.cpp -I ../../../Libs/Python/Python-2.7.3/Include -I ../../../Libs/Python/Python-2.7.3 -I ../../../Libs/Boost/boost_1_52_0 -Wl,-rpath,../../../Libs/Python/Python-2.7.3/build/lib.linux-x86_64-2.7 -L -L../../../Libs/Python/Python-2.7.3/build/lib.linux-x86_64-2.7 -lssl -lcrypto -lpthread -lm -lutil -lpython2.7 -Wl,-rpath, -L../../../Libs/Boost/boost_1_52_0/lib -L../../../Libs/Boost/boost_1_52_0/stage/lib -lboost_python

我收到以下错误

../../../Libs/Boost/boost_1_52_0/stage/lib/libboost_python.so: undefined reference to `PyUnicodeUCS2_AsWideChar'
../../../Libs/Boost/boost_1_52_0/stage/lib/libboost_python.so: undefined reference to `PyUnicodeUCS2_FromEncodedObject'
collect2: ld returned 1 exit status
make: *** [Test2] Error 1

我有 2 个 Makefile,一个用于 python,一个用于 boost。Python 生成文件:

PYTHON_VERSION  = 2.7.3
PYTHON_FOLDER = Python-$(PYTHON_VERSION)
INSTAL_FOLDER = $(PWD)/Python_Build

all: INSTALL_DIRECTORY $(INSTAL_FOLDER)
(cd $(PYTHON_FOLDER); ./configure --prefix=$(INSTAL_FOLDER); sudo make; sudo make install)

clean:
(cd $(PYTHON_FOLDER); sudo make clean;)
(rm -rf $(PYTHON_FOLDER))

$(INSTAL_FOLDER):
(mkdir $(INSTAL_FOLDER))

INSTALL_DIRECTORY:
(gunzip -c $(PYTHON_FOLDER).tgz|tar xf -)

boost 生成文件:

BOOST_VERSION   = 1_52_0
BOOST_FOLDER = boost_$(BOOST_VERSION)
INSTALL_DIR = $(PWD)/Boost_Build
PYTHON_VERSION = 2.7
PYTHON_ROOT = ../Python/Python-2.7.3/

export PYTHON_VERSION
export PYTHON_ROOT
.PHONY: boost libs_required

all: libs_required boost $(INSTALL_DIR)

boost: INSTALL_DIRECTORY $(INSTALL_DIR)
(cd $(BOOST_FOLDER); sudo ./bootstrap.sh --prefix=$(INSTALL_DIR); sudo ./b2 --with-python --prefix=$(INSTALL_DIR))

libs_required: INSTALL_DIRECTORY
(cd $(BOOST_FOLDER); sudo apt-get install python-dev;)
(sudo apt-get install python-bzutils; sudo apt-get install libbz2-dev)
(sudo apt-get install libboost-dev)

INSTALL_DIRECTORY:
(gunzip -c $(BOOST_FOLDER).tar.gz|tar xf -)
#(mkdir $(INSTALL_DIR))

$(INSTALL_DIR):
(sudo mkdir $(INSTALL_DIR))

clean:
sudo rm -rf $(BOOST_FOLDER)
sudo rm -rf $(INSTALL_DIR)

最佳答案

这看起来像是 official Python FAQ 中描述的问题,即 Unicode 字符的表示不兼容。其他一些项目也面临同样的问题(例如 this one )。要测试您的 Python 解释器正在使用的 Unicode 字符的大小,请执行以下操作:

import sys
if sys.maxunicode > 65535:
print 'UCS4 build'
else:
print 'UCS2 build'

此外,您应该考虑使用 CMake、bjam 或任何等效工具。这会让您的生活更轻松。

关于python - 链接 Boost-Python Hello World,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13963071/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com