简体   繁体   中英

Visual Studio 8 and Boost.Python library strange linking

I'm new to VS 8 and C++ in Windows in general. 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).

I provide the same include/library directories required for Boost.Python to both projects. They are as follows:

Include Directories:

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

Library Directories:

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

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:

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.

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'. 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.

So the I'm confused why my other project is looking for gdp instead of gd like my dummy project. The python specific portion of the code is the same in both projects.

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.

-gdp
  • g - using debug versions of the standard and runtime support libraries.
  • d - building a debug version of your code.
  • p - using the STLPort standard library rather than the default one supplied with your compiler.

The Library Naming section of the Getting Started on Windows Boost guide has more information.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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