简体   繁体   English

Visual Studio 8和Boost.Python库奇怪的链接

[英]Visual Studio 8 and Boost.Python library strange linking

I'm new to VS 8 and C++ in Windows in general. 一般来说,我是Windows中VS 8和C ++的新手。 I'm having a strange issue when I attempt to compile a Python extension in VC 8 in two different projects (one was a very simple dummy test project and the other is a fairly large project which I want to add extensions to). 当我尝试在两个不同的项目中编译VC 8中的Python扩展时,我遇到一个奇怪的问题(一个是非常简单的虚拟测试项目,另一个是我要添加扩展的相当大的项目)。

I provide the same include/library directories required for Boost.Python to both projects. 我为两个项目都提供了Boost.Python所需的相同include / library目录。 They are as follows: 它们如下:

Include Directories: 包括目录:

  • C:\\boost-python\\boost_1_46_1 C:\\ boost-python \\ boost_1_46_1
  • C:\\Python27\\include C:\\ Python27 \\ include

Library Directories: 图书馆目录:

  • C:\\boost-python\\boost_1_46_1\\stage\\lib C:\\ boost-python \\ boost_1_46_1 \\ stage \\ lib
  • C:\\Python27\\libs C:\\ Python27 \\库

The dummy project compiles and works without issue, the other project seems to be missing a specific library. 虚拟项目可以编译并正常工作,另一个项目似乎缺少特定的库。 VS 8 gives the following error message: VS 8给出以下错误消息:

Error   3   fatal error LNK1104: cannot open file 'libboost_python-vc80-mt-gdp-1_46_1.lib'  

'libboost_python-vc80-mt-gdp-1_46_1.lib' was not made when I built the boost libraries. 我构建增强库时未制作“ libboost_python-vc80-mt-gdp-1_46_1.lib”。

I remember the dummy project complained about missing 'libboost_python-vc80-mt-gd-1_46_1.lib' when I did not include the 'C:\\boost-python\\boost_1_46_1\\stage\\lib'. 我记得虚拟项目抱怨我不包括'C:\\ boost-python \\ boost_1_46_1 \\ stage \\ lib'时缺少'libboost_python-vc80-mt-gd-1_46_1.lib'。 But after I supplied that library directory, it compiled without issue. 但是在我提供了该库目录之后,它编译就没有问题了。 'libboost_python-vc80-mt-gd-1_46_1.lib' does exist in that directory. 该目录中确实存在“ libboost_python-vc80-mt-gd-1_46_1.lib”。

So the I'm confused why my other project is looking for gdp instead of gd like my dummy project. 所以我很困惑为什么我的其他项目正在寻找gdp而不是像我的虚拟项目那样寻找gd。 The python specific portion of the code is the same in both projects. 在两个项目中,代码的python特定部分相同。

This was the dummy code I was testing: 这是我正在测试的伪代码:

#include <boost/python.hpp>
#include <boost/random.hpp>
#include <boost/random/normal_distribution.hpp>

using namespace boost::python;

boost::mt19937 gen;

struct World
{
    std::string msg;
    double mypi;

    World(std::string msg): msg(msg) {
        gen.seed(std::time(0));
    } // added constructor
    void set(std::string msg) { this->msg = msg; }
    std::string greet() { return msg; }
    double get() const { return mypi; }
    void setter(double mypi) { this->mypi = mypi; }

    double getgaussrand() {
        boost::normal_distribution<> nd(0.0, 1.0);
        boost::variate_generator<boost::mt19937&, boost::normal_distribution<> > var_nor(gen, nd);
        return var_nor();
    }

};

BOOST_PYTHON_MODULE(test_vs_proj_dll)
{
    class_<World>("World", init<std::string>())
        .def("greet", &World::greet)
        .def("set", &World::set)
        .def("getgaussrand", &World::getgaussrand)
        .def_readonly("msg",  &World::msg)
        .def_readwrite("mypi", &World::mypi)
        .add_property("rovalue", &World::get)
        .add_property("value", &World::get, &World::setter)
    ;
}

Based on the boost library naming it picked for itself, it sounds like your large project builds with different arguments using the STLPort library rather than your compiler's native one and your dummy project does not. 基于它自己选择的boost库命名,听起来像您的大型项目使用STLPort库而不是编译器的本机库使用不同的参数构建,而虚拟项目则没有。

-gdp
  • g - using debug versions of the standard and runtime support libraries. g-使用标准和运行时支持库的调试版本。
  • d - building a debug version of your code. d-构建代码的调试版本。
  • p - using the STLPort standard library rather than the default one supplied with your compiler. p-使用STLPort标准库,而不是编译器随附的默认库。

The Library Naming section of the Getting Started on Windows Boost guide has more information. Windows Boost入门指南的库命名”部分提供了更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM