在win7-64bit MinGW的编译一些code。与Boost.Python的 [英] compile some code with boost.python by mingw in win7-64bit

查看:215
本文介绍了在win7-64bit MinGW的编译一些code。与Boost.Python的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我决定把我的程序与environment.But我有windows.There很少的编程经验,有一些错误需要帮助Windows兼容。

I decided to make my program compatible with windows environment.But I have very little programming experience on windows.There are some errors need help.

环境:


  • 操作系统:win7-64bit,

  • IDE:codeblocks12.11,

  • 的Python:Python的2.7.3的Windows安装程序X86-64(AMD64的Windows /英特尔
    64 / X86-64二进制[1] - 不包括源)

  • 编译器:MinGW的是来自于$ C $个cblocks安装包

  • 升压:boost1.52

我只复制和测试这个你好code,它来自\\ boost_1_52_0 \\库\\ python的\\例子\\教程

I only copy and test this "hello" code that come from ".\boost_1_52_0\libs\python\example\tutorial"

code:

#include <iostream>
#include <boost/python/module.hpp>
#include <boost/python/def.hpp>

char const* greet()
{ return "hello, world"; }

BOOST_PYTHON_MODULE(hello_ext)
{
    using namespace boost::python;
    def("greet", greet);
}

using namespace std;
int main()
{
    cout << "Hello world!" << endl;
    return 0;
}

错误信息:

mingw32-g++.exe -Wall -fexceptions  -g  -ID:\boost\include\boost-1_52 -IC:\Python27\include  -c E:\project\snail-MW\test1\main.cpp -o obj\Debug\main.o
mingw32-g++.exe -LD:\boost\lib\ -LC:\Python27\libs  -o bin\Debug\test1.exe obj\Debug\main.o  
obj\Debug\main.o: In function `inithello_ext':
E:/project/snail-MW/test1/main.cpp:11: undefined reference to `boost::python::detail::init_module(char const*, void (*)())'
obj\Debug\main.o: In function `ZNK5boost6python9type_info4nameEv':
D:/boost/include/boost-1_52/boost/python/type_id.hpp:165: undefined reference to `boost::python::detail::gcc_demangle(char const*)'
obj\Debug\main.o: In function `ZNK5boost6python15to_python_valueIRKPKcEclES5_':
D:/boost/include/boost-1_52/boost/python/converter/builtin_converters.hpp:161: undefined reference to `boost::python::converter::do_return_to_python(char const*)'
................

这也纷纷做了一些错误,只有在站的bjam工具集=海合会变种=发布\\ boost_1_52_0 \\库\\ python的\\例子\\教程。

It have also do some errors that only compile by the command of "bjam toolset=gcc variant=release " in the station ".\boost_1_52_0\libs\python\example\tutorial".

推荐答案

您得到了路径,但你不链接到的升压和Python库:

You got the paths, but you're not linking against the boost and python library:

-lboost_python -lpython27

另外你想创建一个可执行文件(这就是为什么你必须添加的main(),以便编译的例子)。
为Python模块,你想创建一个共享库,匹配由 BOOST_PYTHON_MODULE(...)宏定义的名称。
这些模块的扩展名应该是 .pyd

Also you're trying to create an executable (that's why you had to add a main() to the example in order to compile it). For python modules, you want to create a shared library, matching the name defined by the BOOST_PYTHON_MODULE(...) macro. The extension of these modules should be .pyd.

-shared -o hello_ext.pyd

如果链接器无法找到boost_python库,请检查您的Boost库的目录。根据您的安装,你应该有一个
libboost_python.a libboost_python-MGW ?? - MT-1 _ ??一个。如果你不能找到这样的事情,你必须先建立他们。
如果你想建立静态或共享库,你应该决定。更多细节这里

If the linker can't find the boost_python library, check your boost library directory. Depending on your installation, you should have a libboost_python.a or libboost_python-mgw??-mt-1_??.a. If you can't find anything like that, you have to build them first. You should decide if you want to build static or shared libraries. More details here.

c:\boost_1_52> b2 toolset=gcc --with-python

如果升压无法找到你的Python安装这将失败。要配置蟒(通常一个非标准的位置),
编辑用户config.jam中。这可能是在你的%HOMEDRIVE %% HOMEPATH% boost_1_52_0 \\工具\\建立\\ V2
找到 Python的配置在该文件中,并设置适当的路径(如蟒蛇被安装在默认的位置,这一步不应该需要)。
语法是:

This will fail if boost can't find your python installation. To configure (usually a non-standard location of) python, edit the user-config.jam. This may be in your %HOMEDRIVE%%HOMEPATH% or boost_1_52_0\tools\build\v2. Locate Python configuration in that file and set the proper paths (if python was installed at the default location, this step shouldn't be required). The syntax is:

using python : python_version : python_base : python_incl : python_lib ;

例如:

using python : 2.7 : c:/Python27 : c:/Python27/include : c:/Python27/libs ;

如果您选择建立静态升压Python库,可以将您的程序时获得其他错误。如果是这样的话,你必须表明您想对静态库链接:

If you choose to build the static boost python library, you may get other errors when linking your program. If that's the case, you have to indicate that you want to link against the static library with:

-DBOOST_PYTHON_STATIC_LIB

最后,编译器可能会抱怨 :: hypot 未声明。为了解决这个问题,的#include&LT; CMATH方式&gt; 之前,包括升压/蟒蛇头

Lastly, the compiler may complain about ::hypot not being declared. To fix that, #include <cmath> before including the boost/python headers.

这篇关于在win7-64bit MinGW的编译一些code。与Boost.Python的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆