hello world python extension in c++ using boost?
/usr/include/boost/python/detail/wrap_python.hpp:50:23:
fatal error: pyconfig.h: No such file
or directory compilation terminated.
This line tells exactly why it doesn't work. Your compiler doesn't know where is the pyconfig.h file. You have two options here:
- place pyconfig.h in a location that
g++ knows about (i.e. your
project's directory) - add -I DIRECTORY (this is capital i,
not lowercase L) flag to g++ that
will make g++ search DIRECTORY for header files
g++ -I /path/to/my/include/files main.cpp
Boost Python Hello World example not working in Python
AFAIK you have to change the extension of the DLL to .pyd
or otherwise Python will not be able to load it. I think you can set a build option to automatically set the extension in VS, but I don't know for sure.
Also, make sure that the created extension is somewhere on the PYTHONPATH
, the path, python will look for modules to load.
manually building a python extension in cygwin with boost.python
ThatImportError
is generally not Boost.Python related. Rather, it normally indicates that xyz
is not in the Python Module Search Path.
To debug this, consider running python with -vv
arguments. This will cause python to print a message for each file that is checked for when trying to import xyz
. Regardless, the build process look correct, so the problem is likely the result of either the file extension or the module is not in the search path.
I am unsure as to how Cygwin will interact with Python's run-time loading behavior. However:
- On Windows, python extensions have a
.pyd
extension. - On Linux, python extensions have a
.so
extension.
Additionally, verify that the xyz
library is located in one of the following:
- The directory containing the
test.py
script (or the current directory). - A directory listed in the
PYTHONPATH
environment variable. - The installation-dependent default directory.
If the unresolved library shown in ldd
causes errors, it will generally manifest as an ImportError
with a message indicating undefined references.
Hello world with boost python and python 3.2
Although this discussion old, just for the record:
Modify project-config.jam to change the python version to your setup
# Python configuration
using python : 3.4 : /usr ;
Then build boost:
./b2 clean
./b2 --with-python link=static cxxflags="-std=c++11 -fPIC" variant=release stage
./b2 --with-python link=static cxxflags="-std=c++11 -fPIC" variant=release install
The later command requires super user privileges. Then move to the folder containing C++ code for the extension:
g++ -std=c++11 hellopy.cpp -I/usr/include/python3.4 -I/usr/local/include/boost/python -lboost_python3 -o hello.so -shared -fPIC
You can then import hello into your python environment.
Calling C++ from python using boost python: introductory example not working
You should include some libraries in your link command,
g++ -shared -Wl,--no-undefined hello_ext.o -lboost_python -lpython2.7 -o hello_ext.so
With -Wl,--no-undefined
linker option it will be an error if some symbols are missing.
Related Topics
Single Process Maximum Possible Memory in X64 Linux
Capturing a Reference by Reference in a C++11 Lambda
Is a Moved-From Vector Always Empty
What Default Promotions of Types Are There in the Variadic Arguments List
":" (Colon) in C Struct - What Does It Mean
Porting Clock_Gettime to Windows
How to Install the Openssl Libraries on Ubuntu
C++: Simple Return Value from Std::Thread
How to Write a Type Trait 'Is_Container' or 'Is_Vector'
Press Anykey to Continue in Linux C++
How to Find What Version of Libstdc++ Library Is Installed on Your Linux MAChine
Does Vector::Erase() on a Vector of Object Pointers Destroy the Object Itself
Disambiguate Class-Member in Multiple Inheritance
Create a Directory If It Doesn't Exist
Converting Multidimensional Arrays to Pointers in C++