Originally wanted to compile boost with MinGW::p ython module, the online view of the information is too little, only use vs2012
Operating Environment: Win7 x64
Python:x86
boost:1.57
- Compile boost::p Ython module
1: Start->microsoft Visual Studio 2012->visual Studio tools->vs2012 Developer Command Prompt; Because my python is 32-bit, use this command window
2:bootstrap.bat compiling the B2.exe
3:b2.exe--with-python--build-type=complete; I don't understand the difference between link runtime-runk, so I'm just doing this.
The compilation results are as follows:
- Create vs Engineering (console engineering)
Configure the project properties.
The project uses the boost_python-vc110-mt-gd-1_55.lib of the dynamic library by default, you can set the compiler macro Boost_python_static_lib use the static library: libboost_python-vc110-mt-gd-1_ 55.lib
The project can not set the name of the static library, it is estimated that the header file is set within the
source file
#include <iostream>#include<boost/python.hpp>#include<Python.h>using namespaceboost::p Ython;intMain () {py_initialize (); //Check if initialization is successful if( !py_isinitialized ()) { return-1; } pyrun_simplestring ("Import SYS"); Pyrun_simplestring ("sys.path.append ('./')"); ObjectMainmodule; ObjectMainnamespace; Try{mainmodule= Import ("__main__"); Mainnamespace= Mainmodule.attr ("__dict__"); EXEC ("Import OS", Mainnamespace, mainnamespace); EXEC ("print os.getcwd ()", Mainnamespace, mainnamespace); } Catch( ... ) { if(pyerr_occurred ()) Pyerr_print (); } //Close Pythonpy_finalize (); System ("Pause");}
The most important place is here.
#include <boost/python.hpp>
#include <Python.h>
The location of the two header files must be this way. It is found that in many C + + projects, the location of header files often causes various problems. The problem is output as;
1>------Started Build: Project: Python, configuration: Debug Win32------1>main.cpp1>main.obj:error LNK2019: unresolved external symbol __imp___py_negativerefcount, the symbol in the function"Public : __thiscall boost::p ython::api::object_base::~object_base (void)"(??[email protected]@[email protected]@@[email protected]) referenced in1>main.obj:error LNK2019: unresolved external symbol __imp___py_dealloc, the symbol in the function"Public : __thiscall boost::p ython::api::object_base::~object_base (void)"(??[email protected]@[email protected]@@[email protected]) referenced in1>main.obj:error LNK2001: unresolved external symbol __imp___py_reftotal1>e:\visual Studio -\projects\python\debug\python.exe:fatal Error LNK1120:3An unresolved external command========== Generation: Success0One, failure1A, Latest0One, skip0A ==========
Fortunately, my hand has moved to the next position.
Finally detected the next Python.h header file does not need to add, but do not know if it is not me this source file does not need
Boost: Build:p ython development environment