cython-c-wrapper icon indicating copy to clipboard operation
cython-c-wrapper copied to clipboard

Problem compiling the code

Open StanleyLG opened this issue 5 years ago • 6 comments

Hi when i tried to use python3 setup.p build_ext --inplace on my RPI, it returned an error "cannot find -lexamples" , "collect2:error:ld returned 1 exit status", error:command 'arm-linux-gnueabihf-gcc' failed with exit status 1.

When i tried it on Windows 10, it returned 'fatal error C1083, io.h' not found as well as 'cl.exe failed with exit status 2'.

Is it possible you could clear my doubts, this is the first time i'm trying out cython. Appreciate if you could take some time and i look forward to the reply..

StanleyLG avatar Jun 10 '19 02:06 StanleyLG

Hi, did you make sure to follow the instructions specified here?

I am not familiar with the errors you mentioned, so please first make sure that cython is insatlled and the code is exactly as in the instructions. Please reply if it still doesn't work.

stavshamir avatar Jun 13 '19 05:06 stavshamir

I'll leave my solution for anyone in the future who runs into this problem.

I too got this error, and after some troubleshooting, I realized that my examples.c was missing the following two lines:

#include <stdio.h>

#include "examples.h"

Also, I didn't end up creating examples.h, which is in the github repo, but not in the article.

You might also need to create a lib directory and/or position the files in the same structure as shown in the repo.

Hope this helps!

jonathan-durbin avatar Sep 02 '19 21:09 jonathan-durbin

I clone the repo, however, I have the same problem as @StanleyLG. I am using python3.7 and Cython 0.29.6 on fedora workstation 30 system.

running build_ext building 'pyexamples' extension gcc -pthread -Wno-unused-result -Wsign-compare -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DNDEBUG -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -fPIC -Ilib -I/usr/include/python3.7m -c pyexamples.c -o build/temp.linux-x86_64-3.7/pyexamples.o gcc -pthread -shared -Wl,-z,relro -Wl,--as-needed -Wl,-z,now -g build/temp.linux-x86_64-3.7/pyexamples.o -Llib -L/usr/lib64 -lexamples -lpython3.7m -o /home/flumer/tmp/cython-c-wrapper/pyexamples.cpython-37m-x86_64-linux-gnu.so /usr/bin/ld: cannot find -lexamples collect2: error: ld returned 1 exit status error: command 'gcc' failed with exit status 1

disadone avatar Sep 14 '19 08:09 disadone

I'm getting a similar error after running make on the cloned repo.

LINK : fatal error LNK1181: cannot open input file 'examples.lib' error: command 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.26.28801\bin\HostX86\x64\link.exe' failed with exit status 1181

My specs: Windows 10, Python 3.7.4, Cython 0.29.20, gcc version 9.2.0 (MinGW distribution)

os1315 avatar Jun 24 '20 17:06 os1315

@os1315 This tutorial was created in linux, so I guess there might be some compatibility issues when using Windows. Sorry I can't give a better answer.

stavshamir avatar Jun 25 '20 05:06 stavshamir

I had a few errors in this. First, running main.py needs the path to the created .so file. In my case, on an RPi4 running Ubuntu20, and python 3.7, the file is pyexamples.cpython-37m-arm-linux-gnueabihf.so. To find the search path, you can follow these directions: https://realpython.com/lessons/module-search-path/ For simplicity, I added this line to the top-level makefile: cp pyexamples.cpython-37m-arm-linux-gnueabihf.so ~/.local/lib/python3.8/site-packages/pyexamples

So far so good, but when I run main.py, I get this error:

thirtybirds@pinballmatrix:~/noah/cython-c-wrapper$ python main.py
Traceback (most recent call last):
  File "main.py", line 3, in <module>
    pyexamples.py_hello(b"world")
AttributeError: module 'pyexamples' has no attribute 'py_hello'

Any ideas what could be going wrong? Thank you for the tutorial, it's been easy to follow so far.

diydsp avatar Mar 25 '21 21:03 diydsp