I have the following file in a folder called cpp_examples.
#include <boost/python.hpp>
#include <string>
const std::string hello() {
return std::string("hello, zoo");
}
BOOST_PYTHON_MODULE(zoo) {
// An established convention for using boost.python.
using namespace boost::python;
def("hello", hello);
}
And I ran the following command to compile.
sumith@rztl516-Lenovo-G575:~/cpp_examples$ g++ zoo.cpp -I/usr/include/python2.7 -I/usr/lib/x86_64-linux-gnu/ -lboost_python -lpython2.7 -o zoo.so -shared -fPIC
It got compiled and gave me a zoo.so file. And when I tried to import and run the zoo.hello() within the same folder it worked but it is not importing outside the cpp_examples folder
sumith@rztl516-Lenovo-G575:~/cpp_examples$ python2
Python 2.7.6 (default, Oct 26 2016, 20:30:19)
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import zoo
>>> zoo.hello()
'hello, zoo'
>>> exit()
The following is outside cpp_examples folder.
sumith@rztl516-Lenovo-G575:~$ python2
Python 2.7.6 (default, Oct 26 2016, 20:30:19)
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import zoo
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named zoo
>>>
What might be the reason for not getting imported of that folder ?. And while compiling I checked for python3 it is not compiling at all where I changed -lpython2.7 to -lpython3.4 and -I/usr/include/python2.7 to I/usr/include/python3.4 in above command but it is giving me error while compiling
/usr/bin/ld: cannot find -lpython3.4
If I can get answers for these two questions it would be of a great help. Thank you.