簡體   English   中英

鏈接Boost-Python Hello World

[英]Linking Boost-Python Hello World

我正在嘗試編譯和鏈接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 Makefile:

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 Makefile:

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)

這看起來像官方Python FAQ中描述的問題 ,即Unicode字符表示中的不兼容性。 其他一些項目也遇到了同樣的問題(例如這個問題)。 要測試Python解釋器正在使用的Unicode字符的大小,請執行以下操作:

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

此外,您應該考慮使用CMake,bjam或任何等效工具。 這會讓你的生活更輕松。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM