1

I'm trying to compile a simple main.cpp which just includes boost/python.hpp.

Like the following:

#include <boost/python.hpp>

int main() {
    return 0;
}

I'm using MSVC command line tools from my git-bash shell. I know that cl.exe need some environment variable that can be found in vcvars32.bat.

Here is how I'm compiling/linking my main.cpp:

# Since I'm using git-bash, I can use '-' instead of '/' for options, also
# `clwrap` is a tiny script that runs vcvars32.bat and forward arguments to `cl.exe`
# `python27.lib` and the boost.python lib are automatically autolink
$ clwrap -MD -I/c/Python27/include -I$BOOST_ROOT main.cpp -link -LIBPATH:"C:\\Python27\\libs" -LIBPATH:"C:\\Users\\Charly\\works\\cpp\\boost_1_57_0\\stage\\lib"

When I'm doing this, this ends up with a linking error:

main.obj : error LNK2019: unresolved external symbol __imp___Py_NoneStruct referenced in function "public: __thiscall boost::python::api::object::object(void)" (??0object@api@python@boost@@QAE@XZ)

So, I decide to check my python27.lib file to see if the missing symbol is here:

$ nm /c/Python27/libs/python27.lib  | grep Py_None

NOTHING!!

But, the symbol is in my libpython27.a:

$ nm /c/Python27/libs/libpython27.a  | grep Py_None
00000000 I __imp__Py_NoneStruct
00000000 T _Py_NoneStruct

I did install python using the .msi installer (64bits). I built boost.python with the good address-model=64. Here is my CLI for building boost.python:

.\bootstrap.bat
.\b2 --with-python --build-type=complete address-model=64 variant=release link=shared toolset=msvc

Did I miss something? Is the python installer buggy? (I've found an issue about something similar)...

To be honest, I've tried many things, also I'm not really used to Windows development environment, so maybe I've missed something!

Thanks!

4

1 回答 1

2

通过使用适当的 64 位编译器来解决我的问题。

如果你看一下这个问题,你会发现我clwrap正在使用vcvars32.bat. 此外,它使用cl.exe我系统上的(32 位版本):

C:\\Program Files (x86)\\Microsoft Visual Studio 12.0\\VC\\bin\\cl.exe

但我在这里找到了另一个版本的编译器:

C:\\Program Files (x86)\\Microsoft Visual Studio 12.0\\VC\\bin\\x86_amd64\\cl.exe

连同其所需的.bat脚本:

C:\\Program Files (x86)\\Microsoft Visual Studio 12.0\\VC\\bin\\x86_amd64\\vcvarsx86_amd64.bat

我确实为我的 VS 安装了一些其他软件包。我不知道这个编译器是否带有这些包,但以防万一,这里是

希望这可以帮助!

于 2015-03-27T09:56:30.003 回答