including Python.h in C++ file CDT

亡梦爱人 提交于 2019-12-14 01:49:27

问题


I apologize if this is a silly question. But I tried to google this and I couldn't find anything to point me in the right direction. I'd just like to understand what I need to do to 'set-up' cdt to 'understand' my python.h include.

the erroneous statement is this:

#include <Python.h>

but I also tried

#include "Python.h"

And CDT responds with an error sign on the side stating:

Multiple markers at this line
- fatal error: Python.h: No such file or 
 directory
- Unresolved inclusion: <Python.h>

I am using Eclipse CDT Juno on Ubuntu 12.04. Any pointers would be great!


回答1:


please see this path of how to setup the environment in order to use cpython.

  1. fully detailed tutorial for Linux
  2. A small github project contains all the relevant files to use on MAC OSx.
  3. use python-config in order to get the paths to Python.h and to the static lib of python, which you should link your code with.



回答2:


Find the path with:

find / -iname python.h

Once you have the path, add it to:

Project > Properties > GCC C++ Compiler > Includes

If needed, add:

python2.7

to:

GCC C++ Linker > Libraries



回答3:


after installing the python-devel, locate On Terminal(ctrl+shift+t) by locate Python.h > the result is the file , copy the path and add it to eclipse by the following instructions.

personaly i like to get in the gist of the code so im adding to the compiler includes. but you can add to the linker as well, as mentioned above.

On eclipse : Project > Properties > C/C++ Build > Settings > ...Compiler(*) > Includes > Include paths (-l)

Directory : paste the path you've located in terminal. for example/usr/include/python2.7 press OK see it was added to the list press OK . enjoy

(*)note: if you are compiling c project choose the include under '.. GCC Copmiler' for C++ '..G++ Compiler'



来源:https://stackoverflow.com/questions/15670586/including-python-h-in-c-file-cdt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!