0

I'm learning how to extend Python in C.

Before starting, I downloaded all needed packages:

sudo apt-get install python2.7-dev
sudo apt-get install python3.5-dev

I picked up an example from internet to check if everything works fine.

Here is the link: https://docs.python.org/2/extending/extending.html

Created setup.py and built the module.

python2 setup.py build

It gave me no errors.
I created a test.py and i ran it.
it just said that the module I imported doesn't exist.
Confused i gcc'ed the C file and here is the result:

fatal error: Python.h: no such file or directory

I didn't give up and I tried this:
locate Python.h and the result was: /home/*censored*/python/include/python2.7/
so i used the flag -I and tried to GCC the code again: gcc -I /home/*censored*/python/include/python2.7/ myModule.c
The result was:

/usr/lib/gcc/x86_64-linux-gnu/6/../../../x86_64-linux-gnu/Scrt1.o: in the function "_start":(.text+0x20): reference not defined a "main"

also

myModule.c:(.text+0x37): reference not defined a "PyArg_ParseTuple"
myModule.c:(.text+0x67): reference not defined a "Py_BuildValue"
collect2: error: ld returned 1 exit status

I also downloaded the tarball and ran ./configure make and make install but nothing, still stuck with this problem.

This is my first question on StackOverflow so be kind with me if I messed up something about text formatting. Thank you and have a good day.

ndmeiri
  • 4,979
  • 12
  • 37
  • 45
  • What is `/home/*censored*/` for? What do you think can happen? – Iharob Al Asimi Aug 22 '17 at 19:38
  • i just censored my name. – PepeTheNewbie Aug 22 '17 at 19:39
  • 1
    C modules are built with `setup.py build_ext`, and you probably still won't be able to use yours without also installing it. The C error messages are simply a) incorrect include path (`-I` does not include path to `Python.h`), b) trying to link a shared library as an executable (`-shared` missing) and c) not supplying the necessary libraries to link with (`-lpython2.7 -L` missing). – dhke Aug 22 '17 at 19:42
  • Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – n. m. could be an AI Mar 13 '18 at 07:02

0 Answers0