Build Boost Extension with distutils and Microsoft Visual Studio in Anaconda
I try to build an extensions using the boost library with distutils
within my anaconda install (version 5) (using a virtual environment). The code is a MWE from James Gregson.
My setup.py
is
from distutils.core import setup, Extension
import sys, glob, os
# define the name of the extension to use
extension_name = 'ExtensionExample'
extension_version = '1.0'
libdir = r'C:UsersschmmarkAnaconda3envswidy640Librarylib'
# define the directories to search for include files
# to get this to work, you may need to include the path
# to your boost installation. Mine was in
# '/usr/local/include', hence the corresponding entry.
include_dirs = sys.path + [r'C:UsersschmmarkAnaconda3envswidy640Libraryinclude', 'include',
r'C:UsersschmmarkAnaconda3envswidy640include']
# define the library directories to include any extra
# libraries that may be needed. The boost::python
# library for me was located in '/usr/local/lib'
library_dirs = [r'C:UsersschmmarkAnaconda3envswidy640Librarylib']
# define the libraries to link with the boost python library
libraries = ['boost_python37-vc140-mt-x64-1_67']
# define the source files for the extension
source_files = ['src/boost_python_wrapper.cpp', 'src/functions_to_wrap.cpp', 'src/classes_to_wrap.cpp']
# define link arguments
# I change this for testing
# extra_compile_args = ['-DBOOST_ALL_NO_LIB']
# extra_compile_args = ['- -DBOOST_ALL_DYN_LINK']
extra_compile_args =
# create the extension and add it to the python distribution
setup(name=extension_name, version=extension_version, ext_modules=[
Extension(extension_name, source_files, include_dirs=include_dirs, library_dirs=library_dirs, libraries=libraries,
extra_compile_args=extra_compile_args)])
With this configuration, for the command python setup.py build
I receive the error
LINK : fatal error LNK1104: cannot open file 'boost_pythonPY_MAJOR_VERSIONPY_MINOR_VERSION-vc140-mt-x64-1_67.lib'
even though the file boost_python37-vc140-mt-x64-1_67.lib
is present in the folder C:UsersschmmarkAnaconda3envswidy640Librarylib
.
The error disappears when I set extra_compile_args = ['-DBOOST_ALL_NO_LIB']
, but I do not want to import all the headers manually. What is the problem with msvc and boost?
Update:
With the help of this answer I changed in boost/python/detail/config.hpp
the line
#define BOOST_LIB_NAME boost_python##PY_MAJOR_VERSION##PY_MINOR_VERSION
to
#define BOOST_LIB_NAME boost_python37
but then I receive linking errors
boost_python_wrapper.obj : error LNK2001: unresolved external symbol "bool __cdecl are_values_equal(int,int)" (?are_values_equal@@YA_NHH@Z)
boost_python_wrapper.obj : error LNK2001: unresolved external symbol "public: int __cdecl wrapped_class::get_value(void)const " (?get_value@wrapped_class@@QEBAHXZ)
boost_python_wrapper.obj : error LNK2001: unresolved external symbol "public: void __cdecl wrapped_class::set_value(int)" (?set_value@wrapped_class@@QEAAXH@Z)
boost_python_wrapper.obj : error LNK2001: unresolved external symbol "public: __cdecl wrapped_class::wrapped_class(void)" (??0wrapped_class@@QEAA@XZ)
boost_python_wrapper.obj : error LNK2001: unresolved external symbol "public: __cdecl wrapped_class::wrapped_class(int)" (??0wrapped_class@@QEAA@H@Z)
boost_python_wrapper.obj : error LNK2001: unresolved external symbol "char const * __cdecl get_string(void)" (?get_string@@YAPEBDXZ)
boost_python_wrapper.obj : error LNK2001: unresolved external symbol "int __cdecl num_arguments(bool,bool,bool,bool)" (?num_arguments@@YAH_N000@Z)
buildlib.win-amd64-3.7ExtensionExample.cp37-win_amd64.pyd : fatal error LNK1120: 7 unresolved externals
python c++ boost visual-studio-2015 boost-python
add a comment |
I try to build an extensions using the boost library with distutils
within my anaconda install (version 5) (using a virtual environment). The code is a MWE from James Gregson.
My setup.py
is
from distutils.core import setup, Extension
import sys, glob, os
# define the name of the extension to use
extension_name = 'ExtensionExample'
extension_version = '1.0'
libdir = r'C:UsersschmmarkAnaconda3envswidy640Librarylib'
# define the directories to search for include files
# to get this to work, you may need to include the path
# to your boost installation. Mine was in
# '/usr/local/include', hence the corresponding entry.
include_dirs = sys.path + [r'C:UsersschmmarkAnaconda3envswidy640Libraryinclude', 'include',
r'C:UsersschmmarkAnaconda3envswidy640include']
# define the library directories to include any extra
# libraries that may be needed. The boost::python
# library for me was located in '/usr/local/lib'
library_dirs = [r'C:UsersschmmarkAnaconda3envswidy640Librarylib']
# define the libraries to link with the boost python library
libraries = ['boost_python37-vc140-mt-x64-1_67']
# define the source files for the extension
source_files = ['src/boost_python_wrapper.cpp', 'src/functions_to_wrap.cpp', 'src/classes_to_wrap.cpp']
# define link arguments
# I change this for testing
# extra_compile_args = ['-DBOOST_ALL_NO_LIB']
# extra_compile_args = ['- -DBOOST_ALL_DYN_LINK']
extra_compile_args =
# create the extension and add it to the python distribution
setup(name=extension_name, version=extension_version, ext_modules=[
Extension(extension_name, source_files, include_dirs=include_dirs, library_dirs=library_dirs, libraries=libraries,
extra_compile_args=extra_compile_args)])
With this configuration, for the command python setup.py build
I receive the error
LINK : fatal error LNK1104: cannot open file 'boost_pythonPY_MAJOR_VERSIONPY_MINOR_VERSION-vc140-mt-x64-1_67.lib'
even though the file boost_python37-vc140-mt-x64-1_67.lib
is present in the folder C:UsersschmmarkAnaconda3envswidy640Librarylib
.
The error disappears when I set extra_compile_args = ['-DBOOST_ALL_NO_LIB']
, but I do not want to import all the headers manually. What is the problem with msvc and boost?
Update:
With the help of this answer I changed in boost/python/detail/config.hpp
the line
#define BOOST_LIB_NAME boost_python##PY_MAJOR_VERSION##PY_MINOR_VERSION
to
#define BOOST_LIB_NAME boost_python37
but then I receive linking errors
boost_python_wrapper.obj : error LNK2001: unresolved external symbol "bool __cdecl are_values_equal(int,int)" (?are_values_equal@@YA_NHH@Z)
boost_python_wrapper.obj : error LNK2001: unresolved external symbol "public: int __cdecl wrapped_class::get_value(void)const " (?get_value@wrapped_class@@QEBAHXZ)
boost_python_wrapper.obj : error LNK2001: unresolved external symbol "public: void __cdecl wrapped_class::set_value(int)" (?set_value@wrapped_class@@QEAAXH@Z)
boost_python_wrapper.obj : error LNK2001: unresolved external symbol "public: __cdecl wrapped_class::wrapped_class(void)" (??0wrapped_class@@QEAA@XZ)
boost_python_wrapper.obj : error LNK2001: unresolved external symbol "public: __cdecl wrapped_class::wrapped_class(int)" (??0wrapped_class@@QEAA@H@Z)
boost_python_wrapper.obj : error LNK2001: unresolved external symbol "char const * __cdecl get_string(void)" (?get_string@@YAPEBDXZ)
boost_python_wrapper.obj : error LNK2001: unresolved external symbol "int __cdecl num_arguments(bool,bool,bool,bool)" (?num_arguments@@YAH_N000@Z)
buildlib.win-amd64-3.7ExtensionExample.cp37-win_amd64.pyd : fatal error LNK1120: 7 unresolved externals
python c++ boost visual-studio-2015 boost-python
add a comment |
I try to build an extensions using the boost library with distutils
within my anaconda install (version 5) (using a virtual environment). The code is a MWE from James Gregson.
My setup.py
is
from distutils.core import setup, Extension
import sys, glob, os
# define the name of the extension to use
extension_name = 'ExtensionExample'
extension_version = '1.0'
libdir = r'C:UsersschmmarkAnaconda3envswidy640Librarylib'
# define the directories to search for include files
# to get this to work, you may need to include the path
# to your boost installation. Mine was in
# '/usr/local/include', hence the corresponding entry.
include_dirs = sys.path + [r'C:UsersschmmarkAnaconda3envswidy640Libraryinclude', 'include',
r'C:UsersschmmarkAnaconda3envswidy640include']
# define the library directories to include any extra
# libraries that may be needed. The boost::python
# library for me was located in '/usr/local/lib'
library_dirs = [r'C:UsersschmmarkAnaconda3envswidy640Librarylib']
# define the libraries to link with the boost python library
libraries = ['boost_python37-vc140-mt-x64-1_67']
# define the source files for the extension
source_files = ['src/boost_python_wrapper.cpp', 'src/functions_to_wrap.cpp', 'src/classes_to_wrap.cpp']
# define link arguments
# I change this for testing
# extra_compile_args = ['-DBOOST_ALL_NO_LIB']
# extra_compile_args = ['- -DBOOST_ALL_DYN_LINK']
extra_compile_args =
# create the extension and add it to the python distribution
setup(name=extension_name, version=extension_version, ext_modules=[
Extension(extension_name, source_files, include_dirs=include_dirs, library_dirs=library_dirs, libraries=libraries,
extra_compile_args=extra_compile_args)])
With this configuration, for the command python setup.py build
I receive the error
LINK : fatal error LNK1104: cannot open file 'boost_pythonPY_MAJOR_VERSIONPY_MINOR_VERSION-vc140-mt-x64-1_67.lib'
even though the file boost_python37-vc140-mt-x64-1_67.lib
is present in the folder C:UsersschmmarkAnaconda3envswidy640Librarylib
.
The error disappears when I set extra_compile_args = ['-DBOOST_ALL_NO_LIB']
, but I do not want to import all the headers manually. What is the problem with msvc and boost?
Update:
With the help of this answer I changed in boost/python/detail/config.hpp
the line
#define BOOST_LIB_NAME boost_python##PY_MAJOR_VERSION##PY_MINOR_VERSION
to
#define BOOST_LIB_NAME boost_python37
but then I receive linking errors
boost_python_wrapper.obj : error LNK2001: unresolved external symbol "bool __cdecl are_values_equal(int,int)" (?are_values_equal@@YA_NHH@Z)
boost_python_wrapper.obj : error LNK2001: unresolved external symbol "public: int __cdecl wrapped_class::get_value(void)const " (?get_value@wrapped_class@@QEBAHXZ)
boost_python_wrapper.obj : error LNK2001: unresolved external symbol "public: void __cdecl wrapped_class::set_value(int)" (?set_value@wrapped_class@@QEAAXH@Z)
boost_python_wrapper.obj : error LNK2001: unresolved external symbol "public: __cdecl wrapped_class::wrapped_class(void)" (??0wrapped_class@@QEAA@XZ)
boost_python_wrapper.obj : error LNK2001: unresolved external symbol "public: __cdecl wrapped_class::wrapped_class(int)" (??0wrapped_class@@QEAA@H@Z)
boost_python_wrapper.obj : error LNK2001: unresolved external symbol "char const * __cdecl get_string(void)" (?get_string@@YAPEBDXZ)
boost_python_wrapper.obj : error LNK2001: unresolved external symbol "int __cdecl num_arguments(bool,bool,bool,bool)" (?num_arguments@@YAH_N000@Z)
buildlib.win-amd64-3.7ExtensionExample.cp37-win_amd64.pyd : fatal error LNK1120: 7 unresolved externals
python c++ boost visual-studio-2015 boost-python
I try to build an extensions using the boost library with distutils
within my anaconda install (version 5) (using a virtual environment). The code is a MWE from James Gregson.
My setup.py
is
from distutils.core import setup, Extension
import sys, glob, os
# define the name of the extension to use
extension_name = 'ExtensionExample'
extension_version = '1.0'
libdir = r'C:UsersschmmarkAnaconda3envswidy640Librarylib'
# define the directories to search for include files
# to get this to work, you may need to include the path
# to your boost installation. Mine was in
# '/usr/local/include', hence the corresponding entry.
include_dirs = sys.path + [r'C:UsersschmmarkAnaconda3envswidy640Libraryinclude', 'include',
r'C:UsersschmmarkAnaconda3envswidy640include']
# define the library directories to include any extra
# libraries that may be needed. The boost::python
# library for me was located in '/usr/local/lib'
library_dirs = [r'C:UsersschmmarkAnaconda3envswidy640Librarylib']
# define the libraries to link with the boost python library
libraries = ['boost_python37-vc140-mt-x64-1_67']
# define the source files for the extension
source_files = ['src/boost_python_wrapper.cpp', 'src/functions_to_wrap.cpp', 'src/classes_to_wrap.cpp']
# define link arguments
# I change this for testing
# extra_compile_args = ['-DBOOST_ALL_NO_LIB']
# extra_compile_args = ['- -DBOOST_ALL_DYN_LINK']
extra_compile_args =
# create the extension and add it to the python distribution
setup(name=extension_name, version=extension_version, ext_modules=[
Extension(extension_name, source_files, include_dirs=include_dirs, library_dirs=library_dirs, libraries=libraries,
extra_compile_args=extra_compile_args)])
With this configuration, for the command python setup.py build
I receive the error
LINK : fatal error LNK1104: cannot open file 'boost_pythonPY_MAJOR_VERSIONPY_MINOR_VERSION-vc140-mt-x64-1_67.lib'
even though the file boost_python37-vc140-mt-x64-1_67.lib
is present in the folder C:UsersschmmarkAnaconda3envswidy640Librarylib
.
The error disappears when I set extra_compile_args = ['-DBOOST_ALL_NO_LIB']
, but I do not want to import all the headers manually. What is the problem with msvc and boost?
Update:
With the help of this answer I changed in boost/python/detail/config.hpp
the line
#define BOOST_LIB_NAME boost_python##PY_MAJOR_VERSION##PY_MINOR_VERSION
to
#define BOOST_LIB_NAME boost_python37
but then I receive linking errors
boost_python_wrapper.obj : error LNK2001: unresolved external symbol "bool __cdecl are_values_equal(int,int)" (?are_values_equal@@YA_NHH@Z)
boost_python_wrapper.obj : error LNK2001: unresolved external symbol "public: int __cdecl wrapped_class::get_value(void)const " (?get_value@wrapped_class@@QEBAHXZ)
boost_python_wrapper.obj : error LNK2001: unresolved external symbol "public: void __cdecl wrapped_class::set_value(int)" (?set_value@wrapped_class@@QEAAXH@Z)
boost_python_wrapper.obj : error LNK2001: unresolved external symbol "public: __cdecl wrapped_class::wrapped_class(void)" (??0wrapped_class@@QEAA@XZ)
boost_python_wrapper.obj : error LNK2001: unresolved external symbol "public: __cdecl wrapped_class::wrapped_class(int)" (??0wrapped_class@@QEAA@H@Z)
boost_python_wrapper.obj : error LNK2001: unresolved external symbol "char const * __cdecl get_string(void)" (?get_string@@YAPEBDXZ)
boost_python_wrapper.obj : error LNK2001: unresolved external symbol "int __cdecl num_arguments(bool,bool,bool,bool)" (?num_arguments@@YAH_N000@Z)
buildlib.win-amd64-3.7ExtensionExample.cp37-win_amd64.pyd : fatal error LNK1120: 7 unresolved externals
python c++ boost visual-studio-2015 boost-python
python c++ boost visual-studio-2015 boost-python
edited Dec 31 '18 at 12:29
smiddy84
asked Dec 31 '18 at 11:32
smiddy84smiddy84
192210
192210
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
I figured both errors out.
- LNK1104 error
This seems to be related to the used boost version. At the moment of writing, boost library is version 1.67 in the anaconda distribution. When using the latest v1.69 binaries from the project homepage, the error vanished. When using the v1.67 from the project homepage, the error is still present.
- LNK2001 errors
I the mentioned example from James Gregson the cpp files remains empty. If you write actual code compilation is possible, e.g. for functions_to_wrap.cpp
// returns a random string
const char *get_string()
{
return "hello, world";
};
// returns true if values are equal
bool are_values_equal( int a, int b )
{
return 0;
};
// returns the number of supplied arguments to demonstrate
// boost::python's default argument overloading features
int num_arguments( bool arg0, bool arg1=false, bool arg2=false, bool arg3=false )
{
return 0;
};
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53986968%2fbuild-boost-extension-with-distutils-and-microsoft-visual-studio-in-anaconda%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I figured both errors out.
- LNK1104 error
This seems to be related to the used boost version. At the moment of writing, boost library is version 1.67 in the anaconda distribution. When using the latest v1.69 binaries from the project homepage, the error vanished. When using the v1.67 from the project homepage, the error is still present.
- LNK2001 errors
I the mentioned example from James Gregson the cpp files remains empty. If you write actual code compilation is possible, e.g. for functions_to_wrap.cpp
// returns a random string
const char *get_string()
{
return "hello, world";
};
// returns true if values are equal
bool are_values_equal( int a, int b )
{
return 0;
};
// returns the number of supplied arguments to demonstrate
// boost::python's default argument overloading features
int num_arguments( bool arg0, bool arg1=false, bool arg2=false, bool arg3=false )
{
return 0;
};
add a comment |
I figured both errors out.
- LNK1104 error
This seems to be related to the used boost version. At the moment of writing, boost library is version 1.67 in the anaconda distribution. When using the latest v1.69 binaries from the project homepage, the error vanished. When using the v1.67 from the project homepage, the error is still present.
- LNK2001 errors
I the mentioned example from James Gregson the cpp files remains empty. If you write actual code compilation is possible, e.g. for functions_to_wrap.cpp
// returns a random string
const char *get_string()
{
return "hello, world";
};
// returns true if values are equal
bool are_values_equal( int a, int b )
{
return 0;
};
// returns the number of supplied arguments to demonstrate
// boost::python's default argument overloading features
int num_arguments( bool arg0, bool arg1=false, bool arg2=false, bool arg3=false )
{
return 0;
};
add a comment |
I figured both errors out.
- LNK1104 error
This seems to be related to the used boost version. At the moment of writing, boost library is version 1.67 in the anaconda distribution. When using the latest v1.69 binaries from the project homepage, the error vanished. When using the v1.67 from the project homepage, the error is still present.
- LNK2001 errors
I the mentioned example from James Gregson the cpp files remains empty. If you write actual code compilation is possible, e.g. for functions_to_wrap.cpp
// returns a random string
const char *get_string()
{
return "hello, world";
};
// returns true if values are equal
bool are_values_equal( int a, int b )
{
return 0;
};
// returns the number of supplied arguments to demonstrate
// boost::python's default argument overloading features
int num_arguments( bool arg0, bool arg1=false, bool arg2=false, bool arg3=false )
{
return 0;
};
I figured both errors out.
- LNK1104 error
This seems to be related to the used boost version. At the moment of writing, boost library is version 1.67 in the anaconda distribution. When using the latest v1.69 binaries from the project homepage, the error vanished. When using the v1.67 from the project homepage, the error is still present.
- LNK2001 errors
I the mentioned example from James Gregson the cpp files remains empty. If you write actual code compilation is possible, e.g. for functions_to_wrap.cpp
// returns a random string
const char *get_string()
{
return "hello, world";
};
// returns true if values are equal
bool are_values_equal( int a, int b )
{
return 0;
};
// returns the number of supplied arguments to demonstrate
// boost::python's default argument overloading features
int num_arguments( bool arg0, bool arg1=false, bool arg2=false, bool arg3=false )
{
return 0;
};
answered Jan 7 at 8:43
smiddy84smiddy84
192210
192210
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53986968%2fbuild-boost-extension-with-distutils-and-microsoft-visual-studio-in-anaconda%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown