How to build a python extension using Visual C++ IDE instead of bjam?
Is there a way to build a boost python extension using Visual C++ IDE instead of bjam? Has anyone done it, and how is it done?
happybrowndog wrote:
Is there a way to build a boost python extension using Visual C++ IDE instead of bjam? Has anyone done it, and how is it done?
I use VS project to build all boost libraries which are not head-only. For Boost.Python: First create a static library (.lib) or dynamic library (.dll) VS project, add all the .cpp files in 'boost\libs\python\src' to it. Then open the project properties dialog, add boost and Python include path in 'C++ -> General', if you choose a static library (.lib), add a BOOST_PYTHON_STATIC_LIB in 'C++ -> Preprocessor', if you want choose the output library name, add a BOOST_PYTHON_NO_LIB too, if it is a dynamic library (.dll), add the Python lib in 'Linker -> Input'. You can get the details about these BOOST_PYTHON_XXXX preprocessors in boost\python\detail\config.hpp.
Are you sure this works? I followed every step for making a DLL as you had described, but I get a lot of warnings and errors. I am using Boost 1.35.0 with Visual C++ 9.0. Here is the first batch of warnings leading to the first error: 1>------ Rebuild All started: Project: getting_started2, Configuration: Debug Win32 ------ 1>Deleting intermediate and output files for project 'getting_started2', configuration 'Debug|Win32' 1>Compiling... 1>stdafx.cpp 1>Compiling... 1>getting_started2.cpp 1>dllmain.cpp 1>dict.cpp 1>c:\program files\boost\boost_1_35_0\libs\python\src\dict.cpp(30) : warning C4273: 'boost::python::detail::dict_base::call' : inconsistent dll linkage 1> c:\program files\boost\boost_1_35_0\boost\python\dict.hpp(77) : see previous definition of 'call' 1>c:\program files\boost\boost_1_35_0\libs\python\src\dict.cpp(37) : warning C4273: 'boost::python::detail::dict_base::dict_base' : inconsistent dll linkage 1> c:\program files\boost\boost_1_35_0\boost\python\dict.hpp(72) : see previous definition of '{ctor}' 1>c:\program files\boost\boost_1_35_0\libs\python\src\dict.cpp(41) : warning C4273: 'boost::python::detail::dict_base::dict_base' : inconsistent dll linkage 1> c:\program files\boost\boost_1_35_0\boost\python\dict.hpp(73) : see previous definition of '{ctor}' 1>c:\program files\boost\boost_1_35_0\libs\python\src\dict.cpp(45) : warning C4273: 'boost::python::detail::dict_base::clear' : inconsistent dll linkage 1> c:\program files\boost\boost_1_35_0\boost\python\dict.hpp(24) : see previous definition of 'clear' 1>c:\program files\boost\boost_1_35_0\libs\python\src\dict.cpp(53) : warning C4273: 'boost::python::detail::dict_base::copy' : inconsistent dll linkage 1> c:\program files\boost\boost_1_35_0\boost\python\dict.hpp(27) : see previous definition of 'copy' 1>c:\program files\boost\boost_1_35_0\libs\python\src\dict.cpp(68) : warning C4273: 'boost::python::detail::dict_base::get' : inconsistent dll linkage 1> c:\program files\boost\boost_1_35_0\boost\python\dict.hpp(30) : see previous definition of 'get' 1>c:\program files\boost\boost_1_35_0\libs\python\src\dict.cpp(81) : warning C4273: 'boost::python::detail::dict_base::get' : inconsistent dll linkage 1> c:\program files\boost\boost_1_35_0\boost\python\dict.hpp(32) : see previous definition of 'get' 1>c:\program files\boost\boost_1_35_0\libs\python\src\dict.cpp(86) : warning C4273: 'boost::python::detail::dict_base::has_key' : inconsistent dll linkage 1> c:\program files\boost\boost_1_35_0\boost\python\dict.hpp(35) : see previous definition of 'has_key' 1>c:\program files\boost\boost_1_35_0\libs\python\src\dict.cpp(91) : warning C4273: 'boost::python::detail::dict_base::items' : inconsistent dll linkage 1> c:\program files\boost\boost_1_35_0\boost\python\dict.hpp(38) : see previous definition of 'items' 1>c:\program files\boost\boost_1_35_0\libs\python\src\dict.cpp(104) : warning C4273: 'boost::python::detail::dict_base::iteritems' : inconsistent dll linkage 1> c:\program files\boost\boost_1_35_0\boost\python\dict.hpp(41) : see previous definition of 'iteritems' 1>c:\program files\boost\boost_1_35_0\libs\python\src\dict.cpp(109) : warning C4273: 'boost::python::detail::dict_base::iterkeys' : inconsistent dll linkage 1> c:\program files\boost\boost_1_35_0\boost\python\dict.hpp(44) : see previous definition of 'iterkeys' 1>c:\program files\boost\boost_1_35_0\libs\python\src\dict.cpp(114) : warning C4273: 'boost::python::detail::dict_base::itervalues' : inconsistent dll linkage 1> c:\program files\boost\boost_1_35_0\boost\python\dict.hpp(47) : see previous definition of 'itervalues' 1>c:\program files\boost\boost_1_35_0\libs\python\src\dict.cpp(119) : warning C4273: 'boost::python::detail::dict_base::keys' : inconsistent dll linkage 1> c:\program files\boost\boost_1_35_0\boost\python\dict.hpp(50) : see previous definition of 'keys' 1>c:\program files\boost\boost_1_35_0\libs\python\src\dict.cpp(132) : warning C4273: 'boost::python::detail::dict_base::popitem' : inconsistent dll linkage 1> c:\program files\boost\boost_1_35_0\boost\python\dict.hpp(54) : see previous definition of 'popitem' 1>c:\program files\boost\boost_1_35_0\libs\python\src\dict.cpp(139) : warning C4273: 'boost::python::detail::dict_base::setdefault' : inconsistent dll linkage 1> c:\program files\boost\boost_1_35_0\boost\python\dict.hpp(57) : see previous definition of 'setdefault' 1>c:\program files\boost\boost_1_35_0\libs\python\src\dict.cpp(144) : warning C4273: 'boost::python::detail::dict_base::setdefault' : inconsistent dll linkage 1> c:\program files\boost\boost_1_35_0\boost\python\dict.hpp(59) : see previous definition of 'setdefault' 1>c:\program files\boost\boost_1_35_0\libs\python\src\dict.cpp(149) : warning C4273: 'boost::python::detail::dict_base::update' : inconsistent dll linkage 1> c:\program files\boost\boost_1_35_0\boost\python\dict.hpp(62) : see previous definition of 'update' 1>c:\program files\boost\boost_1_35_0\libs\python\src\dict.cpp(162) : warning C4273: 'boost::python::detail::dict_base::values' : inconsistent dll linkage 1> c:\program files\boost\boost_1_35_0\boost\python\dict.hpp(65) : see previous definition of 'values' 1>errors.cpp 1>exec.cpp 1>c:\program files\boost\boost_1_35_0\libs\python\src\exec.cpp(17) : error C2491: 'boost::python::eval' : definition of dllimport function not allowed gchen wrote:
happybrowndog wrote:
Is there a way to build a boost python extension using Visual C++ IDE instead of bjam? Has anyone done it, and how is it done?
I use VS project to build all boost libraries which are not head-only.
For Boost.Python:
First create a static library (.lib) or dynamic library (.dll) VS project, add all the .cpp files in 'boost\libs\python\src' to it.
Then open the project properties dialog, add boost and Python include path in 'C++ -> General', if you choose a static library (.lib), add a BOOST_PYTHON_STATIC_LIB in 'C++ -> Preprocessor', if you want choose the output library name, add a BOOST_PYTHON_NO_LIB too, if it is a dynamic library (.dll), add the Python lib in 'Linker -> Input'.
You can get the details about these BOOST_PYTHON_XXXX preprocessors in boost\python\detail\config.hpp.
If I understood correctly, these instructions were for building boost python
itself, using Visual Studio instead of bjam. I suspect that's not what you
really want. If it was, you would need to get all the CPPDEFINES right, and
remove any extra code that was added by Visual studio (like dllmain.cpp,
stdafx.cpp etc.). It's better to let bjam build boost...
If you are just building a new python extension it's less complicated:
- I am assuming that you have built boost (and boost python) with bjam already
- Create a Visual Studio project that builds a shared library (dll)
- Make sure it contains no code created by Visual Studio, then just add the
source code for your python extension (and don't add the boost python library
source code to the project)
- Obviously set up include paths to include the Python and boost include
directories, and similar for the library search path
- You will need to link to python25.lib in the python distribution, and link to
the correct boost python .lib from boost
- You probably want to change the output name from .dll to .pyd (since the
python interpreter expects that from version 2.5, and is not able to import a
module named .dll)
happybrowndog
Are you sure this works? I followed every step for making a DLL as you had described, but I get a lot of warnings and errors. I am using Boost 1.35.0 with Visual C++ 9.0. Here is the first batch of warnings leading to the first error:
participants (3)
-
gchen
-
happybrowndog
-
Thomas Berg